Docker Commands Cheat Sheet
docker pull <image_name>[:<tag>]
Downloads an image from Docker Hub or a registry.
Lists all locally available Docker images.
docker rmi <image_id> or <image_name>[:<tag>]
Removes one or more Docker images from your local machine.
docker build -t <image_name>[:<tag>] <path_to_Dockerfile>
Builds a Docker image from a Dockerfile.
docker push <image_name>[:<tag>]
Pushes an image to Docker Hub or a registry.
docker history <image_id> or <image_name>[:<tag>]
Shows the history of a Docker image.
docker tag <image_id> or <image_name>[:<tag>] <new_image_name>[:<new_tag>]
Creates an alias for an image.
docker save <image_name>[:<tag>] -o <path/to/save.tar>
Saves one or more images to a tar archive.
docker load -i <path/to/image.tar>
Loads an image from a tar archive.
Basic Container Commands
docker run [OPTIONS] <image_name>[:<tag>] [COMMAND] [ARG…]
Runs a command in a new container.
docker run -d <image_name>
Runs a container in detached mode (in the background).
docker run -p <host_port>:<container_port> <image_name>
Publishes a container’s port(s) to the host.
docker run –name <container_name> <image_name>
Assigns a name to the container.
docker run -v <host_path>:<container_path> <image_name>
Mounts a host directory as a volume in the container.
docker run –env <VARIABLE_NAME>=<VALUE> <image_name>
Sets environment variables in the container.
Lists running containers.
Lists all containers (running and stopped).
docker stop <container_id> or <container_name>
Stops a running container.
docker start <container_id> or <container_name>
Starts a stopped container.
docker restart <container_id> or <container_name>
Restarts a running container.
docker rm <container_id> or <container_name>
Removes one or more stopped containers.
docker rm -f <container_id> or <container_name>
Forces the removal of a running container.
docker logs <container_id> or <container_name>
Shows the logs of a container.
docker logs -f <container_id> or <container_name>
Follows the logs of a container in real-time.
docker exec -it <container_id> or <container_name> <command>
Executes a command inside a running container (interactive).
docker inspect <container_id> or <container_name>
Displays detailed information about a container.
docker stats [<container_id> or <container_name>…]
Displays live resource usage statistics of containers.
docker top <container_id> or <container_name>
Displays the running processes of a container.
docker cp <container_id>:<path_in_container> <host_path>
Copies files/folders between a container and the local filesystem.
docker commit [<container_id>] <repository_name>[:<tag>]
Creates a new image from a container’s changes.
Docker Network Commands
Lists Docker networks.
docker network create <network_name>
Creates a new Docker network.
docker network connect <network_name> <container_id> or <container_name>
Connects a container to a network.
docker network disconnect <network_name> <container_id> or <container_name>