{"id":13343400,"url":"https://github.com/Gurenax/node-express-docker","last_synced_at":"2025-03-12T04:33:32.315Z","repository":{"id":93146353,"uuid":"122799702","full_name":"Gurenax/node-express-docker","owner":"Gurenax","description":"🐳 A quick guide to deploying Yarn-built Node Express apps to Docker","archived":false,"fork":false,"pushed_at":"2018-02-25T02:58:22.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-24T15:39:47.666Z","etag":null,"topics":["docker","docker-image","dockerfile","express","expressjs","node","nodejs","yarn"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Gurenax.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-25T02:48:55.000Z","updated_at":"2020-02-14T17:13:24.000Z","dependencies_parsed_at":"2023-06-05T05:45:24.289Z","dependency_job_id":null,"html_url":"https://github.com/Gurenax/node-express-docker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gurenax%2Fnode-express-docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gurenax%2Fnode-express-docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gurenax%2Fnode-express-docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gurenax%2Fnode-express-docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gurenax","download_url":"https://codeload.github.com/Gurenax/node-express-docker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243158975,"owners_count":20245668,"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":["docker","docker-image","dockerfile","express","expressjs","node","nodejs","yarn"],"created_at":"2024-07-29T19:31:18.506Z","updated_at":"2025-03-12T04:33:32.309Z","avatar_url":"https://github.com/Gurenax.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node Express Docker using Yarn\nThese are procedures to run Docker on Node/Express while using Yarn instead of NPM. The main reason for creating this guide is to enable Yarn-built repositories to run on a Docker images (e.g. React Apps, React Native Apps).\n\n## Steps to get this working\n\n### Create Basic Express Code\n\n1. Initialise the project: `yarn init`\n2. Add express: `yarn add express`\n3. Create server.js: `touch server.js`\n\n```javascript\n'use strict'\n\nconst express = require('express')\n\n// Create the server\nconst server = express()\n\n// Start the server\nserver.listen(7000, error =\u003e {\n  if (error) {\n    console.error(error)\n  } else {\n    console.log('Started at http://localhost:7000')\n  }\n})\n```\n\n4. Add a routes folder: `mkdir routes \u0026\u0026 cd routes`\n5. Create a route for products: `touch products.js`\n\n```javascript\n'use strict'\n\nconst express = require('express')\n\n// Create express router\nconst router = express.Router()\n\n// GET /products\nrouter.get('/products', (req, res) =\u003e {\n  res.json('Hello Products!')\n})\n\n// Export router\nmodule.exports = router\n```\n\n6. Add Routes in server.js\n\n```javascript\n// Routes\nserver.use('/', [require('./routes/products')])\n```\n\n7. Start the server to test if it's running: `yarn start`\n\n\n### Setup Docker\n1. Install docker: `brew cask install docker`\n2. Run docker app and configure your login to docker cloud\n3. Create a Dockerfile `touch Dockerfile`\n\n```Dockerfile\nFROM node:carbon\n\n# Create app directory\nWORKDIR /usr/src/app\n\n# Install app dependencies\n# A wildcard is used to ensure both package.json AND package-lock.json are copied\n# where available (npm@5+) and yarn.lock because we are using yarn\nCOPY package*.json yarn.lock ./\n\n# Run yarn without generating a yarn.lock file\nRUN yarn --pure-lockfile\n\n# Bundle app source\nCOPY . .\n\n# Use the port used by our server.js configuration\nEXPOSE 7000\n\n# This will run `yarn start` when the docker image is ran\nCMD [ \"yarn\", \"start\" ]\n```\n\n4. Create .dockerignore file: `touch .dockerignore`\n```\nnode_modules\nnpm-debug.log\n```\n\n5. Login using Docker CLI\n```\ndocker login\n```\n\n6. Build the docker image\n```\ndocker build -t \u003cyour username\u003e/node-express-docker .\n```\n\n7. Print list of docker images\n```\ndocker images\n```\n\n8. Run the docker image. This will run the image on port 49160 as it was forwarded from port 7000. The `-d` flag specifies that the container is running in detached mode.\n```\ndocker run -p 49160:7000 -d \u003cyour username\u003e/node-express-docker\n```\n\n9. Print list of deployed docker images\n```\ndocker ps\n```\n\n10. Print log of a specific docker container\n```\ndocker logs \u003ccontainer id\u003e\n```\n\n11. Entering into the container's shell mode\n```\ndocker exec -it \u003ccontainer id\u003e /bin/bash\n```\n\n12. Test the app using curl or simply `localhost:49160/products` in a browser\n```\ncurl -i localhost:49160/products\n```\n\nShould output something like :\n```\nHTTP/1.1 200 OK\nX-Powered-By: Express\nContent-Type: application/json; charset=utf-8\nContent-Length: 17\nETag: W/\"11-ek8eHQf3jVcXpzn7ZZ5GiWlH1gg\"\nDate: Sun, 25 Feb 2018 02:42:49 GMT\nConnection: keep-alive\n\n\"Hello Products!\"%\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGurenax%2Fnode-express-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGurenax%2Fnode-express-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGurenax%2Fnode-express-docker/lists"}