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.
12
docker psCONTAINER 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.
12345678
docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES3c5f1757561b gffnginx "/docker-entrypoint.β¦" 11 minutes ago Exited (1) 11 minutes ago gffnginxb5bd31ab21a5 gfffpm "php-fpm -F" 2 months ago Exited (255) 30 minutes ago 9000/tcp gfffpm2b06d7dcafeb gffmariadb "docker-entrypoint.sβ¦" 2 months ago Exited (255) 30 minutes ago 0.0.0.0:3306->3306/tcp gffmariadbe4851e3f9cff 1d2650a832ea "/docker-entrypoint.β¦" 2 months ago Exited (127) 2 months ago sad_kare29793124223a f99a6b7a50d1 "/docker-entrypoint.β¦" 2 months ago Exited (127) 2 months ago peaceful_shannone51094ce8550 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 910111213
docker systemUsage: docker system COMMANDManage DockerCommands: df Show docker disk usage events Get real time events from the server info Display system-wide information prune Remove unused dataRun 'docker system COMMAND --help' for more information on a command.
Docker Disk Free π
Using docker system df will reveal the current disk usage:
123456
docker system dfTYPE TOTAL ACTIVE SIZE RECLAIMABLEImages 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.
docker system pruneWARNING! This will remove: - all stopped containers - all networks not used by at least one container - all dangling images - all dangling build cacheAre you sure you want to continue? [y/N] yDeleted Containers:3c5f1757561b57e274238c5269eba86ef9826a5eed94a4808ee8428175281115..e51094ce855021a959c92804713f8692648b77ba694df51fd7203a31b94125cbDeleted Networks:gff-netDeleted Images:deleted: sha256:55dace38659aaf4cf1ec316275ed02767f08c288b95dfdbf3404fbf2fdfaae26..deleted: sha256:d0b7778a667d57124f275b189a5d3a14d36781bb978074d53fc4fc25840dcfd0deleted: sha256:bcdbfacb472492673657ff182cedcdee564dbe023e9d4f0718a25d5ab48ebef5Deleted build cache objects:n80kf8n89i6mlufwp61yeqvtoz5mcxx5zazdz5m7nnyf00lvea..et8gqulnmn29njhpv4vv6bnxdz2lmrrlubl58ytq844mmb1fljTotal 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 π.