Containers: Run, List, Stop
These are the commands you type most often. Replace web with the name of your container, or use the container ID from docker ps.
| Command | What it does |
|---|---|
docker run -d --name web nginx:1.30 | Starts a container in the background |
docker ps | Lists running containers |
docker ps -a | Includes stopped ones |
docker stop web | Stops it cleanly |
docker start web | Starts it again |
docker restart web | Stops and starts it |
docker stats | Live CPU and memory use |
docker inspect web | All settings as JSON |
Options for docker run
| Option | Meaning |
|---|---|
-d | Runs in the background |
--name web | Names the container |
-p 8080:80 | Host port 8080 to container port 80 |
-v data:/data | Mounts a volume |
-e KEY= | Sets an environment variable |
--restart unless- | Restarts it after a crash or reboot |
--rm | Deletes it when it exits |
-it | Interactive terminal |
Options go before the image name; anything after it is passed to the program inside the container. A published port is open to the internet even when ufw denies incoming traffic, as Docker port mapping explains. The choices for --restart are in Docker restart policies.
Images and Builds
| Command | What it does |
|---|---|
docker pull nginx:1.30 | Downloads an image |
docker images | Lists local images |
docker build -t myapp:1.0 . | Builds from the Dockerfile here |
docker tag myapp:1.0 myapp:prod | Adds a second name |
docker history myapp:1.0 | Shows the layers |
docker image rm nginx:1.30 | Removes an image |
How to write the file that docker build reads is in how to write a Dockerfile. Removing images safely is covered in how to remove Docker images.
Logs and Shell Access
| Command | What it does |
|---|---|
docker logs web | Prints the output so far |
docker logs -f --tail 100 web | Follows from the last 100 lines |
docker logs --since 1h web | Only the last hour |
docker exec -it web sh | Opens a shell inside |
docker exec web nginx -t | Runs one command inside |
docker cp web:/etc/ | Copies files out |
More options are in how to view Docker container logs and how to open a shell in a Docker container.
Volumes and Networks
| Command | What it does |
|---|---|
docker volume create data | Creates a named volume |
docker volume ls | Lists volumes |
docker volume inspect data | Shows where it lives |
docker network create appnet | Creates a network |
docker network ls | Lists networks |
docker network connect appnet web | Joins a container to it |
Containers on the same user-defined network reach each other by container name, so a database needs no published port. Volumes and bind mounts are compared in Docker volumes vs bind mounts.
Clean-Up
Read this first: the commands below delete, and there is no undo. Data that matters belongs in a named volume or a bind mount, with a backup. Look before you remove anything:
docker ps -a
docker volume ls
docker system df| Command | What it removes |
|---|---|
docker rm web | One stopped container |
docker container prune | All stopped containers |
docker image prune | Dangling images |
docker image prune -a | All unused images |
docker system prune | Stopped containers, unused networks, dangling images, cache |
docker volume prune | Unused anonymous volumes |
docker system prune leaves volumes alone, and its cache is the unused build cache. docker volume prune -a also removes named volumes that no container uses, databases included. Details are in how to stop and remove Docker containers and how to clean up disk space used by Docker.
Docker Compose
| Command | What it does |
|---|---|
docker compose up -d | Starts the project |
docker compose ps | Lists its containers |
docker compose logs -f | Follows all services |
docker compose exec web sh | Shell in one service |
docker compose pull | Fetches newer images |
docker compose down | Removes containers and network |
Run these in the folder that holds compose.yaml. Named volumes survive down; down -v deletes them. See docker compose up -d and, if the command is missing, how to install Docker Compose.
System Information
| Command | What it shows |
|---|---|
docker version | Client and engine versions |
docker info | Storage, logging, counts |
docker system df | Disk use by type |
docker context ls | Which engine the client uses |
systemctl status docker | Whether the service runs |
If every command fails with a message about the daemon, see Cannot connect to the Docker daemon.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations