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

后端 未结 5 1218
执念已碎
执念已碎 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:46

    If you're using docker-for-mac 18.03 or newer it auto creates a special DNS entry host.docker.internal that dynamically binds to the host inet ip. You can then use the dns name to proxy services running on the host machine from inside a container as a stand-in for localhost.

    i.e. an nginx config file:

    server {
      listen 0.0.0.0:80;
      server_name localhost;
    
      location / {
        proxy_pass http://host.docker.internal:3000;
      }
    }
    

提交回复
热议问题