This guide gathers the basic commands every Docker user will frequently need. Personally, I keep getting back to it from time to time when my Docker knowledge gets rusty. Hope it helps you too!
docker images
docker rmi <image-name>
docker ps
docker ps -a
docker ps -a -q
docker rm $(docker ps -a -q)
docker system prune
docker system prune -a
Note the dot (.) at the end
docker build -t image-name .
docker build -t image-name -f /path/to/your/Dockerfile .
Note: Run = create + start
docker run -dit image-name:latest
docker create image-name:latest
docker start <container-id>
Note: Assuming image's OS is Ubuntu/Debian
docker exec -it <container-id> sh
docker stop <container-id>
docker rm <container-id>
docker rm -f <container-id>
docker run -p <local-port>:<container-port> image-name:latest
E.g.: If the image exposes port 8008
and you want to use port 3000
on the machine hosting the container:
docker run -p 3000:8008 image-name:latest
docker logs <container-id>
Top comments (6)
Looks good. Thanks for sharing:)
Glad it's helpful!
This is awesome!
Thanks!
I need this, thanks! :)
Anytime!