7 Ninja-Level Docker Commands
Seven of my favorite Docker commands, from checking what each container eats to wiping out test junk in one go. Bookmark it and let it be your guardian angel.

I wrote this post in Spanish in 2022 and adapted it to English in 2026.
In this post I'm going to show you 7 of my favorite Docker commands. It's not a proper tutorial. Just bookmark it and let it be your guardian angel.
1. See how many resources each container is eating #
Of all the handy Docker commands you'll see today, this one shows the resources your containers are using. Great for getting an idea of how much budget you'll need to deploy your app on a cloud service.
docker stats
docker ps -f id=34b0df6e0f94
Remember to swap 34b0df6e0f94 for the id of the container you're checking.
2. Clean up the system #
docker system prune
This command deletes every volume, image, container and network that's no longer in use.
Before you run it, I recommend running:
docker ps -adocker volume lsdocker network ls
...and checking you're not about to nuke anything you'll regret, because this command deletes for real, and there's no Ctrl + Z to save you from a screwup.
3. Get every bit of info about a container #
docker inspect <container_id>
This command will spit so much crap into your terminal that it's a bit hard to read it all, because it takes "all the information" very literally: volumes, IPs, networks, the works.
So you don't get dizzy in all that output, I recommend parsing it as JSON with jq so you can look at everything in detail.
Want one specific key? Use jq, the go-to JSON parser on Linux
docker inspect <container_id> | jq '.[].<dict_key>'
Examples:
- Show the network info
docker inspect <container_id> | jq '.[].NetworkSettings'
- Show the volumes
docker inspect <container_id> | jq '.[].Mounts'
- To reach a subkey, chain keys with a dot
docker inspect 34b0df6e0f94 | jq '.[].State.Status'
docker inspect 34b0df6e0f94 | jq '.[].NetworkSettings.Networks'
4. Add a file from the internet to a container image without installing wget #
ADD example.com/tmp /tmp/
This one lets you skip installing wget in your containers, which also saves you the update. You're welcome.
5. Retry restarting a container only a set number of times #
restart: on-failure:<times_to_try>
Example:
restart: on-failure:10
This works better than restart: always because it stops trying when something keeps failing.
6. See what time each log entry happened #
docker logs --tail=10 -t <container_id>
Want more lines? Just bump up the tail and you're done.
7. Delete every container from an image #
docker rm $(docker stop $(docker ps -a -q --filter ancestor=<image-name> --format="{{.ID}}"))
Let me slow down and explain this one, and why it's so useful.
When you're developing, there are times you need to keep spinning up containers while you test, and afterwards you're left with a TON of containers sitting there in "exited" status.
Couldn't you avoid that with --rm when you run the container?
Yes, but it doesn't work in every case.
Couldn't you just delete the failed container before starting another one?
Also yes, but that's a royal pain.
That's where this command comes in: you can create containers like a maniac, knowing that when testing's over you can wipe out all the junk with a single command, without touching the dangerous docker system prune.


