Navigate back to the homepage

learning docker - day 3

Christos Paschalidis
December 16th, 2020 · 1 min read

docker compose



1version: '3.1' # if no version is specified then v1 is assumed. Recommend v2 minimum
3services: # containers. same as docker run
4 servicename: # a friendly name. this is also DNS name inside network
5 image: # Optional if you use build:
6 command: # Optional, replace the default CMD specified by the image
7 environment: # Optional, same as -e in docker run
8 volumes: # Optional, same as -v in docker run
9 servicename2:
11volumes: # Optional, same as docker volume create
13networks: # 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 comes inactivated by default.

to activate

1docker swarm init

list the managers and the workers

1docker node ls


1docker swarm --help


replaces the docker run for swarms

1docker service --help

run a service and ping an ip

1docker service create --name apl alpine ping

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 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

#install docker in a vm using userdata

2curl -fsSL -o
4usermod -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

now you will now have to copy and paste this to the node

More articles from blog for tech

learning docker - day 2

Docker commands I learned today

December 15th, 2020 · 1 min read

learning docker - day 1

Docker commands I learned today

December 14th, 2020 · 1 min read
© 2020–2021 blog for tech
Link to $ to $