DEV Community

Rakesh KR
Rakesh KR

Posted on

Docker Commads

Here is a table of 100+ Docker commands organized by category for easy reference:

Category Command Description
General Docker Commands docker --help Displays Docker help and usage info.
docker info Provides detailed information about Docker's configuration and state.
docker version Displays Docker's version information.
Container Management docker run [OPTIONS] IMAGE [COMMAND] [ARG...] Run a container from an image.
docker ps Lists all running containers.
docker ps -a Lists all containers (running and stopped).
docker stop <container_name> Stops a running container.
docker start <container_name> Starts a stopped container.
docker restart <container_name> Restarts a container.
docker pause <container_name> Pauses a running container.
docker unpause <container_name> Resumes a paused container.
docker kill <container_name> Sends a SIGKILL signal to a running container.
docker rm <container_name> Removes a stopped container.
docker rename <old_name> <new_name> Renames a container.
docker exec -it <container_name> <command> Runs a command inside a running container.
docker attach <container_name> Attaches to a running container's process.
docker logs <container_name> Retrieves logs from a container.
Image Management docker pull <image_name> Pulls an image from a Docker registry.
docker build -t <image_name> <path> Builds a Docker image from a Dockerfile.
docker images Lists all images available locally.
docker rmi <image_name> Removes an image from the local system.
docker tag <image_name> <new_image_name> Tags an image with a new tag.
docker push <image_name> Pushes an image to a Docker registry.
Network Management docker network ls Lists all Docker networks.
docker network create <network_name> Creates a new Docker network.
docker network connect <network_name> <container_name> Connects a container to a network.
docker network disconnect <network_name> <container_name> Disconnects a container from a network.
docker network inspect <network_name> Displays detailed information about a specific network.
Volume Management docker volume ls Lists all Docker volumes.
docker volume create <volume_name> Creates a new Docker volume.
docker volume inspect <volume_name> Displays detailed information about a specific volume.
docker volume rm <volume_name> Removes a Docker volume.
Docker Compose docker-compose up Starts the services defined in a Docker Compose file.
docker-compose down Stops and removes containers defined in a Docker Compose file.
docker-compose build Builds or rebuilds services defined in a Docker Compose file.
docker-compose logs Displays logs for services defined in a Docker Compose file.
docker-compose exec <service_name> <command> Runs a command inside a running service container in Docker Compose.
docker-compose ps Lists all containers in the current Docker Compose project.
Docker Swarm docker swarm init Initializes a Docker Swarm mode cluster.
docker swarm join Joins a node to a Docker Swarm cluster.
docker node ls Lists all nodes in the Docker Swarm cluster.
docker service ls Lists all services in a Docker Swarm cluster.
docker service create <service_name> Creates a new service in Docker Swarm.
docker service update <service_name> Updates a service in Docker Swarm.
Docker Registry docker login <registry_url> Logs into a Docker registry.
docker logout <registry_url> Logs out from a Docker registry.
Docker System docker system prune Removes all unused containers, networks, images, and volumes.
docker system df Shows disk usage by Docker images, containers, and volumes.
docker system info Displays information about the Docker system.
Container Info docker inspect <container_name> Returns detailed information about a container in JSON format.
Container Health Check docker healthcheck <container_name> <command> Performs health checks on a running container.
Container Logs docker logs -f <container_name> Follows the logs output from a running container.
Resource Limits docker run --memory="512m" --cpus="1.0" <image_name> Runs a container with memory and CPU resource limits.
Build Cache docker build --no-cache -t <image_name> . Builds a Docker image without using cache.
Tagging Images docker build -t <username>/<repo>:<tag> . Builds and tags an image with the given username, repository, and tag.
Container Execution docker exec -it <container_name> bash Executes a bash shell inside a running container.
File Operations docker cp <container_name>:<container_path> <host_path> Copies files from a container to the host.
docker cp <host_path> <container_name>:<container_path> Copies files from the host to a container.
Build and Test docker build --file <Dockerfile> . Builds a Docker image using a specified Dockerfile.
Container Status docker stats Displays a live stream of container resource usage.
Container Health Check docker run --health-cmd="<health_command>" Specifies a health check for a container.
Container Process docker top <container_name> Displays the running processes inside a container.
File Systems docker diff <container_name> Shows changes made to a container’s filesystem.
Attach Console docker attach <container_name> Attaches to the container’s standard input, output, and error.
Exporting and Importing docker export <container_name> > <file_name>.tar Exports a container's filesystem to a tarball.
docker import <file_name>.tar Imports a tarball as a new image.
Logs and Debugging docker logs --tail <n> <container_name> Shows the last 'n' lines of logs from a container.
docker logs --follow <container_name> Follows the logs of a container as they are written.
Running in Detached Mode docker run -d <image_name> Runs a container in detached mode (in the background).
Container Restart Policies docker run --restart always <image_name> Runs a container that always restarts when it fails or when Docker restarts.
Resource Limits docker run --memory=2g --cpus="2.0" <image_name> Runs a container with memory and CPU resource limits.
Check Dependencies docker inspect --format '{{.State.Health.Status}}' <container_name> Checks the health status of a container.
Container State docker container stats <container_name> Shows resource usage for a running container.
Docker Configuration docker config Displays configuration of Docker on the system.

Top comments (0)