Docker Basics
docker version
Shows the Docker version installed on your system.
docker version
docker info
Displays system-wide information about Docker, including number of containers, images, and other details.
docker info
docker help
Provides help on using Docker commands.
docker help
Working with Images
docker pull
Downloads an image from a Docker registry (e.g., Docker Hub).
docker pull <image_name>
docker images
Lists all the images on your local machine.
docker images
docker rmi
Removes one or more images from your local machine.
docker rmi <image_id>
docker tag
Tags an image with a new name.
docker tag <existing_image> <new_image:tag>
docker build
Builds an image from a Dockerfile.
docker build -t <image_name:tag> <path_to_dockerfile>
docker push
Uploads an image to a Docker registry.
docker push <image_name:tag>
Working with Containers
docker run
Runs a container from an image.
docker run -d --name <container_name> <image_name>
docker ps
Lists all running containers.
docker ps
docker ps -a
Lists all containers, including stopped ones.
docker ps -a
docker stop
Stops a running container.
docker stop <container_id>
docker start
Starts a stopped container.
docker start <container_id>
docker restart
Restarts a container.
docker restart <container_id>
docker rm
Removes a container.
docker rm <container_id>
docker logs
Displays the logs of a container.
docker logs <container_id>
docker exec
Runs a command in a running container.
docker exec -it <container_id> <command>
docker attach
Attaches your terminal to a running container.
docker attach <container_id>
Container Networking
docker network ls
Lists all Docker networks.
docker network ls
docker network create
Creates a new Docker network.
docker network create <network_name>
docker network inspect
Displays detailed information about a network.
docker network inspect <network_name>
docker network connect
Connects a container to a network.
docker network connect <network_name> <container_id>
docker network disconnect
Disconnects a container from a network.
docker network disconnect <network_name> <container_id>
Docker Volumes
docker volume ls
Lists all Docker volumes.
docker volume ls
docker volume create
Creates a new Docker volume.
docker volume create <volume_name>
docker volume inspect
Displays detailed information about a volume.
docker volume inspect <volume_name>
docker volume rm
Removes a Docker volume.
docker volume rm <volume_name>
Docker Compose
docker-compose up
Builds, (re)creates, starts, and attaches to containers for a service defined in a
docker-compose.yml
file.docker-compose up
docker-compose down
Stops and removes containers, networks, volumes, and images created by
docker-compose up
.docker-compose down
docker-compose ps
Lists containers started by Docker Compose.
docker-compose ps
docker-compose logs
Displays log output from services managed by Docker Compose.
docker-compose logs
docker-compose exec
Executes a command in a running service container.
docker-compose exec <service_name> <command>
Cleanup Commands
docker system prune
Removes all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes.
docker system prune
docker container prune
Removes all stopped containers.
docker container prune
docker image prune
Removes unused images.
docker image prune
docker volume prune
Removes all unused volumes.
docker volume prune
Inspecting and Debugging
docker inspect
Returns low-level information about Docker objects.
docker inspect <container_id or image_id>
docker diff
Inspects changes to files or directories on a container’s filesystem.
docker diff <container_id>
Security
docker scan
Scans your Docker images for vulnerabilities.
docker scan <image_name>
By mastering these commands, you can effectively manage Docker images, containers, networks, volumes, and more, enhancing your ability to deploy and maintain containerized applications.