docker compose
template
docker-compose.yml
1version: '3.1' # if no version is specified then v1 is assumed. Recommend v2 minimum23services: # containers. same as docker run4 servicename: # a friendly name. this is also DNS name inside network5 image: # Optional if you use build:6 command: # Optional, replace the default CMD specified by the image7 environment: # Optional, same as -e in docker run8 volumes: # Optional, same as -v in docker run9 servicename2:1011volumes: # Optional, same as docker volume create1213networks: # Optional, same as docker network create
custom build images
see example here
to build this you need to use
1docker compose build
to remove it
1docker compose down -rmi local
will also remove all the custom image build
swarm
swarm comes inactivated by default.
to activate
1docker swarm init
list the managers and the workers
1docker node ls
swarm
1docker swarm --help
service
replaces the docker run for swarms
1docker service --help
run a service and ping an ip
1docker service create --name apl alpine ping 8.8.8.8
list all the service
1docker service ls
will show you all the tasks or else containers for this service
1docker service ps <name>
create replicas
1docker service update apl --replicas 3
swarm cluster - 3 nodes
using https://get.docker.com/ to install docker to a digital ocean droplet 1. create the droplet 2. install docker 3. init swarm in the public ip
1docker swarm init --advertise-addr 165.22.94.133
#install docker in a vm using userdata
1#!/bin/bash2curl -fsSL https://get.docker.com -o get-docker.sh3sh get-docker.sh4usermod -aG docker root # root needs to be the user. now in ec2 I thinkg the user is ec2-user or root
this is what you see when you do the bellow. see image
the *
explains where you are.
1docker node ls
take the manager token
you wanna do that for each node. you get the keys. they are always available and you can also change them in case of explosure
1docker node update --role manager <node_name>2docker swarm join-token manager
this will give you something between these lines
1docker swarm join --token SWMTKN-1-asdasda-94joeig0exhdk7319jgnwj662 xxx.xx.xx.xxx:2377
now you will now have to copy and paste this to the node