{"id":18981897,"url":"https://github.com/nodeshift/docker","last_synced_at":"2025-06-27T22:33:11.147Z","repository":{"id":41140098,"uuid":"141716741","full_name":"nodeshift/docker","owner":"nodeshift","description":"Sample Dockerfile templates for building Dev, Debug, Test and Run images for your application","archived":false,"fork":false,"pushed_at":"2022-08-16T19:43:59.000Z","size":24,"stargazers_count":131,"open_issues_count":0,"forks_count":75,"subscribers_count":16,"default_branch":"main","last_synced_at":"2025-02-21T09:23:41.711Z","etag":null,"topics":["dockerfile"],"latest_commit_sha":null,"homepage":null,"language":"Dockerfile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nodeshift.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-20T13:40:53.000Z","updated_at":"2025-02-18T04:58:33.000Z","dependencies_parsed_at":"2022-09-19T18:00:24.297Z","dependency_job_id":null,"html_url":"https://github.com/nodeshift/docker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nodeshift/docker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeshift%2Fdocker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeshift%2Fdocker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeshift%2Fdocker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeshift%2Fdocker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nodeshift","download_url":"https://codeload.github.com/nodeshift/docker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeshift%2Fdocker/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262344188,"owners_count":23296458,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dockerfile"],"created_at":"2024-11-08T16:11:38.534Z","updated_at":"2025-06-27T22:33:11.118Z","avatar_url":"https://github.com/nodeshift.png","language":"Dockerfile","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Docker Templates for Node.js\n\u003ca href='http://CloudNativeJS.io/'\u003e\u003cimg src='https://img.shields.io/badge/homepage-CloudNativeJS-blue.svg'\u003e\u003c/a\u003e\n\nThis project uses the Universal Base Docker images built by Red Hat and provides guidance on how to add best-practise Dockerfiles into your project.\n\n\nThis project contains three template Dockerfiles:\n\n| Dockerfile        | Description                                                           |\n|-------------------|-----------------------------------------------------------------------|\n| Dockerfile        | A default Dockerfile for building and running your Node.js application |\n| Dockerfile-tools  | A Dockerfile for developing or debugging your Node.js application     |\n| Dockerfile-run    | A multi-stage Dockerfile for building a \"run\" image for your application, based on the UBI 8 Node.js Minimal image |\n\nIn order to use these template files, copy the files from this project into your application directory.\n\n## Installing the Templates\n\nThe templates can most easily be installed into your project using either of the following mechanisms:\n\n* All Files:  \n  Use the \"Clone or download\" button and select \"Download ZIP\" to copy the entire set of templates, and copy those into your project.\n* Individual Files:  \n  Use \"wget\" to download individual files using:\n  ```sh\n  wget https://raw.githubusercontent.com/NodeShift/docker/main/{file}\n  ```\n\n## Using `Dockerfile`\n\nThe Dockerfile template creates a Docker image for your application that:\n\n* Uses the `registry.access.redhat.com/ubi8/nodejs-16:latest` image\n\nThe template also makes the following assumptions about your application:\n\n* It listens on port 3000\n* It can be started using `npm start`\n\nYou can change these settings by updating the `EXPOSE` and `CMD` entries of the Dockerfile.\n\n### Building the Docker image for your application\n\nAfter any required changes have been made to the Dockerfile, you can build a Docker image for your application using the following command:\n\n```sh\ndocker build -t my-nodejs-application -f Dockerfile .\n```\nwhere `my-nodejs-application` is the name you want to give your created Docker image.\n\n### Running the Docker image for your application\nAfter the Docker image has been created for your application, you can run it using either of the following commands:\n\n* Run as an interactive application on your command line:\n  ```sh\n  docker run -i -p 3000:3000 -t my-nodejs-application\n  ```\n  This maps port 3000 in the Docker image to port 3000 on your machine. If you are using a different port, you will need to change the mapping.\n\n* Run as a daemon process:\n  ```sh\n  docker run -d -p 3000:3000 -t my-nodejs-application\n  ```\n  This uses the `-d` flag rather than the `-i` flag to run the Docker image as a background task.\n\n## Using `Dockerfile-tools`\n\nThe Dockerfile-tools template creates a Docker image for your application that:\n\n* Uses the `registry.access.redhat.com/ubi8/nodejs-16:latest` image\n* Provides a script for running in `dev` mode using `nodemon`\n* Provides a script for running in `debug` mode using `node --inspect`\n\nThe template also makes the following assumptions about your application:\n\n* It listens on port 3000\n* It can be started using `node server/server.js`\n\nYou can change the port by editing the `EXPOSE` entry in the Dockerfile-tools file, and the start command by editing the `run-dev` and `run-debug` scripts.\n\n### Building the Docker tools image for your application\nAfter any required changes have been made to the Dockerfile-tools, you can build a Docker image for your application using the following command:\n\n```sh\ndocker build -t my-nodejs-application-tools -f Dockerfile-tools .\n```\nwhere `my-nodejs-application-tools` is the name you want to give your created tools Docker image.\n\n### Running the Docker tools image for your application: Development Mode\nRunning the image in Development Mode uses `nodemon` to watch for changes in your application and automatically restart it as those changes are made.\n\nTo enable your local changes to be updated in the Docker image, you must map your local file system into the running Docker container, as follows:\n\n1. Generate a Linux version of your `node_modules` dependencies locally, by generating them inside the node:16 docker image:\n  ```sh\n  docker run -i -v \"$PWD\"/package.json:/tmp/package.json -v \"$PWD\"/node_modules_linux:/tmp/node_modules -w /tmp -t node:16 npm install\n  ```\n  This step only needs to be repeated if you modify your package.json file.\n  \n2. Run the Docker tools image as an interactive application on your command line in dev mode:\n  ```sh\n  docker run -i -p 3000:3000 -v \"$PWD\"/:/app -v \"$PWD\"/node_modules_linux:/app/node_modules -t my-nodejs-application-tools /bin/run-dev\n  ```\n  This maps port 3000 in the Docker image to port 3000 on your machine. If you are using a different port, you will need to change the mapping.\n  This command also maps your local directory into the Docker container, allowing you to modify your Node.js application code and see the changes running immediately in the container.\n     \n### Running the Docker tools image for your application: Debug Mode\n\nIn order to run your application in debug mode:\n* Run as an interactive applications on your command line in debug mode:\n  ```sh\n  docker run -i -p 3000:3000 -p 9229:9229 -t my-nodejs-application-tools /bin/run-debug\n  ```\n  This maps port 3000 in the Docker image to port 3000 on your machine. If you are using a different port, you will need to change the mapping.\n  This command also maps port 9229 in the image to the same port on your machine so that you can connect the debugger.\n\nIf you wish to run your Docker tools image as a background task, switch the `-i` flag to `-d` on the command line.\n\n## Using `Dockerfile-run`\nThe Dockerfile-run template creates a Docker image using a multi-stage build that:\n\n* Retrieves your dependencies and compiles any native add-ons using the `registry.access.redhat.com/ubi8/nodejs-16:latest` image\n* Copies your dependencies into the `registry.access.redhat.com/ubi8/nodejs-16-minimal:latest`image for reduced size\n\nThe template also makes the following assumption about your application:\n\n* It listens on port 3000\n* It can be started using `npm start`\n\nYou can change these settings by updating the `EXPOSE` and `CMD` entries of the Dockerfile-run template.\n\n### Building the Docker run image for your application\nAfter any required changes have been made to the Dockerfile-run file, you can build a Docker image for your application using the following command:\n\n```sh\ndocker build -t my-nodejs-application-run -f Dockerfile-run .\n```\nwhere `my-nodejs-application-run` is the name you want to give your created Docker run image.\n\n### Running the Docker run image for your application\nAfter the Docker run image has been created for your application, you can run it using either of the following commands:\n\n* Run as an interactive application on your command line:\n  ```sh\n  docker run -i -p 3000:3000 -t my-nodejs-application-run\n  ```\n  This maps port 3000 in the Docker image to port 3000 on your machine. If you are using a different port, you will need to change the mapping.\n\n* Run as a daemon process:\n  ```sh\n  docker run -d -p 3000:3000 -t my-nodejs-application-run\n  ```\n  This additionally uses the `-d` flag to run the Docker image as a background task.\n\n## Publishing the Image\nIn order to use your application's Docker image in a cloud it needs to be published. You can deploy to the image to the DockerHub registry using the following commands:\n\n1. Log in to DockerHub:\n\n   ```sh\n   docker login\n   ```\n   This logs you into DockerHub using your [Docker ID](https://docs.docker.com/docker-id/#/register-for-a-docker-id), where you have a namespace that matches your DockerHub ID.\n\n1. Tag your application's Docker image with the name you want to use in DockerHub:\n   ```sh\n   docker tag my-nodejs-application-run \u003cnamespace\u003e/nodeserver:1.0.0\n   ```\n   where `\u003cnamespace\u003e` is your namespace in DockerHub.\n\n1. Publish your application's Docker image to DockerHub:\n   ```sh\n   docker push \u003cnamespace\u003e/nodeserver:1.0.0\n   ```\n   where `\u003cnamespace\u003e` is your namespace in DockerHub.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodeshift%2Fdocker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodeshift%2Fdocker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodeshift%2Fdocker/lists"}