Run docker logs on the container. Whatever the app printed before it stopped is there. A container exists to run one main process, your app, so "won't start" almost always means the app inside crashed or exited. Usually it's a missing environment variable, a database or service it can't reach, the wrong start command, or an app listening on localhost inside the container, where nothing outside can reach it.
What's the problem
The image builds, but the container exits a second after starting, restarts in a loop, or sits at "starting" and never becomes healthy. Your app is unreachable.
Why it happens
- The app crashed. The container's main process is the command at the end of the Dockerfile. If that program fails on start, the container stops with it.
- A setting is missing. Passwords, keys and addresses are passed in as environment variables when the container runs. If they aren't provided, the app reads blanks and fails.
- It can't reach what it needs. The database address points at
localhost, which inside a container means the container itself, not your machine or another container. - It's running but unreachable. The app listens on
localhostinside the container, so the port you published leads nowhere. It needs to listen on0.0.0.0. - The health check never passes. If the Dockerfile defines a health check, the container reports "starting" until the check succeeds. A wrong check address or a slow start keeps it there.
How to fix it
- Read the logs:
docker logs <container>shows what the app printed. Look at the last lines before it exited. - Check the exit code with
docker ps -a. A code other than 0 means the app failed. Then read the logs again. - Pass in every environment variable the app needs, with
-e, an env file, or your compose file. - Fix addresses between containers. Use the other service's name (in Docker Compose, the service name) instead of
localhost. - Make the app listen on
0.0.0.0and the port you publish. - Check the start command (
CMDorENTRYPOINT) runs the right file from the right folder. - If it's stuck at "starting", test the health check command by hand inside the container.
When to call Preventionlabs
If the logs point at one missing setting, fix it and you're running. Call us when the container setup was built by someone who's gone, nothing is documented, and every fix reveals another missing piece. A resurrection gets the app running in your own hosting account, with the user flows you list working end to end, and hands it back with notes on how to run and deploy it.
Submit your project for a free assessmentFree assessment. $10,000 AUD flat to get it live, only if we take it on and you go ahead.
Sources
- Docker: Run multiple processes in a containerofficial docs
A container's main running process is the ENTRYPOINT and/or CMD at the end of the Dockerfile.
- Docker: docker container logsofficial docs
The docker logs command batch-retrieves logs present at the time of execution.
- Docker: Dockerfile reference: HEALTHCHECKofficial docs
When a container has a healthcheck specified, it has a health status in addition to its normal status. This status is initially starting.
- Render: Web Services: Port bindinghosting platform docs
Every Render web service must bind to a port on host 0.0.0.0 to serve HTTP requests.