Everyday Docker 🐳

The docker command 🐳

Using docker on the command line. Maybe you are a Docker expert, maybe you know a little about Docker, or maybe you just know enough to leverage Docker for local development with lando or sail.

This post intends to show you some basics to help clean up and stabilize your local development environment if you are using Docker.

Running ContainersπŸƒβ€β™€οΈβ€βž‘οΈ

The docker ps command will reveal the current running containers on your system.

1
2
docker ps
CONTAINER ID   IMAGE     COMMAND

Currently I have 0️⃣ containers running on my system.

All Containers β˜‘

The docker ps -a command show all containers, running and stopped on your system.

1
2
3
4
5
6
7
8
docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS                        PORTS                    NAMES
3c5f1757561b   gffnginx       "/docker-entrypoint.…"   11 minutes ago   Exited (1) 11 minutes ago                              gffnginx
b5bd31ab21a5   gfffpm         "php-fpm -F"             2 months ago     Exited (255) 30 minutes ago   9000/tcp                 gfffpm
2b06d7dcafeb   gffmariadb     "docker-entrypoint.s…"   2 months ago     Exited (255) 30 minutes ago   0.0.0.0:3306->3306/tcp   gffmariadb
e4851e3f9cff   1d2650a832ea   "/docker-entrypoint.…"   2 months ago     Exited (127) 2 months ago                              sad_kare
29793124223a   f99a6b7a50d1   "/docker-entrypoint.…"   2 months ago     Exited (127) 2 months ago                              peaceful_shannon
e51094ce8550   f99a6b7a50d1   "/docker-entrypoint.…"   2 months ago     Exited (127) 2 months ago                              nervous_benz

Adding the -a flag shows that there are a total of 6️⃣ containers total on my system.

Docker System Command 🧼

Using the docker system commands can help show how many resources are currently used by Docker. And therefore what can be reclaimed if you need it.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
docker system

Usage:  docker system COMMAND

Manage Docker

Commands:
  df          Show docker disk usage
  events      Get real time events from the server
  info        Display system-wide information
  prune       Remove unused data

Run 'docker system COMMAND --help' for more information on a command.

Docker Disk Free πŸ†“

Using docker system df will reveal the current disk usage:

1
2
3
4
5
6
docker system df
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          45        5         13.74GB   12.74GB (92%)
Containers      6         0         5.64kB    5.64kB (100%)
Local Volumes   100       4         4.935GB   4.519GB (91%)
Build Cache     109       0         89.41MB   89.41MB

Docker System Prune πŸ”₯

We can use docker system prune to clean up disk space, unused networks, volumes.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
docker system prune
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
  - all dangling build cache

Are you sure you want to continue? [y/N] y
Deleted Containers:
3c5f1757561b57e274238c5269eba86ef9826a5eed94a4808ee8428175281115
.
.
e51094ce855021a959c92804713f8692648b77ba694df51fd7203a31b94125cb

Deleted Networks:
gff-net

Deleted Images:
deleted: sha256:55dace38659aaf4cf1ec316275ed02767f08c288b95dfdbf3404fbf2fdfaae26
.
.
deleted: sha256:d0b7778a667d57124f275b189a5d3a14d36781bb978074d53fc4fc25840dcfd0
deleted: sha256:bcdbfacb472492673657ff182cedcdee564dbe023e9d4f0718a25d5ab48ebef5

Deleted build cache objects:
n80kf8n89i6mlufwp61yeqvto
z5mcxx5zazdz5m7nnyf00lvea
.
.
et8gqulnmn29njhpv4vv6bnxd
z2lmrrlubl58ytq844mmb1flj

Total reclaimed space: 447.2MB

Here we can see that I've regained 447MB of space. Modest, but I've easily seen it regain GBs of space πŸͺ on my system.

Conclusion 🎁

Docker is a powerful tool for deployment and local development. In particular for local development the commands discussed heretofore

can help keep your system clean and running smooth. If docker runs out of disk space things can start to fail in non-graceful ways. Making debugging 🐞 difficult if not impossible. So, leveraging these commands on the regular can help keep you sane and productive πŸ“ˆ.

thanks for reading.

πŸ“¨ Contact GSPC βœ‰οΈ

AWS Certified Certified Terraform Associate AWS Serverless AWS Certified Developer Associate GitHub Foundations Certification GitHub Actions Certification Certified SysOps Administrator Certified AWS Security Specialist Certified AWS DevOps Engineer Professional GCP: Cloud Digital Leader Certification Badge