Docker is a platform for developing, shipping and running applications in containers. Containers are lightweight, isolated environments that contain everything needed to run an application, including the code, runtime, system tools, and libraries. Docker provides a command-line interface (CLI) to interact with containers and manage containerized applications. Here are some commonly used Docker commands:
Docker Build Commands:-
Command | Description |
docker build -t <image_name> . | Build a Docker image from a Dockerfile and tag it. |
docker build --no-cache -t <image_name> . | Build a Docker image without using the cache. |
docker build -f <dockerfile_name> -t <image_name> . | Build an image using a specified Dockerfile. |
Docker Clean Up Commands:-
Command | Description |
docker system prune | Remove all unused Docker resources. |
docker container prune | Remove all stopped containers. |
docker image prune | Remove unused images. |
docker volume prune | Remove unused volumes. |
docker network prune | Remove unused networks. |
Container Interaction Commands:-
Command | Description |
docker run <image_name> | Run a Docker image as a container. |
docker start <container_id> | Start a stopped container. |
docker stop <container_id> | Stop a running container. |
docker restart <container_id> | Restart a running container. |
docker exec -it <container_id> <command> | Execute a command inside a container interactively. |
Container Inspection Commands:-
Command | Description |
docker ps | List running containers. |
docker ps -a | List all containers (including stopped ones). |
docker logs <container_id> | Fetch the logs of a specific container. |
docker inspect <container_id> | Inspect detailed information about a container. |
Image Commands:-
Command | Description |
docker images | List available Docker images. |
docker pull <image_name> | Pull a Docker image from a registry. |
docker push <image_name> | Push a Docker image to a registry. |
docker rmi <image_id> | Remove a Docker image. |
Docker Run Commands:-
Command | Description |
docker run -d <image_name> | Run a Docker image in detached mode. |
docker run -p <host_port>:<container_port> <image_name> | Publish container ports to the host. |
docker run -v <host_path>:<container_path> <image_name> | Mount a host directory or volume to a container. |
docker run --name <container_name> <image_name> | Assign a custom name to the container. |
Docker Registry Commands:-
Command | Description |
docker login | Log in to a Docker registry. |
docker logout | Log out from a Docker registry. |
docker search <term> | Search for Docker images in a registry. |
docker pull <registry>/<image_name> | Pull a Docker image from a specific registry. |
Docker Service Commands (Swarm):-
Command | Description |
docker service create --name <service_name> <image_name> | Create a Docker service within a Swarm. |
docker service ls | List running Docker services in a Swarm. |
docker service scale <service_name>=<replicas> | Scale the replicas of a Docker service. |
docker service logs <service_name> | View logs of a Docker service in a Swarm. |
Docker Network Commands:-
Command | Description |
docker network create <network_name> | Create a Docker network. |
docker network ls | List available Docker networks. |
docker network inspect <network_name> | Inspect detailed information about a Docker network. |
docker network connect <network_name> <container_name> | Connect a container to a Docker network. |
Docker Volume Commands:-
Command | Description |
docker volume create <volume_name> | Create a Docker volume. |
docker volume ls | List available Docker volumes. |
docker volume inspect <volume_name> | Inspect detailed information about a Docker volume. |
docker volume rm <volume_name> | Remove a Docker volume. |