[Docker] How to fix 'host not found in upstream "host.docker.internal"'.

fmtweisszwerg

Fomalhaut Weisszwerg

Posted on May 20, 2024

[Docker] How to fix 'host not found in upstream "host.docker.internal"'.
Notice for Japanese: 今回は FLINTERS ブログ祭りの一環で記事を書いています

TL;DR

  1. Update docker to 20.10.0 or later.

  2. Create docker-compose.override.yml

  3. write followings into docker-compose.override.yml

services:
  MY_SERVICE:
    extra_hosts:
      - "host.docker.internal:host-gateway"
Enter fullscreen mode Exit fullscreen mode

It is needed to be replaced MY_SERVICE to your service name.

What is "host.docker.internal" ?

"host.docker.internal" is a magic name of a gateway. It is defined on "Docker Desktop for Mac/Windows" by default but not on the others. So it is possible to use "host.docker.internal" on macOS and Windows by default. But the others require you to define it yourself.

How to define "host.docker.internal"

The docker-compose.yml already in the VCS repository is as following:

services:
  proxy:
    image: nginx
Enter fullscreen mode Exit fullscreen mode

Then your docker-compose.override.yml need to be:

services:
  proxy:
    extra_hosts:
      - "host.docker.internal:host-gateway"
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
fmtweisszwerg
Fomalhaut Weisszwerg

Posted on May 20, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related