Docker Lesson 5 — Docker Compose with Multiple Local Containers
Sep 8, 2018 · 2 min read
It’s the note for Docker and Kubernetes: The Complete Guide
https://www.udemy.com/docker-and-kubernetes-the-complete-guide/
The sample is about using 2 containers for NodeJs and Redis.
Docker Compose
- Separate CLI that gets installed along with Docker
- Used to start up multiple Docker containers at the same time
- Automates some of the long-winded arguments we were passing to `docker run`
----------------------------------------------
| docker build -t yakushou730/visits:latest |
| docker run -p 8080:8080 yakushou730/visits |
----------------------------------------------=> docker-compose.yml
(containes all the options we'd normally pass to docker-cli)=> docker-compose CLI
--EXAMPLEdocker-compose.ymlHere are the containers I want created:* redis-server
- Make it using the 'reids' image* node-app
- Make it using the Dockerfile in the current directory
- Map port 8081 to 8081
--docker-compose.ymlversion: '3'
services:
redis-server:
image: 'redis'
node-app:
build: .
ports:
- "4001:8081"
-------------------------
| docker run myimage | => docker-compose up
----------------------------------------------
| docker build . |
----------------------- => docker-compose up --build
| docker run myimage |
-------------------------Launch in background
$ docker-compose up -dStop Containers
$ docker-compose down--Status codes0 => We exited and everything is OK
1, 2, 3, etc => We exited because something went wrong !Restart Policies"no" => Never attempt to restart this . container if it
stops or crashes
always => If this container stops *for any reason* always
attempt to restart it
on-failure => Only restart if the container stops with an error
code
unless-stopped => Always restart unless we (the developers) forcibly
stop it--$ docker-compose ps
