Docker Cheatsheet

Basic commands


>> docker images (view images)
>> docker ps -a (view containers status)
>> docker pull ubuntu (pull images)

>> docker run -d ubuntu (deattached mode)
>> docker run -it ubuntu (interactive mode)
>> docker run -d --name myubuntu ubuntu (naming)
>> docker run -it --name myubuntu ubuntu /bin/bash (running docker with bash)

>> docker start myubuntu
>> docker stop myubuntu

>> docker rm myubuntu (remove containers)
>> docker rmi ubuntu:latest (remove image ubuntu:<tagname>)
>> docker rm $(docker ps -aq) (remove all containers)
>> docker rmi $(docker images -q)

Swarm

>> docker swarm init --listen-addr [your_ip]:2377 --secret SECRET123
note: engine port-2375;secure engine port-2376;swarm port-2377

>> docker info (view swarms)

Join as manager

>> docker swarm join --secret SECRET123 \
--ca-hash sha256:e293898euq48uiu \
192.168.1.1:2377 \
--manager \
--listen-addr 192.168.1.2:2377

Join as worker and automatically accepted

>> docker swarm join --secret SECRET123 \
--ca-hash sha256:e293898euq48uiu \
192.168.1.1:2377 \
--listen-addr 192.168.1.2:2377

Auto Join Manager-Worker

>> docker swarm init --listen-addr [your_ip]:2377 --secret SECRET123 --auto-accept worker
>> docker swarm init --listen-addr [your_ip]:2377 --secret SECRET123 --auto-accept manager
>> docker swarm init --listen-addr [your_ip]:2377 --secret SECRET123 --auto-accept worker,manager

Note: Manager needs acceptance/approval to join, worker doesn't need

list swarm and its status

>> docker node ls

>> docker node accept 7ywq67qwyf68qr6ryuy

Promote worker to manager

>> docker node promote 9u35d53gd6yfsd36dghdgd (the ID you get when you do, node ls)
Advertisements