{"id":15493064,"url":"https://github.com/simison/docker-nodejs-dev-boilerplate","last_synced_at":"2025-04-11T00:58:21.250Z","repository":{"id":137298284,"uuid":"51998547","full_name":"simison/docker-nodejs-dev-boilerplate","owner":"simison","description":"[WIP] A boilerplate to demonstrate containerized development in NodeJS using Docker.","archived":false,"fork":false,"pushed_at":"2016-02-23T15:12:18.000Z","size":11,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T00:58:16.412Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simison.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-18T10:11:05.000Z","updated_at":"2017-05-15T04:33:37.000Z","dependencies_parsed_at":"2023-05-07T02:47:00.624Z","dependency_job_id":null,"html_url":"https://github.com/simison/docker-nodejs-dev-boilerplate","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/simison%2Fdocker-nodejs-dev-boilerplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simison%2Fdocker-nodejs-dev-boilerplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simison%2Fdocker-nodejs-dev-boilerplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simison%2Fdocker-nodejs-dev-boilerplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simison","download_url":"https://codeload.github.com/simison/docker-nodejs-dev-boilerplate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248322611,"owners_count":21084336,"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":[],"created_at":"2024-10-02T08:03:58.993Z","updated_at":"2025-04-11T00:58:21.229Z","avatar_url":"https://github.com/simison.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Docker-NodeJS Development Boilerplate\n\n**This is a boilerplate to demonstrate containerized development in NodeJS using Docker.**\n\n#### Stack\n- Containerized using **[Docker](https://www.docker.com/)**.\n- Uses **[Nginx](http://nginx.org/)** container to proxy http 80 port to a **[NodeJS](https://nodejs.org/)** server running on port 3000.\n- Package management using **NPM** and **[Bower](http://bower.io/)**.\n- Sets up **[MongoDB](https://www.mongodb.org/)** container.\n- Watching for changes using **[Nodemon](http://nodemon.io/)** and **[LiveReload](http://livereload.com/)**.\n- Builds and starts the app using **[Gulp](http://gulpjs.com/)** task runner.\n- Everything is orchestrated using **[Docker-Compose](http://docs.docker.com/compose/)**\n\n#### Reasoning\nLearning how to setup all this for Docker required quite a bit of reading and most of the guides you find are for production deployment, while I was more interested in using Docker for development setup.\n\nIt's very convenient to be able to get development environment running quickly and easily in very different platforms (OSX/Linux/Windows). Docker is perfect for this.\n\nEspecially differences between production and development configurations for `node_modules` and `bower_components` was hard to understand: while in production you might want these \"layers\" to be cached until you actually change something from `package.json` or `bower.json`, in development you want to have them readily available.\n\nIt's also worth nothing that running `gulp` or `bower install` directly requires you to install those globally (`npm i gulp bower -g`), but when run via NPM (see scripts section from `package.json`), it uses versions installed to `node_modules`.\n\n## Installing\n\n##### 1. Install prerequisites\n* Install [Docker](https://www.docker.com/) on your system.\n* Install [Docker Compose](http://docs.docker.com/compose/) on your system.\n\n##### 2. Configure `/etc/hosts` file\n\nCheck what is your Docker machine's name by running `docker-machine ls` — often it's `default`.\n\nThen run this one-liner — just replace `default` with your machine name, if it differs:\n```bash\nprintf \"\\n\\n$(docker-machine ip default)\\\\tapp.dev\" | sudo tee -a /etc/hosts \u003e /dev/null\n```\n\nThis will add these lines to your `/etc/hosts` file and it will ask for sudo password:\n\n```\n[DOCKER-MACHINE-IP]\tapp.dev\n```\n\n\u003e Tip: If you would like to skip Nginx, you can access NodeJS directly with `http://[DOCKER-MACHINE-IP]:3000/`\n\u003e If you're OSX user, you need to follow [these instructions for OSX](https://labs.ctl.io/tutorials/docker-on-the-mac-without-boot2docker/) (not required on Linux).\n\n##### 3. Build and start containers\n\nRun `docker-compose up`\n\nThe build script will:\n- Download Nginx, NodeJS and MongoDB containers\n- Install NPM modules\n- Install Bower components\n- Launch Gulp task runner which in turn will compile frontend assets and start serving the app\n\n##### 4. Hack!\n\nOpen [http://app.dev/](http://app.dev/)\n\nNow go ahead and do changes to `./src/app.scss` or `./public/index.html` and see this page reload changes.\n\n#### Running \u0026 upgrading\n\n- Hit `Ctrl+C` to turn off containers.\n- Type `docker-compose up` to start them up again. You might want to run containers as daemon: `docker-compose up -d` and then attach to Node container to see the logs: `docker-compose logs app`. Otherwise you'll see logs from all the containers.\n- To update NPM and Bower modules, run: `docker-compose run app npm update`\n\n## Running without Docker\n1. Install NodeJS and MongoDB. Make sure MongoDB is running in localhost at default port.\n2. Run `npm start`\n3. Open [http://localhost:3000/](http://localhost:3000/)\n\nThis will skip Nginx proxy setup.\n\n## Running in production\nThis boilerplate doesn't currently include production configuration, but you could serve the application using Docker.\n\nTo serve in production without Docker, building the assets first (`npm build`) and then serve `server.js` using e.g. **Nginx** proxy together with app runner such as **[Phusion Passenger](phusionpassenger.com)**, **[PM2](https://www.npmjs.com/package/pm2)** or **Forever**.\n\nIt's important to understand that Docker-Compose configuration (`docker-compose.yml`) is meant for running this in development and in production you would use only `Dockerfile` configuration.\n\n## Security notes\nSince this boilerplate is meant mainly for development, it doesn't have security measures configured for the app or Docker containers. Included app (`server.js`) is a very simple barebone hello-world example.\n\nNote that it's recommended not to have `bower_components` folder publicly accessible — use Gulp to compile exactly what you need from the folder.\n\n## File structure\n- `config`: Nginx configuration files for `location` and `server` configuration blocks. These basically turn Nginx caching off to make development easier.\n- `docker-compose.yml`, `Dockerfile` and `.dockerignore`: Configurations for Docker containers.\n- `node_modules`: Backend modules\n- `bower_components`: Frontend vendor assets\n- `public`: Folder served by NodeJS server.\n- `public/build`: Compiled frontend assets\n- `src`: files to be compiled to `public/build`\n- `gulpfile.js`: Gulp task runner configuration\n- `.editorconfig`: [EditorConfig](http://editorconfig.org/) is awesome\n- `bower.json` and `.bowerrc`: configurations and requirements for frontend vendor assets\n- `package.json`: scripts and NPM requirements for this app\n- `server.js`: Application entry point\n- `.gitignore`: [Gitignore](https://github.com/github/gitignore)\n\n## Reading\n- [Docker for development - common problems and solutions](https://medium.com/@rdsubhas/docker-for-development-common-problems-and-solutions-95b25cae41eb)\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimison%2Fdocker-nodejs-dev-boilerplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimison%2Fdocker-nodejs-dev-boilerplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimison%2Fdocker-nodejs-dev-boilerplate/lists"}