Here's a comprehensive cheat sheet of Docker commands along with an example of each one. If you need more details on a particular command, just type the command and --help.
docker version
Display the Docker client and server versions.
$ docker version
docker info
Display system-wide information about Docker.
$ docker info
docker pull
Pull a Docker image from a container registry.
$ docker pull ubuntu:latest
docker images
List all locally available Docker images.
$ docker images
docker rmi
Remove one or more Docker images.
$ docker rmi ubuntu:latest
docker run
Create and start a new Docker container from an image.
$ docker run -d -p 8080:80 nginx
docker ps
List all running Docker containers.
$ docker ps
docker ps -a
List all Docker containers, including stopped ones.
docker ps -a
docker start
Start a stopped Docker container.
$ docker start my_container
docker stop
Stop a running Docker container gracefully.
$ docker stop my_container
docker kill
Forcefully terminate a running Docker container.
$ docker kill my_container
docker restart
Restart a running or stopped Docker container.
$ docker restart my_container
docker exec
Execute a command inside a running Docker container.
$ docker exec -it my_container bash
docker logs
Display the logs of a running Docker container.
$ docker logs my_container
docker build
Build a Docker image from a Dockerfile.
$ docker build -t my_app:latest .
docker-compose up
Create and start multiple Docker containers defined in a docker-compose.yml file.
$ docker-compose up -d
docker-compose down
Stop and remove containers defined in a docker-compose.yml file.
$ docker-compose down
docker network ls
List all Docker networks.
$ docker network ls
docker network create
Create a new Docker network.
$ docker network create my_network
docker volume ls
Description: List all Docker volumes.
$ docker volume ls
docker volume create
Create a new Docker volume.
$ docker volume create my_volume
docker inspect
Display detailed information about a Docker object (container, image, network, volume).
$ docker inspect my_container
docker prune
Remove unused Docker resources (containers, networks, volumes, images) to free up disk space.
$ docker system prune
docker export / docker import
Description: Export a container's file system as a tar archive and import it as a new image.
Example:
$ docker export my_container > container_backup.tar
$ docker import container_backup.tar my_image:latest
docker login
Log in to a container registry to push and pull images.
$ docker login myregistry.example.com
docker push
Push a Docker image to a container registry.