Docker Cheatsheet
Most commonly used Docker commands. The Github repo could be found here.
Most Common Docker Commands
Command | Explanation | Shorthand |
---|---|---|
docker image ls | Lists all images | docker images |
docker image rm <image> | Removes an image | docker rmi |
docker image pull <image> | Pulls image from a docker registry | docker pull |
docker container ls | Lists running containers | docker ps |
docker container ls -a | Lists all containers | docker ps -a |
docker container run <image> | Runs a container from an image | docker run <image> |
docker container rm <container> | Removes a container | docker rm <container> |
docker container stop <container> | Stops a container | docker stop <container> |
docker container exec <container> | Executes a command inside the container | docker exec <container> |
Running and Stopping Containers
Command | Explanation | Example |
---|---|---|
docker run <image> | Running an image | docker run ubuntu:20.04 |
docker run -t <image> | Running tty without sending messages | docker run -t ubuntu:20.04 |
docker run -it <image> | Running tty and sending messages | docker run -it ubuntu:20.04 |
docker run -d -it --name <container> <image> <command> | Running tty and sending messages detached mode | docker run -d -it --name loop ubuntu:20.04 sh -c "while true; do date; sleep 1; done" |
docker logs -f <container> | Outputs container’s log | docker logs -f loop |
docker pause <container> | Pauses container | docker pause loop |
docker unpause <container> | Unpauses container | docker unpause loop |
-t
creates tty-i
pass the STDIN to the container--name <container>
passes the container name