Fixing nginx 'host not found in upstream' error in Docker

An nginx container in Docker can exit immediately with a 'host not found in upstream' error when the backend hostname cannot be resolved at startup. nginx resolves each proxy_pass hostname once when it launches, so it refuses to run if Docker's DNS cannot answer for that name. A test on Docker Engine 29.9.2 reproduced the failure, and the same error is widely reported in community forums. The main cause is that the backend container is not running or is not on the same user-defined network as nginx, since the default bridge network provides no container name resolution. Solutions include attaching both containers to one user-defined network, using the correct service name or alias, or adding a resolver directive to let nginx start without the backend and track IP changes.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in