You may have been tempted to have the following line in the Dockerfile but it won't work because Docker Daemon manages container's /etc/hosts file.

RUN ....
echo " host.docker.internal" >> /etc/hosts

The solution is to use extra hosts parameter to the docker-compose.yml file.

  - "some-host:"

Usually the extra hosts section is used to pass host-gateway's IP which is host's ip the container so the container can connect to the host.

  - "host.docker.internal:host-gateway"

Referral Note: When you purchase through an referral link (if any) on this page, we may earn a commission.