Docker Commands Developers Actually Use: A Practical Guide
Learn the Docker commands developers use most often to build images, run containers, inspect applications, manage images, view logs, and clean up unused resources.

Prerequisites: Basic command-line knowledge and Docker installed on your system
Docker Commands Developers Actually Use: A Practical Guide
Docker becomes much easier once you know the small set of commands you will use repeatedly.
You do not need to memorize every Docker command. For everyday development, a handful of commands can help you build images, start containers, inspect applications, view logs, manage images, and clean up unused resources.
This guide focuses on practical Docker commands with examples you can actually use in a development workflow.
Docker Commands at a Glance
| Task | Command |
|---|---|
| Check Docker version | docker --version |
| Get Docker information | docker info |
| Download an image | docker pull nginx |
| List images | docker images |
| Build an image | docker build -t myapp . |
| Run a container | docker run nginx |
| List running containers | docker ps |
| List all containers | docker ps -a |
| Stop a container | docker stop <container> |
| Start a stopped container | docker start <container> |
| Remove a container | docker rm <container> |
| View logs | docker logs <container> |
| Execute a command inside a container | docker exec -it <container> sh |
| Remove an image | docker rmi <image> |
1. Check Whether Docker Is Installed
Start by checking the installed Docker version:
docker --versionExample output:
Docker version 27.0.3, build 7d4bcd8This is useful when setting up a new development machine or troubleshooting version-related problems.
You can also inspect Docker's configuration and runtime information:
docker infoUnlike docker --version, docker info provides information about the Docker environment.
2. Download a Docker Image
Before running a container, you may need an image.
For example, to download the official Nginx image:
docker pull nginxDocker retrieves the image from the configured container registry.
You can then verify that the image exists locally:
docker imagesTypical output contains information such as:
- Repository
- Tag
- Image ID
- Creation time
- Size
3. Run Your First Container
The basic syntax is:
docker run <image>For example:
docker run nginxThis creates and starts a container using the Nginx image.
For web applications, you will often want to map a host port to a container port.
For example:
docker run -p 8080:80 nginxThe format is:
HOST_PORT:CONTAINER_PORTSo:
8080:80means requests to port 8080 on the host are forwarded to port 80 in the container.
4. Run a Container in the Background
A development terminal becomes difficult to use if your application occupies it continuously.
Use detached mode:
docker run -d -p 8080:80 nginxThe -d option runs the container in the background.
You can then continue using the terminal while the container runs.
5. Give Your Container a Name
Docker can automatically generate a container name, but meaningful names are easier to work with.
Use:
docker run -d --name web-server -p 8080:80 nginxNow you can reference the container as:
web-serverFor example:
docker logs web-serverThis is usually easier than remembering a generated container name or ID.
6. List Running Containers
To see currently running containers:
docker psYou will typically see:
- Container ID
- Image
- Command
- Creation time
- Status
- Ports
- Container name
To see both running and stopped containers:
docker ps -aThis distinction is important when debugging because a container that exited will not appear in docker ps.
7. Stop a Running Container
To stop a container:
docker stop web-serverYou can also use its container ID:
docker stop <container-id>Stopping a container does not remove it.
The container still exists and can be started again.
8. Start a Stopped Container
If a container has been stopped, you can start it again:
docker start web-serverThis is different from docker run.
docker run
Creates a new container from an image and starts it.
docker start
Starts an existing stopped container.
Understanding this difference prevents developers from accidentally creating multiple containers for the same application.
9. Restart a Container
You can restart an existing container with:
docker restart web-serverThis can be useful when an application needs to be restarted without manually stopping and starting it.
10. View Container Logs
Logs are one of the most useful tools when debugging Docker applications.
Use:
docker logs web-serverTo continuously follow new log entries:
docker logs -f web-serverThe -f option follows the container's output.
This is especially useful when:
- An application fails during startup
- An API returns unexpected errors
- A server does not respond
- An environment variable is missing
- A backend process crashes
11. Execute a Command Inside a Running Container
Sometimes logs are not enough.
You may need to inspect the container itself.
For containers that provide a shell, you can use:
docker exec -it web-server shThe command opens an interactive shell inside the running container.
Once inside, you can inspect files and processes available in the container.
For images that include Bash, you may use:
docker exec -it web-server bashHowever, not every image contains Bash, so sh is often more portable.
12. Build Your Own Docker Image
Suppose your project contains a Dockerfile.
A basic build command is:
docker build -t myapp .Here:
docker buildbuilds an image-t myappassigns the image a name.tells Docker to use the current directory as the build context
After building, check the image:
docker imagesYou should see myapp in the local image list.
13. Run the Image You Built
After creating the image:
docker build -t myapp .You can run it with:
docker run -d --name myapp-container myappIf the application listens on a specific container port, publish it to the host:
docker run -d --name myapp-container -p 3000:3000 myappThe exact port depends on how your application is configured.
14. List Docker Images
To see images stored locally:
docker imagesYou may find several versions of the same application.
For example:
REPOSITORY TAG IMAGE ID CREATED SIZE
myapp latest abc123 2 minutes ago 180MB
nginx latest def456 1 day ago 190MBImage tags are useful for identifying different versions.
15. Remove a Docker Container
To remove a stopped container:
docker rm web-serverIf the container is still running, stop it first:
docker stop web-server
docker rm web-serverYou can also remove a stopped container automatically after stopping it with:
docker rm -f web-serverUse force removal carefully because it stops the container before removing it.
16. Remove a Docker Image
To remove an image:
docker rmi myappDocker will prevent removal when the image is still required by existing containers in situations where that would conflict.
Before deleting images, check which containers and images you still need.
17. Inspect a Container
When you need detailed information about a container:
docker inspect web-serverThis can expose configuration information such as:
- Network settings
- Mounts
- Environment configuration
- Container state
- Image information
It is particularly useful when a container behaves differently from what you expected.
18. Check Container Resource Usage
Docker provides a live resource view with:
docker statsThis can show resource usage for running containers.
It is useful when investigating applications that appear to consume excessive CPU or memory.
For example, if a development container suddenly becomes slow, docker stats can help determine whether the container is consuming significant resources.
19. Clean Up Unused Docker Resources
Over time, development work can leave behind unused containers, networks, images, and build resources.
Docker provides:
docker system pruneDocker asks for confirmation before performing the cleanup.
Be careful with cleanup commands because removing resources can affect things you intended to keep.
For this reason, inspect your Docker resources before running cleanup commands in important environments.
A Practical Docker Development Workflow
A typical workflow might look like this:
The important idea is that Docker becomes part of your development feedback loop.
You build an image, run it, inspect the result, troubleshoot problems, make changes, and build again.
Common Docker Mistakes
1. Confusing Images and Containers
An image is a packaged application environment.
A container is a running or stopped instance created from an image.
Think of it like this:
Image
↓
Container
↓
Running ApplicationYou can create multiple containers from the same image.
2. Forgetting Port Mapping
A container may be running successfully while the application is inaccessible from your browser.
For example:
docker run nginxmay start Nginx, but you have not necessarily published its port to the host.
For local access, you could use:
docker run -p 8080:80 nginxThen access the application through the host port you published.
3. Looking Only at docker ps
If an application has crashed immediately, it may no longer appear in:
docker psInstead, use:
docker ps -aThen inspect the logs:
docker logs <container>This simple combination solves many beginner Docker debugging problems.
4. Creating Too Many Containers
Repeatedly running:
docker run ...creates new containers.
If you intended to restart an existing container, use:
docker start <container>instead.
A Small Docker Cheat Sheet
# Docker version
docker --version
# Docker information
docker info
# Download an image
docker pull nginx
# List images
docker images
# Run a container
docker run nginx
# Run in background
docker run -d nginx
# Run with port mapping
docker run -d -p 8080:80 nginx
# Run with a custom name
docker run -d --name web-server nginx
# List running containers
docker ps
# List all containers
docker ps -a
# Stop container
docker stop web-server
# Start container
docker start web-server
# Restart container
docker restart web-server
# View logs
docker logs web-server
# Follow logs
docker logs -f web-server
# Open shell
docker exec -it web-server sh
# Build image
docker build -t myapp .
# Inspect container
docker inspect web-server
# View resource usage
docker stats
# Remove container
docker rm web-server
# Remove image
docker rmi myapp
# Clean unused resources
docker system pruneWhat Should You Learn After These Commands?
Once you are comfortable with the Docker CLI, the next step is learning how these commands fit into real application development.
A useful learning path is:
- Docker images and containers
- Dockerfiles
- Port mapping
- Environment variables
- Volumes
- Container networking
- Docker Compose
- Multi-container applications
- Image optimization
- CI/CD with Docker
For a full-stack developer, Docker becomes especially useful when your application contains multiple services such as a frontend, backend API, and database.
Docker Checklist for Developers
Before calling your Docker workflow complete, make sure you can:
- Pull an image
- Build an image
- Run a container
- Map ports
- Name containers
- List containers
- Stop and restart containers
- Read container logs
- Execute commands inside containers
- Inspect containers
- Check resource usage
- Remove unused containers
- Understand the difference between images and containers
Final Takeaway
You do not need to memorize hundreds of Docker commands.
Start with the commands you will actually use during development:
docker pull
docker build
docker run
docker ps
docker logs
docker exec
docker stop
docker start
docker inspect
docker rm
docker rmiOnce these become familiar, learning Dockerfiles, Compose, networking, volumes, and CI/CD becomes much easier.
The goal is not to memorize Docker syntax. The goal is to understand what is happening at each step of your application's container workflow.







Comments (0)
Be the first to share your thoughts.