How do I access a server on localhost with nginx docker container?

后端 未结 5 1216
执念已碎
执念已碎 2020-12-13 03:05

I\'m trying to use a dockerized version of nginx as a proxy server for my node (ExpressJS) application. Without any configuration to nginx and publishing port 80 for the con

5条回答
  •  遥遥无期
    2020-12-13 03:49

    On linux, this works for me:

    In the docker-compose.yml, mount an entrypoint script into the nginx container:

      nginx:
        image: nginx:1.19.2
        # ...
        volumes:
          - ./nginx-entrypoint.sh:/docker-entrypoint.d/nginx-entrypoint.sh:ro
    

    The contents of the entrypoint map a local address to the host local address.

    apt update
    apt install iproute2 -y
    echo "`ip route | awk '/default/ { print $3 }'`\tdocker.host.internal" >> /etc/hosts
    

    Then, instead of using localhost inside the container, you can use docker.host.internal.

提交回复
热议问题