Docker Session IV
Docker Compose and Docker Swarm
Discussion on
● Docker Compose
● Docker Swarm
● Docker Compose vs Docker Swarm
● Discussion
Docker Compose
● What is docker compose?
SETUP
● Install docker compose
○ https://docs.docker.com/compose/install
● Write docker compose yml file
○ docker-compose.yml
FORMAT
Version: 3.6
services:
<service_name>:
build:
image:
depends_on:
ports:
volumes:
VERSION
● 3.0 - 3.6
● 2.0 - 2.3
● 1.0
SERVICES
● Name of a containers group
● Once service can have multiple containers
BUILD
● Build: <context>
● Eg.
○ build: ./dir
BUILD DETAIL
● Build:
○ Context: <dir>
○ Dockerfile: <alternate dockerfile>
● Eg.
○ Build:
■ Context: ./dir
■ Dockerfile: Rails.Dockerfile
BUILD SAMPLE
version: '3'
services:
webapp:
build:
context: ./dir
dockerfile: Dockerfile-alternate
IMAGE
● Specify the image to start the container from.
● Image: redis
GUESS
● What happens if both build and image tag are present?
build: ./dir
image: webapp:tag
RESULT
● What happens if both build and image tag are present?
build: ./dir
image: webapp:tag
This results in an image named webapp and tagged tag, built
from ./dir.
PORTS
● <host_port>:<container_port>
● Eg.
○ Ports:
■ 8080:80
ports:
- "3000"
- "3000-3005"
- "8000:8000"
- "9090-9091:8080-8081"
- "49100:22"
- "127.0.0.1:8001:8001"
- "127.0.0.1:5000-5010:5000-5010"
- "6060:6060/udp"
VOLUMES
● <host_path>:<container_path>
● Eg.
○ Volumes:
■ “/tmp/logs/:/app/logs/”
DEPENDS ON
● Runs dependent container first
DEPLOY
● Ignore this
deploy:
replicas: 6
restart_policy:
condition: on-failure
BUT WHY?
● Docker compose up and run ignore this as well.
DOCKER NETWORK
● Network drivers
○ Bridge
○ Host
○ None
○ Macvlan
○ Overlay
○ Network plugins
BRIDGE
● Default
○ Created by default
● User defined
○ User needs to create and attach it to container
■ During container run command
■ Attach on running container
BRIDGE DIFF
● Default
○ Accessible through ip address
● User defined
○ Accessible through both ip address and container name
HOST
● Uses host network
NONE
● No communication through network
MACVLAN
● Uses mac address
OVERLAY
● Uses for multi host containers
NETWORK PLUGINS
● Install and use third-party network plugins with Docker
COMMUNICATION
NETWORK SUMMARY
● User defined bridge network for single host containers
● Overlay for multi host containers communication
Docker Swarm
● What is docker swarm?
○ Clustering and
○ Scheduling tool
DOCKER COMPOSE vs SWARM
● Single vs Multiple hosts
● Swarm uses overlay network driver
UPCOMING
● Who is going to present on what?
Queries???
Thank You!!!

Docker session IV: Docker Compose and Docker Swarm

Editor's Notes

  • #2 *Not sure about docker kubernetes
  • #4 Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a Compose file to configure your application's services. Then, using a single command, you create and start all the services from your configuration. Written in python eventhough docker is completely written in go
  • #5 For MacOS / Windows: Already installed For Linux: install manually
  • #8 Load balancer Used for autoscaling
  • #12 What happens when docker file has image:redis? If image does not exist compose attempts to pull it.
  • #15 “3000” <- container port
  • #18 We ignore this for now.
  • #28 Myapp_default network
  • #30 Docker Swarm is a clustering and scheduling tool for Docker containers.