First habit
Do not guess first. Check container status, logs, ports, and service names before changing things.
This page focuses on what to do when a container does not run correctly, when the browser cannot reach the app, or when services fail to talk to each other.
Do not guess first. Check container status, logs, ports, and service names before changing things.
docker ps, docker logs, docker exec, and docker inspect solve many beginner issues.
Most Docker problems come from wrong ports, wrong env vars, wrong file copies, wrong host names, or missing rebuilds.
docker ps
docker ps -a
docker logs <container_id>
docker exec -it <container_id> sh
docker inspect <container_id>
docker ps -a to check whether the container is actually running or already exited.docker logs to read the startup error.process.env.DB_HOST
environment:
DATABASE_HOST: db
This fails because the app expects DB_HOST, but Compose sends DATABASE_HOST. The names must match exactly.
docker exec -it <container_id> sh
env
This helps confirm whether the expected values were really passed into the running container.
docker exec -it <container_id> sh
ls /app
If the expected files are not present, check your COPY commands and build context in the Dockerfile.
docker compose up --build
If you changed code or the Dockerfile, you may still be running an old image. Rebuild before testing again.
docker compose ps
docker compose logs
docker compose logs app
docker compose up --build
docker compose down
db instead of changing IPs.localhost means that same container.Next step: after debugging basics, you are ready for more advanced topics like health checks, production patterns, and deployment workflows.