Skip to content
Log In Sign Up info@muvcloud.com

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.

CommandWhat it does
docker run -d --name web nginx:1.30Starts a container in the background
docker psLists running containers
docker ps -aIncludes stopped ones
docker stop webStops it cleanly
docker start webStarts it again
docker restart webStops and starts it
docker statsLive CPU and memory use
docker inspect webAll settings as JSON

Options for docker run

OptionMeaning
-dRuns in the background
--name webNames the container
-p 8080:80Host port 8080 to container port 80
-v data:/dataMounts a volume
-e KEY=valueSets an environment variable
--restart unless-stoppedRestarts it after a crash or reboot
--rmDeletes it when it exits
-itInteractive 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

CommandWhat it does
docker pull nginx:1.30Downloads an image
docker imagesLists local images
docker build -t myapp:1.0 .Builds from the Dockerfile here
docker tag myapp:1.0 myapp:prodAdds a second name
docker history myapp:1.0Shows the layers
docker image rm nginx:1.30Removes 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

CommandWhat it does
docker logs webPrints the output so far
docker logs -f --tail 100 webFollows from the last 100 lines
docker logs --since 1h webOnly the last hour
docker exec -it web shOpens a shell inside
docker exec web nginx -tRuns one command inside
docker cp web:/etc/nginx .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

CommandWhat it does
docker volume create dataCreates a named volume
docker volume lsLists volumes
docker volume inspect dataShows where it lives
docker network create appnetCreates a network
docker network lsLists networks
docker network connect appnet webJoins 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
CommandWhat it removes
docker rm webOne stopped container
docker container pruneAll stopped containers
docker image pruneDangling images
docker image prune -aAll unused images
docker system pruneStopped containers, unused networks, dangling images, cache
docker volume pruneUnused 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

CommandWhat it does
docker compose up -dStarts the project
docker compose psLists its containers
docker compose logs -fFollows all services
docker compose exec web shShell in one service
docker compose pullFetches newer images
docker compose downRemoves 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

CommandWhat it shows
docker versionClient and engine versions
docker infoStorage, logging, counts
docker system dfDisk use by type
docker context lsWhich engine the client uses
systemctl status dockerWhether 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.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

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.

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