Docker + fig / compose + nginx + node.js + mysql + redis Docker + fig / compose + nginx + node.js + mysql + redis nginx nginx

Docker + fig / compose + nginx + node.js + mysql + redis


Before the configuration of docker-compose part, you must decide on the architecture of the system.

The parts you have -

  • MySQL executable version X listening on port 3306
  • MySQL data stored on disk
  • Redis executable version Y listening on port 6379
  • Redis backup data on disk
  • Node.js executable version Z listening on port 3000
  • Files of your Express.js application
  • Nginx executable version Q listening on port 80

Additional infrastructure considerations -

  • Single instance, one cpu/core
  • Single instance, multiple cpus/cores
  • Multiple instances
  • Which load-balancer is used (if at all)

For a single instance that will run all the components, you probably don't even need a load balancer - so unless you need to serve static files alongside your application, there is little sense here to have nginx because it wouldn't be doing anything useful.

When you have multiple containers running your express.js application either on one instance (for multi-core/CPU) or multiple instances then you need to have some kind of load balancing going on, maybe using nginx.

Handling data inside the container is not recommended since the container filesystem is not very good at handling highly mutating data. So for MySQL and Redis you probably want to have external mount points where the data resides.

Your Express.js application needs configuration of which Redis and MySQL servers it needs to connect with, this can be done using Docker links.

Thus, your Docker Compose will look something like this -

redis:  image: redis  volumes:    - /data/redis:/datamysql:  image: mysql:5.6  environment:    - MYSQL_ROOT_PASSWORD=verysecret  volumes:    - /data/mysql:/var/lib/mysqlapplication:  image: node:0.12  working_dir: /usr/src/myapp  volumes:    - /src/app:/usr/src/myapp  ports:    - 80:3000  links:    - redis    - mysql

This assumes you will store the data of MySQL and Redis on the host filesystem in /data, and your application on the host filesystem is at /src/app.

I recommend you look for the Docker Compose YAML file reference for all the various options that can be used https://docs.docker.com/compose/yml/.

Since the images used are the blessed images from Docker HUB, their readme files are important to take note of for more configuration -

Adding more instances of the application is easy, but then you will need to add nginx to load balance the incoming traffic to the multiple application containers.

Then when you want to run this kind of setup using multiple hosts, it becomes much more complex since docker-links will not work and you need another way to discover the container IP addresses and ports. And a load balancer will be required to have a single endpoint that accepts traffic for multiple instances of the application. Here I would recommend to take a good look on https://consul.io for help.


I think that you don't need to split nginx and nodejs to different instances. Currently I'm also setting up nodejs on docker, so will be back here soon and try to put complex response on you question.

There you can find a useful article about setting up similar architecture on docker http://blog.stxnext.com/posts/2015/01/development-with-docker-and-fig/ , the difference django / nodejs should not be a problem.