0% found this document useful (0 votes)
19 views4 pages

Important Docker Commands

Uploaded by

foneuk99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views4 pages

Important Docker Commands

Uploaded by

foneuk99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

‭All Docker Commands‬

‭ ere's a comprehensive list of commonly used Docker commands, along with their‬
H
‭usage:‬

‭Basic Docker Commands‬

‭1.‬ ‭
docker version‬
‭: Displays Docker version information.‬
‭2.‬ ‭
docker info‬
‭: Provides detailed information about the‬‭Docker installation.‬
‭3.‬ ‭
docker --help‬
‭: Lists all available Docker commands‬‭and options.‬

‭Image Management Commands‬

‭1.‬ d
‭ocker pull <image>‬ ‭: Downloads an image from a Docker‬‭registry (e.g., Docker‬
‭Hub).‬
docker pull nginx‬
‭○‬ ‭Example:‬‭
‭2.‬ ‭
docker images‬
‭: Lists all Docker images available on‬‭the system.‬
docker images‬
‭○‬ ‭Example:‬‭
‭3.‬ ‭
docker rmi <image>‬
‭: Deletes a Docker image from the‬‭system.‬
docker rmi nginx‬
‭○‬ ‭Example:‬‭
‭4.‬ ‭
docker build -t <name> <path>‬
‭: Builds a Docker image‬‭from a Dockerfile.‬
docker build -t myapp:latest .‬
‭○‬ ‭Example:‬‭
‭5.‬ d
‭ocker tag <source_image> <target_image>‬ ‭: Tags an‬‭image with a new‬
‭name.‬
docker tag nginx:latest myrepo/nginx:v1‬
‭○‬ ‭Example:‬‭
‭6.‬ ‭
docker save -o <file> <image>‬
‭: Saves an image to a‬‭tar archive.‬
docker save -o nginx.tar nginx:latest‬
‭○‬ ‭Example:‬‭
‭7.‬ ‭
docker load -i <file>‬
‭: Loads an image from a tar archive.‬
docker load -i nginx.tar‬
‭○‬ ‭Example:‬‭

‭Container Management Commands‬

‭1.‬ ‭
docker run <image>‬
‭: Creates and starts a new container‬‭from an image.‬
docker run nginx‬
‭○‬ ‭Example:‬‭
‭2.‬ d
‭ocker run -d <image>‬ ‭: Runs a container in detached‬‭mode (in the‬
‭background).‬
docker run -d nginx‬
‭○‬ ‭Example:‬‭
‭3.‬ ‭
docker run -it <image>‬
‭: Runs a container interactively with a terminal.‬
docker run -it ubuntu bash‬
‭○‬ ‭Example:‬‭
‭4.‬ ‭
docker ps‬
‭: Lists all running containers.‬
docker ps‬
‭○‬ ‭Example:‬‭
‭5.‬ ‭
docker ps -a‬
‭: Lists all containers, including stopped‬‭ones.‬
docker ps -a‬
‭○‬ ‭Example:‬‭
‭6.‬ ‭
docker stop <container>‬
‭: Stops a running container.‬
docker stop my_container‬
‭○‬ ‭Example:‬‭
‭7.‬ ‭
docker start <container>‬
‭: Starts a stopped container.‬
docker start my_container‬
‭○‬ ‭Example:‬‭
‭8.‬ ‭
docker restart <container>‬
‭: Restarts a container.‬
docker restart my_container‬
‭○‬ ‭Example:‬‭
‭9.‬ ‭
docker rm <container>‬
‭: Deletes a stopped container.‬
docker rm my_container‬
‭○‬ ‭Example:‬‭
docker exec -it <container> <command>‬
‭10.‬‭ ‭: Executes a‬‭command in a‬
‭running container.‬
docker exec -it my_container bash‬
‭○‬ ‭Example:‬‭
docker logs <container>‬
‭11.‬‭ ‭: Displays logs from a container.‬
docker logs my_container‬
‭○‬ ‭Example:‬‭
docker attach <container>‬
‭12.‬‭ ‭: Attaches to a running container's‬‭console.‬
docker attach my_container‬
‭○‬ ‭Example:‬‭
docker kill <container>‬
‭13.‬‭ ‭: Forcefully stops a container.‬
docker kill my_container‬
‭○‬ ‭Example:‬‭

‭Container Networking Commands‬

‭1.‬ ‭
docker network ls‬
‭: Lists all Docker networks.‬
docker network ls‬
‭○‬ ‭Example:‬‭
‭2.‬ ‭
docker network create <name>‬
‭: Creates a new Docker‬‭network.‬
docker network create my_network‬
‭○‬ ‭Example:‬‭
‭3.‬ ‭
docker network rm <name>‬
‭: Deletes a Docker network.‬
docker network rm my_network‬
‭○‬ ‭Example:‬‭
‭4.‬ d
‭ocker network connect <network> <container>‬ ‭: Connects‬‭a container to‬
‭a network.‬
docker network connect my_network my_container‬
‭○‬ ‭Example:‬‭
‭5.‬ d
‭ocker network disconnect <network> <container>‬ ‭: Disconnects‬‭a‬
‭container from a network.‬
docker network disconnect my_network my_container‬
‭○‬ ‭Example:‬‭

‭Volume Management Commands‬

‭1.‬ ‭
docker volume ls‬
‭: Lists all Docker volumes.‬
docker volume ls‬
‭○‬ ‭Example:‬‭
‭2.‬ ‭
docker volume create <name>‬
‭: Creates a new Docker volume.‬
docker volume create my_volume‬
‭○‬ ‭Example:‬‭
‭3.‬ ‭
docker volume rm <name>‬
‭: Deletes a Docker volume.‬
docker volume rm my_volume‬
‭○‬ ‭Example:‬‭
‭4.‬ ‭
docker volume inspect <name>‬
‭: Displays detailed information‬‭about a volume.‬
docker volume inspect my_volume‬
‭○‬ ‭Example:‬‭
‭5.‬ d
‭ocker run -v <volume>:/path/in/container <image>‬ ‭: Mounts a volume‬
‭into a container.‬
‭○‬ ‭Example:‬‭docker run -v my_volume:/data nginx‬

‭Dockerfile Commands‬

‭1.‬ ‭
docker build -f <Dockerfile>‬
‭: Builds an image from‬‭a specific Dockerfile.‬
docker build -f Dockerfile .‬
‭○‬ ‭Example:‬‭

‭Docker Compose Commands‬

‭1.‬ ‭
docker-compose up‬ docker-compose.yml‬‭file.‬
‭: Starts containers defined in a‬‭
docker-compose up‬
‭○‬ ‭Example:‬‭
‭2.‬ ‭
docker-compose down‬
‭: Stops and removes containers,‬‭networks, and volumes‬
docker-compose up‬
‭created by‬‭ ‭.‬
docker-compose down‬
‭○‬ ‭Example:‬‭
‭3.‬ ‭
docker-compose ps‬
‭: Lists containers created by Docker‬‭Compose.‬
docker-compose ps‬
‭○‬ ‭Example:‬‭
‭4.‬ ‭
docker-compose logs‬
‭: Shows logs for containers managed‬‭by Docker Compose.‬
docker-compose logs‬
‭○‬ ‭Example:‬‭
‭5.‬ ‭
docker-compose build‬
‭: Builds or rebuilds services‬‭defined in a Compose file.‬
docker-compose build‬
‭○‬ ‭Example:‬‭

‭Image and Container Inspection‬

‭1.‬ d
‭ocker inspect <container_or_image>‬ ‭: Returns low-level‬‭information about‬
‭a container or image.‬
docker inspect my_container‬
‭○‬ ‭Example:‬‭
‭2.‬ ‭
docker top <container>‬
‭: Displays running processes‬‭in a container.‬
docker top my_container‬
‭○‬ ‭Example:‬‭
‭3.‬ ‭
docker stats‬
‭: Displays resource usage statistics of‬‭running containers.‬
docker stats‬
‭○‬ ‭Example:‬‭

‭System Cleanup Commands‬

‭1.‬ ‭
docker system df‬
‭: Displays information about disk‬‭usage by Docker.‬
docker system df‬
‭○‬ ‭Example:‬‭
‭2.‬ d
‭ocker system prune‬ ‭: Removes unused data (stopped containers, unused‬
‭networks, dangling images).‬
docker system prune‬
‭○‬ ‭Example:‬‭
‭3.‬ ‭
docker image prune‬
‭: Removes unused and dangling images.‬
docker image prune‬
‭○‬ ‭Example:‬‭
‭4.‬ ‭
docker container prune‬
‭: Removes all stopped containers.‬
docker container prune‬
‭○‬ ‭Example:‬‭

‭Other Commands‬

‭1.‬ d
‭ocker commit <container> <image>‬ ‭: Creates a new image‬‭from a‬
‭container's changes.‬
docker commit my_container my_image‬
‭○‬ ‭Example:‬‭
‭2.‬ ‭
docker export <container>‬
‭: Exports a container's filesystem‬‭to a tar archive.‬
docker export my_container > container.tar‬
‭○‬ ‭Example:‬‭
‭3.‬ ‭
docker import <file>‬
‭: Imports a tarball to create‬‭an image.‬
docker import container.tar my_imported_image‬
‭○‬ ‭Example:‬‭

‭ hese Docker commands cover the most common activities when working with Docker,‬
T
‭ranging from managing containers, images, and volumes to orchestrating multi-container‬
‭applications with Docker Compose. Mastering these commands helps in efficiently creating,‬
‭deploying, and managing containerized applications.‬

You might also like