Docker lab/version note: use supported Linux-container tools and patched images. Check version compatibility before running the examples. Docker, Swarm and platform-specific deployment steps were not tested live.
What this guide covers
A container can fail because its process exits, it runs out of resources, its port is wrong or a required file is unavailable. Check these separately before rebuilding or deleting anything.
Before you start
These commands use the node-lab container from the Node.js guide. Replace that name for your container. Keep logs and inspect output private if they contain application data.
Step 1: Check the container and logs
Run:
docker context show
docker ps -a --filter name=node-lab --no-trunc
docker inspect node-lab --format '{{.Id}} image={{.Image}} status={{.State.Status}}'
docker inspect node-lab --format 'exit={{.State.ExitCode}} oom={{.State.OOMKilled}} error={{json .State.Error}}'
docker logs --timestamps --tail 100 node-lab
Confirm the Docker context, image and exit state. Read the first application error. An exited container remains inspectable until removed.
Step 2: Check resource failures
Run:
docker stats --no-stream node-lab
docker inspect node-lab --format 'memory={{.HostConfig.Memory}} cpu={{.HostConfig.NanoCpus}} restarts={{.RestartCount}}'
docker inspect node-lab --format '{{json .State.Health}}'
An OOM flag indicates a memory-related kill. Exit code 137 by itself is not proof of that cause. Compare memory limits and observed demand before changing them.
Step 3: Test the host port
Run:
docker port node-lab
curl --fail --show-error --connect-timeout 3 --max-time 5 http://127.0.0.1:8080/healthz
docker inspect node-lab --format '{{json .NetworkSettings.Ports}}'
Check that the host port maps to the application’s actual container port. Inside the container, the process normally needs to listen on 0.0.0.0, not just 127.0.0.1.
Step 4: Test inside the container
For this Node example:
docker exec node-lab node -e "fetch('http://127.0.0.1:3000/healthz').then(async r=>{console.log(r.status,await r.text());process.exit(r.ok?0:1)}).catch(e=>{console.error(e.message);process.exit(1)})"
If this succeeds but the host request fails, inspect publication, firewall and binding. For dependency failures, check the Docker network, service DNS name and credentials separately. Inspect mounted-file ownership if the process reports permission errors.
Check the result
Fix one identified cause, restart or replace the container as appropriate, and repeat the same failing check. Do not prune volumes or disable security settings merely to see whether the error disappears.
Conversation
0 commentsNo comments yet. Start the conversation below.