正在获取 Docker 个指向主机 localhost 的链接容器 localhost

Getting Docker linked containers localhost pointing to host localhost

所以在我的主机环境中,我在端口 10000 上有这个 tomcat 服务 运行ning,所以我可以访问办公室内部服务。

我有一个 windows 主机条目:

localhost developer.mycompany.com

所以我可以访问端点 developer.mycompany.com:10000/some/url,如果成功 return 一个 json 响应。

我还有一个 Docker compose 文件,它启动了 nginx 和 php-fpm 容器并将它们链接到 运行 基于 linux 的 PHP 开发环境.

我想要实现的是让 docker 容器知道 developer.mycomoany.com 主机条目。因此,当我的 linke 容器上的 PHP 代码向 http://developer.mycompany.com:10000/some/url 发送 POST 请求时,它知道主机条目并能够到达该终点。

我已经尝试了配置 net=host,但这不适用于链接的容器。

PHP 应用程序错误消息:

{"result":{"success":false,"message":"Error creating resource: [message] fopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known\n[file] /srv/http/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php\n[line] 282\n[message] fopen(http://developer.mycompany.com:10000/app/register): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known\n[file] /srv/http/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php\n[line] 282"}}

如何在链接的容器上启用我的 PHP 应用程序以与主机 developer.mycompany.com (localhost) 条目通信?

这是我的 docker-撰写:

app:
  image: linxlad/docker-php-fpm
  tty: true
  ports:
   - "9000:9000"
  volumes:
   - ./logs/php-fpm:/var/log/php-fpm
   - ~/Development/Apps/php-hello-world:/srv/http
web:
  image: linxlad/docker-nginx
  ports:
   - "8080:80"
  volumes:
   - ./conf/nginx:/etc/nginx/conf.d
   - ./logs/nginx:/var/log/nginx
   - ~/Development/Apps/php-hello-world:/srv/http
  links:
   - app

编辑:

她是我在 docker 机器上的 ifconfig 输出。

谢谢

我找到了我的 docker 机器的 IP 并在我的主机 nginx 代理配置中使用了它,然后将它重定向到我的 docker 容器中的 nginx 位置配置。

主机 nginx:

location /apps/myapp/appversion {
    proxy_pass   http://192.168.99.100:8080;
} 

Docker Nginx 容器配置:

location /apps/myapp/appversion {
    try_files $uri $uri/ /index.php?args;
    if (!-e $request_filename) {
        rewrite ^/(.*)$ /index.php last;
    }
}