18 Docker commands cheat sheet

In this tutorial, we will see a docker cheat sheet with 18 useful commands that you would generally use while working with docker containers.

1. Docker run

Using a docker image and running a container.

docker run <image name>

2. Docker build

Build an image from a docker file.

docker build -t appname:latest

3. Docker pull

Pull a docker image from the cloud registry.

docker pull <image name>

4. Docker push

Push a docker image to the cloud registry.

docker push <image name>

5. Docker images

List all the docker images.

docker images

6. Docker ls

List all the running docker containers.

docker container ls

7. Docker start

Start a docker container.

docker start <container name>

8. Docker stop

Stop a docker container.

docker stop <container name>

9. Docker restart

Restart a docker container.

docker restart <container name>

10. Docker kill

Forcefully terminate a docker container.

docker kill <container name>

11. Docker rm

Remove a stopped docker container.

docker rm <container name>

12. Docker rmi

Remove a docker image.

docker rmi <container name>

13. Docker exec

Run a command in a running docker container.

docker exec -it <container name> bash

14. Docker logs

View the logs of a docker container.

docker logs <container name>

15. Docker inspect

Inspect a docker container or image.

docker inspect <container name>

16. Docker system prune

Remove everything.

docker system prune

17. Docker save image

Save a docker image to a tar archive

docker save <image name> > <image name>.tar

18. Docker load image

Load a docker image from a tar archive

docker load < <image name>.tar