Docker Commands

Prefix with sudo if the current user is not root (admin) ~ applicable to Linux environment.

General

1
2
3
4
5
6
7
8
9
docker version ~ display version
docker run hello-world ~ run hello-world test container
docker logs [CONTAINER NAME] ~ works even if the container is stopped
docker images
docker ps –all ~ list containers
docker network ls ~ list networks

docker rm $(docker ps -a -q) ~ deletes all excited containers
​ first run sudo -i ~ switch to root

Stats

Along with the linux memory usage command ~ sudo free -m you can also check each containers stats:

1
2
3
sudo docker stats [CONTAINER NAME]

(CTRL C to quit)

Copy

Copy from the logs dir to the host

1
2
sudo docker cp [CONTAINER NAME]:/app/logs/ /home/carl/obfuscation/
you can also specify the current dir with a period .

Copy to container

1
sudo docker cp /path/on/host [CONTAINER NAME]:/path/on/container

EXEC session to container

1
sudo docker exec -it 279 sh (where 279 is the start of the container ID)
1
2
sudo docker exec compose-angular-web cat /etc/nginx/nginx.conf
sudo docker exec compose-angular-web ls /usr/share/nginx/html

Interactive processes (like a shell)

This was helpful when debugging pgDash when the container would not start and we needed to run in interactive mode, run from bash their command to start the app and then cat out the logs.

1
2
3
docker run -it –entrypoint /bin/bash pgdash_image    (note the – – before entrypoint)
/usr/sbin/pgdashd
cat /var/log/pgdash/pgdash.log

<* https://docs.docker.com/engine/reference/run/#operator-exclusive-options>

Network

1
2
3
sudo docker network connect golden-gate [CONTAINER NAME]
sudo docker network connect bridge [CONTAINER NAME]
sudo docker network disconnect golden-gate [CONTAINER NAME]

Inspect

1
2
3
4
docker network inspect [NETWORK NAME]
docker container inspect [CONTAINER NAME]
docker inspect -f “{{ .NetworkSettings.Networks.nat.IPAddress }}” [CONTAINER NAME]
~ shows its IP to get around the WinNAT plow

Volumes

1
2
3
docker volume ls
docker volume inspect my-vol
sudo docker volume prune ~ deletes volumes not in use

Options

Options are passed after commands, I can never rememeber what they all do :)

1
2
-t                 ~ Name and optionally a tag in the ‘name:tag’ format
~ docker build -t docker101tutorial .