Here are some of my favourite Docker related short-cuts and productivity hacks
Attach to an already running container, with an Interactive TTY
The most handy command that's been added to the Docker CLI is
exec, which means that we no longer need to fuss with things like
ns-enter. This also means that one doesn't have to bother much about containers running with an
entrypoint script, as getting to a
bash prompt is effortless
docker exec -it b5cc04781384 /bin/bash
Loopback IP inside a container, isn't always what you think it is!
If you try to access your host via
127.0.0.1, you'll be in for a rude surprise. Docker adds a new network interface,
docker0, to your iptables with the IP
Should you ever need to access ports on your host system, you'll need to reference that IP instead, and here's some further reading on the subject.
Remove all stopped containers
This will remove all stopped containers by getting a list of all containers with docker
ps -a -q and passing their ids to docker
rm. This should not remove any running containers, and it will warn you that it can’t remove a running image.
docker rm $(docker ps -a -q)
Remove all untagged images
In Docker parlance, untagged images are those that are 'dangling', and as such they've added a simplified filter to aid in their removal. This is a handy command to run, especially to reclaim some valuable disk space.
docker rmi $(docker images -q --filter "dangling=true")
What are your favourite Docker hacks, let me know in the comments below!