Docker and Swarm cheatsheet

Basic

Action Command example
Run a container named “web”and expose service on port docker run -d -p 80:80 --name web nginx
Stop container docker stop web
Remove container docker rm web
Run the same “web “container and set a point as web content docker run -d -v $PWD/web:/usr/share/nginx/html:ro -p 80:80 --name web nginx

Build images

Action Command example
Build docker build -t alpine-mongo .
List built images docker images

Compose and swarm

Swarm

  • The manager node generates the swarm
  • A second node executes the output
Action Command example
Init manager node docker swarm init
New node orchestrated by manager docker swarm join --token SWMTKN-1-69yjut8vfhelsyujw0kayrifdj42a4dj74j29mykwekkyuczbq-6xw587ux0fr1gykx8rddy6rmd 192.168.1.205:2377s

Compose

  • Compose groups microservice content to set up a stack
Action Command example
Deploy service in stack docker stack deploy -c wordpressv3.yml wordpress