- Notifications
You must be signed in to change notification settings - Fork190
Docker Compose for Node projects with Node, MySQL, Redis, MongoDB, NGINX, Apache2, Memcached, Certbot and RabbitMQ images
License
Osedea/nodock
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Docker Compose for Node projects with Node, MySQL, MongoDB, NGINX, Memcached, Redis, Certbot and RabbitMQ images
Thedocker Node.js image is very simple, you give it an entrypoint and it runs it. This is fine for very simple/small scripts but for larger projects you'll probably want something a bit more robust.
The goal of NoDock is to provide a complete environment for your node project: Node.js service(s), databases, web servers, queues, etc. while doing the "wiring" for you.
You can use NoDock for simple projects by using one of theexamples or you can build upon them.
- Requirements
- Installation
- Usage
- Examples
- Workspace
- HTTPS
- Non-web project
- Multiple Node containers
- More options
- Contributing
- License
- Credits
As a git submodule:
git submodule add https://github.com/Osedea/nodock.git
Clone into your project:
git clone https://github.com/Osedea/nodock.git
We recommend youfork this repository if you intend to add project specific scripts/configurations.
cd nodock# Run "node" and "nginx"docker-compose up -d node nginx
To overwrite thedocker-compose.yml
file you can use adocker-compose.override.yml
# docker-compose.override.ymlversion:'3'services:[...]
We provide examples of configurations you might use for a specific stack. Each example has it's own README file with instructions.
- Simple Web with Apache - Node + Apache
- Simple Web with Nginx - Node + NGINX
- MySQL - MySQL + Node + NGINX
- PostgreSQL - PostgreSQL + Node + NGINX
- Mongo - MongoDB + Node + NGINX
- RabbitMQ - RabbitMQ + Node + NGINX
- Memcached - Memcached + Node + NGINX
- Redis - Redis + Node + NGINX
- RethinkDB - RethinkDB + Node + NGINX
- 2 Node Apps - Node + Node + NGINX
Theworkspace
container is where you want to be manually running commands forNoDock
. You can use this container to initialize your project, for task-automation, forcronjobs, etc.
By default HTTPS is disabled. To enable it, you may use the following settings
# docker-compose.override.yml[...]nginx:build:args: -WEB_SSL=true
Add your certificate tonginx/certs/cacert.pem
and the private key tonginx/certs/privkey.pem
.
SELF_SIGNED: "true"
will generate the necessary files, do note thatSELF_SIGNED: "true"
as no effect ifWEB_SSL: "false"
# docker-compose.override.yml[...]nginx:build:args: -WEB_SSL=true -SELF_SIGNED=true
CN
must be a publicly accessible address andEMAIL
should be the server admin contact email.
# docker-compose.override.yml[...]nginx:build:args: -WEB_SSL=truecertbot:environment: -CN=example.com -EMAIL=fake@gmail.com
Don't forget to bring up the container if you plan on using certbot (docker-compose up -d certbot
).
The default NGINX server block configuration is aimed at web projects but if you want to have a single non-web container you can do something similar to the following configuration.
# docker-compose.override.yml[...]nginx:build:args:-NO_DEFAULT=trueports: -"10000:10000"
Do note that usingNO_DEFAULT
makesWEB_REVERSE_PROXY_PORT
,WEB_SSL
andSELF_SIGNED
have no effect.
You will then have to provide your own NGINX server block like so
# nginx/sites/custom-node.confserver { listen 10000 default_server; location / { proxy_pass http://node:5000; }}
To add more node containers, simply add the following to yourdocker-compose.override.yml
or environment specific docker-compose file.
# docker-compose.override.yml[...]node2:# name of new containerbuild:# reuse the same values from the node service, cannot use extends in docker-compose 3+context:./nodeargs: -NODE_VERSION=latest -PROJECT_PATH=/opt/app/ -NODE_ENV=production -YARN=falsevolumes: -../:/opt/appentrypoint:run-nodock "node alternate.js"# the entrypoint for the "node2" containernginx:ports: -"10000:10000"# the port(s) to forward for the "node2" containerlinks: -node2# link "nginx" to "node2"
You'll also need to add a server block for "node2".
# nginx/sites/node2.confserver { listen 10000 default_server; location / { proxy_pass http://node2:8000; }}
You can run cronjobs in theWorkspace by storing them in theworkspace/crontab/root
file.
# workspace/crontab/root* * * * * echo "Every Minute" >> /var/log/cron.log
To customize the NoDock installation, either add adocker-compose.override.yml
in the NoDock directory or store environment specific configurations.
docker-compose -f nodock/docker-compose.yml -f docker-compose.dev.yml up -d
Set theYARN
argument totrue
.
# docker-compose.override.yml[...]node:build:args: -YARN=true
Usemain.js
instead ofindex.js
# docker-compose.override.yml[...]node:entrypoint:run-nodock "node main.js"
The defaultNODE_ENV
value isproduction
, you can change it to development by doing the following
# docker-compose.override.yml[...]node:build:args: -NODE_ENV=development
The default node version islatest
, this isNOT advisable for production
# docker-compose.override.yml[...]node:build:args: -NODE_VERSION=4.6.0
You can specify aPROJECT_PATH
to change the directory in whichnpm
will perform it'sinstall
command and the directory in whichrun-nodock
will run the entrypoint script. This is most desirable when running more than one Node project at a time since they are bound to each have their ownpackage.json
file.
# docker-compose.override.yml[...]node:build:args:PROJECT_PATH:somefolder# note that this is the same as "/opt/app/somefolder"
# docker-compose.override.yml[...]mysql:build:args: -MYSQL_DATABASE=default_database -MYSQL_USER=default_user -MYSQL_PASSWORD=secret
# docker-compose.override.yml[...]postgresql:build:args: -POSTGRES_DB=default_db -POSTGRES_USER=default_user -POSTGRES_PASSWORD=secret
Use port8080
instead of8000
to bind your Node server
# docker-compose.override.yml[...]nginx:build:args: -WEB_REVERSE_PROXY_PORT=8080
To change the timezone for theworkspace
container, modify theTZ
build argument in the Docker Compose file to one in theTZ database.
For example, if I want the timezone to beNew York
:
# docker-compose.override.yml[...]workspace:build:context:./workspaceargs: -TZ="America/New_York"
At the moment, NoDock supports 2 plugins:Management andFederation.
To activate them, change their values totrue
in your docker-compose file:
# docker-compose.override.yml[...]rabbitmq:build:args: -MANAGEMENT=true -FEDERATION=true
# docker-compose.override.yml[...]rabbitmq:build:args: -RABBITMQ_DEFAULT_USER=custom_user -RABBITMQ_DEFAULT_PASS=custom_pass
You can editredis/redis.conf
to modify the redis config.
Do not hesitate to contribute to NoDock by creating an issue, fixing a bug or bringing a new idea to the table.
To fix a bug or introduce a new feature, please create a PR, we will merge it in to themaster
branch after review.
We thank you in advance for contributing.
MIT License (MIT)
NoDock uses Open Source components. You can find the source code of their open source projects along with license information below. We acknowledge and are grateful to these developers for their contributions to open source.
Project: LaraDockhttps://github.com/LaraDock/laradock
Copyright (c) 2016 Mahmoud Zalt (mahmoud@zalt.me)
License (MIT)https://github.com/LaraDock/laradock/blob/master/LICENSE
Project: baseimage-dockerhttps://github.com/phusion/baseimage-docker
Copyright (c) 2013-2015 Phusion Holding B.V.
License (MIT)https://github.com/phusion/baseimage-docker/blob/master/LICENSE.txt
About
Docker Compose for Node projects with Node, MySQL, Redis, MongoDB, NGINX, Apache2, Memcached, Certbot and RabbitMQ images