Your first container, and what to look at when it will not start

A container is a program running in a space of its own, with everything it needs already packed in an image. It lives as long as its main process lives: if the program ends or fails, the container stops. Almost everything that goes wrong at first is settled with two commands, docker ps -a and docker logs. This article assumes Docker is installed on a VPS: here is how to install it.

Starting a test web server

1 Start the container: docker run -d --name test -p 8080:80 nginxThe -d keeps it in the background, --name gives it a name, and -p 8080:80 connects the server’s port 8080 to the container’s port 80. The nginx image is downloaded the first time.
2 See whether it is up: docker psIt shows only those running. With docker ps -a it shows the stopped ones too.
3 Ask for the page, on the server itself: curl http://localhost:8080. You get nginx’s welcome HTML.
4 Read the logs: docker logs test, or add -f to follow live, and --tail 100 for just the last lines.
5 Stop and delete: docker stop test
docker rm test
Stopping does not delete. While the container exists, the name test stays taken.

When it will not start: what the symptom means

What you see What it usually is What to do
Status “Exited (0)” The program ended normally. A container with nothing to do ends at once. If you expected a service, the image or command is not a service. Read the image’s page.
Status “Exited (1)” The program failed on start: a missing file, an unset variable, a configuration error. docker logs name: the last line usually says why.
Status “Exited (137)” The container was killed. Often it is the server running out of memory. free -h, and see whether the VPS has free memory.
“Restarting” It fails and starts again, in a loop, because of the restart policy. The logs, as with Exited (1). Stop it first: docker stop name.
“port is already allocated” The port you asked for is already used by something else. sudo ss -tlnp shows who has it. Pick another port on the left-hand side.
“pull access denied” or “not found” A misspelt image name, or a private image with no login. Check the name at hub.docker.com.
“permission denied” on docker.sock Your user is not in the docker group. Use sudo, or see the end of the installation article.

To look inside a container that is running: docker exec -it test shIt opens a command line in there. Leave with exit. To see the full configuration (ports, volumes, variables): docker inspect test.

What is inside a container disappears with it. If you delete the container, the files the program created in there go too, unless you connected a folder or a volume. Before putting important data in a container, read Docker Compose: an application with its database.
Publishing a port opens it to the world. With -p 8080:80 anyone can reach it, and Docker steps around the ufw rules. For tests on the server only, use -p 127.0.0.1:8080:80. See ports and firewall on a VPS.

Server not answering, or SSH no longer getting in? That is ours: tell us what you see and when it began. The application inside the container is yours, and the guide above helps you find what makes it fail.

Open a support ticket

SEE ALSO

Installing Docker and Docker Compose on a VPS

Docker Compose: an application with its database

Common VPS and Cloud errors: SSH, memory, disk and reboots

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from KSh858.00/mo (3-year plan, with coupon)

See plans
  • 0 Users Found This Useful
Was this answer helpful?