douguxun6866
2015-12-09 10:34
浏览 919

获取Docker链接容器localhost指向主机localhost

So on my host environment I have this tomcat service running on port 10000 so I can access the office internal services.

I have a windows hosts entry:

localhost developer.mycompany.com

So I can access the endpoint developer.mycompany.com:10000/some/url and if successful return a json response.

I also have a Docker compose file that has spun up nginx and php-fpm containers and linked them to run a linux based PHP development environment.

What I am trying to achieve is to make the docker container(s) aware of the developer.mycomoany.com host entry. So when my PHP code on my linke containers sends a POST request to http://developer.mycompany.com:10000/some/urlit knows about the host entry and is able to hit that end point.

I have tried the config net=host but that doesn't work with linked containers.

PHP app error message:

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

How do I enable my PHP app on my linked containers to talk to the host developer.mycompany.com (localhost) entry?

Here is my docker-compose:

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

Edits:

Her is my ifconfig output from docker machine.

enter image description here

Thanks

图片转代码服务由CSDN问答提供 功能建议

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

我有一个Windows主机条目:

localhost developer.mycompany.com < p>所以我可以访问端点 developer.mycompany.com:10000/some/url ,如果成功返回json响应。

我也有一个Docker 编写已经旋转了nginx和php-fpm容器的文件并将它们链接起来运行基于Linux的PHP开发环境。

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

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

PHP app 错误消息:

{“result”:{“success”:false,“message”:“创建资源时出错:[message] fopen():php_network_getaddresses:getaddrinfo 失败:名称或服务未知 [file] /srv/http/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php [line] 282 [message] fopen(http://developer.mycompany .com:10000 / app / register):无法打开流:php_network_getaddresses:getaddrinfo failed:名称或服务未知 [file] /srv/http/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php\ [line] 282“}}

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

这是我的docker-compose:

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

编辑:

她是来自docker机器的ifconfig输出。

< / a>

谢谢

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douhuo3696 2015-12-14 10:41
    已采纳

    I found the IP of my docker machine and used that in my hosts nginx proxy config like such which then redirected it to the nginx location config in my docker container.

    Host nginx:

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

    Docker Nginx container config:

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

相关推荐 更多相似问题