Quick and useful Docker commands and configs

Quick and useful Docker commands and configs

Here is a list of some docker snippets that I use daily.

Create a tagged image from Dockerfile

docker build -t tag_name /path/to/

Run a docker image in detached mode

docker run -p local_port:remote_port -d tag_name

Remove stopped containers

docker rm $(docker ps -a -q)

Remove untagged images

docker rmi $(docker images | grep "^<none>" | awk "{print $3}")

Stop and remove all containers

docker stop $(sudo docker ps -a -q) && sudo docker rm $(sudo docker ps -a -q)

Show Docker containers memory consumption

sudo docker stop $(sudo docker ps -a -q) && sudo docker rm $(sudo docker ps -a -q) && sudo docker rmi $(sudo docker images -a -q)