I'm trying to set up a Node.js app on Docker multiple containers. My app is currently on one Ubuntu DO droplet & uses:
- Node.js (express 4)
- mysql for the app database
- redis for a key-value store
- nginx for load balancing and serve static files.
I need to dockerize the different parts, one for each container obviously, then use Docker-Compose (Previously known as Fig) to simply describe the different containers & setup the links between them.
I'm steal unclear about the multi-container appraoch.
One for nginx
one for Node.js & my express app
one for MySql
and one for Redis
How would the Docker-compose.yml will look like? I'm guessing the nginx, mysql & redis will be unmodified official images? While the node.js will have a build directive to point to a Dockerfile, which will note it is based on the node.js official image along with configuration instructions? I will need to configure / provision mysql & redis for example so does it mean that each needs to be separate with its own Dockerfile?
What would be the way to link between the containers? use volumes to copy files into them, setting ports, adjusting the hosts file to map some.domain.com to the nginx ip?
I will then need to install globally some npm packages like nodemon & PM2 and set some cron jobs... (on the Node.js container?)
here is a first draft, I would appreciate any help to better understand this new setup:
Docker-compose.yml
nginx:
image: nginx
links:
- "node"
node:
build: .
volumes:
- "app:/src/app"
ports:
- "3030:3000"
links:
- "db:mysql"
db:
image: mysql:5.6
environment:
- MYSQL_ROOT_PASSWORD=mypassword
Dockerfile
FROM node:0.12
RUN mkdir /src
RUN npm install nodemon pm2 -g
WORKDIR /src
ADD app/package.json /src/package.json
RUN npm install
ADD app/nodemon.json /src/nodemon.json
EXPOSE 3000
CMD npm start
I'm using this simple project as a base, though my app needs