DEV Community

Cover image for 5 Docker Commands You Don't Know Yet
Jonas Scholz for Sliplane

Posted on • Updated on

5 Docker Commands You Don't Know Yet

You just started with your Docker Journey and think you know everything? Strap in and learn some fancy new commands to impress your friends and boss with!

1. docker system df

If you're anything like me, you're probably building docker containers left and right without really thinking about where everything is stored. Want to find out how much storage your containers, images, volumes, and cache artifacts need? Simply run docker system df and be amazed at how much of your disk is just used for docker 🤓

PS: Too much space used? Try this: docker system prune --all

docker system df

2. docker stats

Continuing with monitoring commands, did you know that you can see exactly how much resources each container is using? You can see the CPU, memory, and even network usage! Especially useful if you're running containers you haven't built yourself and you need to keep a close eye on them 👀

Simply run docker stats to see all the juicy details!

docker stats

3. docker build --cpu-quota=50000

Everyone knows that Docker likes to use all of the available CPU resources, making everything else SUPER slow during the build process. But what if we could tell Docker how much of your available CPU to use? 🤔

The solution to this problem is the --cpu-quota flag of the docker build command which isn't even documented when executing docker build --help! The --cpu-quota flag allows you to define how much of your CPU cores can be used. Every core equals 100000. If you have a 4 core CPU and you want docker build to use a maximum of 80% of your CPU, you would need to calculate 4 * 100000 * 0.8 = 320000, and then set --cpu-quota 320000. On Linux or Macos you can also calculate it automatically:

# Linux
docker build --cpu-quota $(( $(grep -c ^processor /proc/cpuinfo) * 100000 * 8 / 10 )) -t your_image_name your_docker_directory

# MacOS
docker build --cpu-quota $(( $(sysctl -n hw.logicalcpu) * 100000 * 8 / 10 )) -t your_image_name your_docker_directory
Enter fullscreen mode Exit fullscreen mode

4. docker cp

The docker cp command is useful for copying files or directories between a running Docker container and your local filesystem. This is especially handy when you need to extract logs or output files from a container. The command is quite simple: You need your containers name, the path of the file inside your container, and the path on your filesystem where the file should be copied to. Then combine it to get something like that:

docker cp

5. docker top

Alright, last but not least we have docker top! docker top prints out the currently running processes inside a running container. If you start a container with --name myapp, simply run docker top myapp and you will see what is going on inside the container. This is especially great if you're debugging a container and you're not sure if your CMD command is correct!

docker top containerName


I really hope you learned one or two new docker commands today! If you need any help, or have any questions about these commands, please write a comment! And if you want to deploy your own Dockerized Apps, check out Sliplane!

Top comments (14)

avwerosuoghene profile image
Avwerosuoghene Darhare-Igben

The --cpu-quota flag is indeed quite valuable. Appreciate you sharing this!

citronbrick profile image

Here are links to the reference documentation:

  1. system (quite insufficient information)
  2. stats
  3. build options
  4. cp
  5. top (could do with an example)
code42cate profile image
Jonas Scholz

Thanks! Completely forgot to add them:)

onlinemsr profile image
Raja MSR

Thanks for sharing this informative post on Docker commands. I found it very helpful and easy to understand. The way you explained the commands with examples made it easier for me to grasp the concepts.

eduardo_picado profile image
Eduardo Picado

Great tips! Another good one is to use lazydocker

code42cate profile image
Jonas Scholz

Ohh that looks nice, didn't know it before. Going to check it out!

leoantony72 profile image
Leo Antony

that was interesting

parzival_computer profile image


code42cate profile image
Jonas Scholz

Glad that you found it interesting:)

thecodersden profile image
Rajdip Bhattacharya

Really cool!

gseriche profile image
Gonzalo Seriche Vega

The "docker build --cpu-quota" didn't know their existence; I agree with you; docker ate all the CPU, and you must go for a coffee in the nearby coffee shop.

khemraksa profile image
Khem Raksa Peou (BugsBuster)

Really Cool!

code42cate profile image
Jonas Scholz

glad you enjoyed it :)

wimadev profile image
Lukas Mauser

Wow, build cache can really bite into your disk space, never took the time to inspect. Thanks! 🙌🏻