It is unlikely that your application will only require a single container. Usually you will have several containers for other services like a database, web service, background tasks, etc. For this we use the docker-compose command. docker-compose uses a very simple YAML file to build multiple containers. Each container can have its own Dockerfile that customises the individual container but docker-compose will build all the containers and put them into the same virtual network. Docker containers and services do not even need to be aware that they are deployed on Docker, or whether their peers are also Docker workloads or not. Whether your Docker hosts run Linux, Windows, or a mix of the two, you can use Docker to manage them in a platform-agnostic way.
YAML
# YAML
version: '3'
services:
web:
build: .
ports:
- "4000:80"
volumes:
- .:/code
Compose Two Container
# YAML
version: '3'
services:
web:
image: wordpress
links:
- mysql
environment:
- WORDPRESS_DB_PASSWORD=sample
ports:
- "127.0.0.3:8080:80"
mysql:
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=sample
- MYSQL_DATABASE=wordpress
Docker Compose in Depth - Volumes and Networks (MultiContainer Componse)
Docker compose
volumes:
- .:/code
vim app.py
docker-compose down
Build:
Context: .docker
Dockerfile: myapp.docker
Container_name: myapp
Compose networking
networks:
default:
external:
name: existing-network
Compose networking
# you need to use the latest version of docker-compose yml
version: '3.5'
services:
app:
image: nginx
networks:
- my-network-name
networks:
my-network-name:
name: my-global-net
Create a Cluster and add worker to Cluster
Initiate swarm manager
Joining workers
Cluster Nodes