Skip to main content

Cheatsheet

Images

Search Docker Hub

docker search <query>

Download Image

docker pull <image>

Create Image

docker commit <container> new_image:tag
docker commit <container> new_image

Remove Image

docker image rm <image>

or

docker rmi <image>

Tag Image

docker tag <image> new_image:tag
docker tag <image> new_image

Display Image Information

docker image inspect

Build Image

docker image build -t <image_name> .

or

docker build -t <image_name> .

Containers

Run Container

docker container run <image>

or

docker run <image>
  • Execute Shell
docker container run -it <image> /bin/bash
  • Overwrite ENTRYPOINT and Execute Shell (Be careful, as it might not work as originally planned)
docker container run --entrypoint /bin/bash -it <image>

Port Forwarding

docker run -p <host-port>:<container-port> <image>

File System Mount

docker run -v /path/to/local:/path/to/container <image>

or

docker run --mount type=bind,source=/path/to/local,target=/path/to/container <image>

Running Containers

docker container ls -a

or

docker ps -a

Display Container stdout, stderr

docker container logs <container>

or

docker logs <container>

Display Container Information

docker container inspect <container>

Rename Container

docker container rename <old_name> <new_name>

Enter Shell of Running Container

docker container exec -it <container> /bin/bash

or

docker exec -it <container> /bin/bash

Stop Container

  • SIGTERM
docker container stop
  • SIGKILL
docker container kill

or

docker kill

Automatically Start Container when OS Boots

  • When you want to always start it
docker container run -d --restart=always <container>
  • When you don't want to execute the container stopped by docker container stop or similar
docker container run -d --restart=unless-stopped <container>
  • When you want to add a setting to a container that is already running
docker update --restart=[always,unless-stopped] <container>