Skip to main content
The Docker commands you need most on a server are docker run -d to start a container, docker ps -a to list containers, docker logs -f <name> to read output, docker exec -it <name> sh to open a shell, docker stop and docker rm to stop and remove, and docker system df to see disk use. Each table below gives the command, what it does and an example.

Before you start

  • Run the commands as a user in the docker group, or put sudo in front.
  • You can use a container’s name (for example web) or the first few characters of its ID wherever a command needs <name>.
  • An image is the read-only template. A container is a running (or stopped) copy of an image. A volume is storage that survives when you replace the container.

How to run a container

Ports published with -p bypass ufw and firewalld. Anything you publish on 0.0.0.0 is reachable from the internet. Use 127.0.0.1: for admin tools and databases.

Container commands

Example output of docker ps:

How to read container logs

How to open a shell inside a container

Use bash instead of sh if the image has it. Type exit to leave; the container keeps running. To run a single command without a shell:

Image commands

How to update a container to a new image

A container never changes its image. To update, pull the new image and create a new container with the same options:
Data in volumes stays. Data written inside the container (not in a volume) is lost. Docker Compose makes this a two-command job.

Volume and network commands

Containers on the same user-defined network reach each other by container name.

Disk space and clean-up

Example output of docker system df:
docker volume prune -a and docker rm -v delete volume data, including databases. See clean up Docker disk space for what each prune command removes.

Frequently asked questions

What is the difference between docker stop and docker kill?

docker stop asks the main process to shut down and waits, by default 10 seconds, before forcing it. docker kill ends it at once, which can corrupt data that is being written.

Why does my container exit straight away?

The main process ended or crashed. Run docker ps -a to see the exit code and docker logs <name> to see the error.

How do I copy a file into or out of a container?

Use docker cp, for example docker cp web:/etc/nginx/nginx.conf ./nginx.conf or docker cp ./index.html web:/usr/share/nginx/html/.

How do I see which ports a container publishes?

Run docker port web. It prints lines such as 80/tcp -> 127.0.0.1:8080.

VPS and dedicated server guides

Every guide in this section.

Install Docker

Docker Engine from the official repository.

Docker Compose tutorial

Define containers in one file.

Clean up Docker disk space

What each prune command deletes.

Install Portainer

The same tasks in a web UI.

Checked against the official Docker CLI reference on 4 November 2026; commands tested on Ubuntu 24.04 LTS with Docker Engine 29.9.2. Output can differ slightly between Docker versions.

Need Extra Help?

If you encounter any issues, our support team is ready to assist:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026