Quick Reference
Docker common commands reference
Setting Up Docker
Install Docker
Refer to the official Docker documentation for OS-specific installation instructions.
Verify Docker installation:
Docker Images
Building an Image
To create a Docker image from a Dockerfile:
your-image-name
: Name of the image.tag
: Version tag (commonlylatest
for the most recent version).
Listing Images
To view all Docker images on your system:
Removing an Image
To remove a specific Docker image:
Removing All Images
To remove all Docker images:
Docker Containers
Running a Container
To run a Docker container from an image:
Listing Running Containers
To view all running containers:
Listing All Containers
To see all containers, including stopped ones:
Stopping a Container
To stop a specific running container:
Removing a Container
To remove a stopped container:
Removing All Containers
To remove all containers:
Debugging and Interactivity
Running a Container Interactively
To run a container in interactive mode (often used with a shell):
Bash Into a Running Container
To enter the shell of a running container:
Maintenance and Cleanup
Removing Stopped Containers, Unused Volumes, and Networks
To perform a cleanup:
Removing Unused Images
To remove dangling (unused) images:
Other Handy Commands
Viewing Logs of a Container
To view the logs of a running or stopped container:
Copying Files from/to a Container
To copy files between your host and a container:
Debugging and Interactivity with Docker Containers
Debugging containers often requires entering the container's environment, executing commands, or inspecting files. Here's how to navigate these tasks.
Entering a Container's Shell
Sometimes, to debug or inspect the container's internals, you may want to get a shell inside a running container. Here's how you can do that:
If the container is using a different shell, you might need to replace
/bin/sh
with/bin/bash
or another appropriate shell.
Running a Container with an Interactive Shell
If you are just starting a container and want it to give you a shell immediately, use:
Again, replace /bin/sh
if a different shell is used in the container.
Viewing Container Logs
To view the logs produced by a running or a stopped container:
Inspecting Container Metadata
For a detailed report on a container (like IP addresses, volumes, environment variables, etc.):
Checking Container Processes
To see which processes are running inside a container:
Debugging a Container That Won't Start
If a container is failing to start, it's often useful to override its entrypoint to keep it running and then bash into it to inspect:
This will override the container's default entry point with a shell, allowing you to start the intended command manually or inspect why it might be failing.
Last updated