Essential Docker Commands Every Developer Should Know
This article provides a concise cheat‑sheet of common Docker commands—including image management, container lifecycle, networking, resource limits, and registry operations—explaining each option and showing practical usage examples for developers and DevOps engineers.
Docker Command Cheat Sheet
This guide lists the most frequently used Docker commands with brief explanations of their options, helping you manage images, containers, and registries efficiently.
docker images # List images; can pipe to "| grep <pattern>"
docker images | grep nginx # Example: filter images containing "nginx"
docker images [OPTIONS] [REPOSITORY[:TAG]]
OPTIONS:
-a # List all images
--digests # Show image digests
-f # Filter output
--format # Specify output template
--no-trunc # Do not truncate output
-q # Show only image IDs
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
OPTIONS:
-d # Run container in background (detached)
-i # Keep STDIN open (often used with -t)
-t # Allocate a pseudo‑TTY
-p host:container # Publish container port
--name "nginx" # Assign a name to the container
-h "localhost" # Set container hostname
-e spring.profiles.active="dev" # Set environment variable
--env-file=[] # Read environment variables from file
-m # Set memory limit
--volume /home/data:/etc/data # Bind mount a volume
... and so on
docker create IMAGE # Create a container without starting it
docker start CONTAINER_ID # Start a stopped container
docker stop CONTAINER_ID # Stop a running container
docker restart CONTAINER_ID # Restart a container
docker rm [-f] [-v] CONTAINER_ID # Remove a container (‑f forces, ‑v removes volumes)
docker ps [OPTIONS] # List containers
OPTIONS:
-a # Show all containers, including stopped
-f # Filter output
--format # Output format template
-l # Show latest created container
-n # Show last N containers
--no-trunc # Do not truncate output
-q # Quiet mode, only container IDs
-s # Show total file size
docker exec -it CONTAINER_ID sh # Open an interactive shell in a running container
docker rm $(docker ps -a -q) # Remove all stopped containers
docker rmi [-f] IMAGE_ID # Remove an image (‑f forces)
docker inspect [OPTIONS] NAME|ID # Retrieve metadata of a container or image
OPTIONS:
-f # Output format template
-s # Show total size
-type # Return JSON for a specific type
# Example: Get IP of a running nginx container
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' nginx
docker kill -s SIGKILL CONTAINER_ID # Kill a running container
docker logs -f -t CONTAINER_ID # Follow container logs with timestamps
docker build [OPTIONS] PATH|URL|- # Build an image from a Dockerfile
OPTIONS:
-f # Path to Dockerfile
-m # Set memory limit
--memory-swap # Set swap limit (memory+swap, "-1" for unlimited)
--no-cache # Do not use cache when building
--pull # Attempt to pull newer version of base images
-q # Quiet mode, output only image ID
--rm # Remove intermediate containers after a successful build
--shm-size # Set /dev/shm size (default 64M)
--tag NAME:TAG# Tag the image
--network # Set network mode for RUN instructions
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG] # Tag an image
docker save -o IMAGE.tar IMAGE_NAME # Save an image to a tar archive
docker load -i IMAGE.tar # Load an image from a tar archive
docker info # Display Docker system information
docker version # Show Docker version information
docker login -u USERNAME -p PASSWORD # Log in to a Docker registry
docker logout # Log out from the registry
docker pull IMAGE[:TAG] # Pull or update an image (‑a for all tags)
docker push IMAGE[:TAG] # Push a local image to a registryUse this reference to streamline your container workflows and improve productivity when working with Docker.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
