Compatibility / Dependency - Long Time Setup - Difference Dev/Test/Prod Environment
Containerize Applications - Run each service with its own dependencies in separate container
Command | Example | What It Does |
---|---|---|
docker version |
docker version |
Displays Docker version details of both client and server. |
docker info |
docker info |
Shows detailed information about Docker installation, containers, images, etc. |
docker pull |
docker pull ubuntu:latest |
Downloads a Docker image from Docker Hub or any specified repository. |
docker images |
docker images |
Lists all Docker images available locally. |
docker run |
docker run ubuntu echo "Hello World" |
Runs a command in a new container (creates and starts a container). |
docker run -d |
docker run -d nginx |
Runs a container in detached mode (in the background). |
docker run -it |
docker run -it ubuntu /bin/bash |
Runs a container in interactive mode, allowing a shell session with -it options. |
docker ps |
docker ps |
Lists all currently running containers. |
docker ps -a |
docker ps -a |
Lists all containers, including stopped ones. |
docker stop |
docker stop container_id |
Stops a running container. |
docker start |
docker start container_id |
Starts an existing, stopped container. |
docker restart |
docker restart container_id |
Restarts a container. |
docker rm |
docker rm container_id |
Removes a stopped container. |
docker rmi |
docker rmi image_id |
Deletes a Docker image. |
docker build |
docker build -t myapp . |
Builds an image from a Dockerfile in the current directory, tagging it as myapp . |
docker tag |
docker tag myapp:latest myrepo/myapp:v1 |
Tags an image with a new name and tag, useful for pushing to repositories. |
docker push |
docker push myrepo/myapp:v1 |
Uploads an image to a repository like Docker Hub. |
docker exec |
docker exec -it container_id /bin/bash |
Executes a command inside a running container, e.g., opening a shell. |
docker logs |
docker logs container_id |
Shows the logs for a container (both running and stopped). |
docker cp |
docker cp container_id:/file.txt . |
Copies files between the container and the host. |
docker inspect |
docker inspect container_id |
Shows detailed information about a container or image in JSON format. |
docker commit |
docker commit container_id mynewimage |
Creates a new image from a container’s changes. |
docker network ls |
docker network ls |
Lists all Docker networks. |
docker network create |
docker network create mynetwork |
Creates a new network for containers to communicate. |
docker network connect |
docker network connect mynetwork container_id |
Connects a container to an existing network. |
docker volume ls |
docker volume ls |
Lists all Docker volumes. |
docker volume create |
docker volume create myvolume |
Creates a new volume. |
docker volume rm |
docker volume rm myvolume |
Deletes a specified volume. |
docker compose up |
docker compose up |
Starts services defined in a docker-compose.yml file. |
docker compose down |
docker compose down |
Stops and removes containers defined in a docker-compose.yml file. |
docker stats |
docker stats |
Displays real-time resource usage statistics of running containers. |
docker history |
docker history ubuntu:latest |
Shows the history of an image’s layers. |
docker prune |
docker system prune |
Cleans up unused containers, networks, images, and optionally, volumes to free up disk space. |
docker top |
docker top container_id |
Displays the running processes inside a container. |
docker save |
docker save -o ubuntu.tar ubuntu:latest |
Saves an image as a .tar archive, useful for transferring images without pushing to a registry. |
docker load |
docker load -i ubuntu.tar |
Loads an image from a .tar archive. |
docker update |
docker update --memory 512M container_id |
Updates configuration options for a running container, like memory limits. |