This chapter's settings are all fixed when a container is created. A broken service is usually one wrong flag. Find it in this order:
1. docker ps -a Is it Up, Exited, or Restarting?
│
├── Exited / Restarting ──► 2. docker logs NAME Why does PID 1 exit?
│
└── Up ──► 3. curl localhost:PORT Does traffic arrive?
│
├── Couldn't connect ──► no container publishes that host port
└── Connection reset ──► the mapping points at the wrong container port
4. docker inspect NAME Record every setting before you remove anything
5. fix the input (env file, flags), docker rm -f NAME, docker run ... again
6. curl againSymptoms and causes
| Symptom | Likely cause | Where to look |
|---|---|---|
Exited (1) right after start | Missing or misspelled variable | docker logs, {{json .Config.Env}} |
Restarting (1) | Same, with a restart policy retrying | docker logs, {{json .HostConfig.RestartPolicy}} |
Couldn't connect to server | No -p for that host port | docker port, PORTS in docker ps |
Connection reset by peer | Wrong container port in -p | docker port, the program's port (docker exec NAME env, logs) |
port is already allocated | Another container owns the host port | docker ps |
Record before you remove
The replacement must keep every setting that was right. Read them first:
docker inspect --format '{{json .HostConfig.RestartPolicy}}' greeter
docker inspect --format '{{json .HostConfig.PortBindings}}' greeter{"Name":"on-failure","MaximumRetryCount":5}
{"80/tcp":[{"HostIp":"","HostPort":"8080"}]}The restart policy on-failure with 5 retries becomes --restart on-failure:5 on the new container. The port binding reads host port 8080 to container port 80. Print the environment the same way with {{range .Config.Env}}{{println .}}{{end}}.
Edit the env file
Open the file in the editor panel, fix it, save:
nano ~/greeter/greeter.envA misspelled key is not an error for Docker. It passes the variable as written, and the program never sees the name it expects.