Guides › HTML / PHP sites › Site down or error screens

Docker: Port Already Allocated or Container Exits Immediately

Docker.

Reference guide. This guide is written from established practice and the official documentation of the tools involved. We have not yet tested every step on a live demo site. Back up your site before you change anything.
Site down or error page

Port is already allocated means something else uses that port. A container that exits at once means its main process stopped.

1Find who uses the port2Stop or remove it3Read the exit reason4Check the command5Check the exit code6Check environment values7RebuildFixed? Test the site. If not, get help.
The steps in order. Work down the list and stop when the problem is solved.

Step 1: Find who uses the port

Illustration for Step 1: Find who uses the port

Run docker ps and sudo lsof -i :PORT to see the owner.

Step 2: Stop or remove it

Illustration for Step 2: Stop or remove it

Run docker stop name or change your mapping to another host port such as 8081:80.

Step 3: Read the exit reason

Illustration for Step 3: Read the exit reason

Run docker logs container and check the last lines.

Step 4: Check the command

Illustration for Step 4: Check the command

A container stops when its main command ends. Make sure it runs a foreground process.

Step 5: Check the exit code

Illustration for Step 5: Check the exit code

Run docker ps -a. Code 137 usually means out of memory.

Step 6: Check environment values

Illustration for Step 6: Check environment values

Missing variables often make apps exit.

Step 7: Rebuild

Illustration for Step 7: Rebuild

Run docker compose up --build.

Still stuck?

If these steps do not solve it, we fix it for you for a flat $99. Full refund if we do not solve it within 7 days.

Related guides

Did this solve it? If not, email hello@sitefixlab.org with the exact error text and we will look into it. Try the problem finder.

Last updated 2026-11-22.