2 minutes
Docker Cheatsheet
This time, I’d like to share my Docker cheatsheet. Since it’s hard to remember every single command,
I find it better to write them down as notes.
But since it’s too much to write all at once, I’ll break it into smaller parts. For now, I’ll just focus on Docker Images and Docker Containers.
Hopefully, this will be helpful for anyone who’s looking for Docker commands!
1. Docker Image
| Description | Command |
|---|---|
| Build an Image from a Dockerfile | docker build -t IMAGE_NAME_PATH_TO_DOCKERFILE |
| List all local Images | docker images |
| Pull an image from Docker Hub | docker pull IMAGE_NAME:TAG |
| Remove a local image | docker rmi IMAGE_NAME:TAG |
| Tag an Image | docker tag SOURCE_IMAGE:TAG TARGET_IMAGE:TAG |
| Push an Image to Docker Hub | docker push IMAGE_NAME:TAG |
| Inspect details of an image | docker image inspect IMAGE_NAME:TAG |
| Save an image to a tar archive | docker save -o IMAGE_NAME.tar IMAGE_NAME:TAG |
| Load an image from a tar archive | docker load -i IMAGE_NAME.tar |
| Prune unused images | docker image prune |
2. Docker Container
| Description | Command |
|---|---|
| Run a container from an image | docker run IMAGE_NAME |
| Run a named container from an image | docker run --name container_name IMAGE_NAME:TAG |
| List all running containers | docker ps |
| List all containers | docker ps -a |
| Stop a running container | docker stop CONTAINER_NAME_OR_ID |
| Start a stopped container | docker start CONTAINER_NAME_OR_ID |
| Run container in interactive mode | docker run -it CONTAINER_NAME_OR_ID |
| Run container in interactive shell mode | docker run -it CONTAINER_NAME_OR_ID sh |
| Remove a stopped container | docker rm CONTAINER_NAME_OR_ID |
| Remove a running container (Forcefully) | docker rm -f CONTAINER_NAME_OR_ID |
| Inspect details of a container | docker container inspect CONTAINER_NAME_OR_ID |
| View container logs | docker logs CONTAINER_NAME_OR_ID |
| Pause a running container | docker pause CONTAINER_NAME_OR_ID |
| Unpause a paused container | docker unpause CONTAINER_NAME_OR_ID |