doumei1203 2018-10-11 07:26
浏览 105

Docker中的PHP与NTLM代理:无法分配请求的地址

I have Windows-10 with Docker 18.06.0-ce-win72 (19098). In our network uses NTLM-proxy, so docker goes to the Internet through Ntlmaps (I also try Cntlm, result is the same). I run image based on php:7.2-fpm with docker-compose. I enter the conteiner

docker exec -it {id} bash

and run command:

curl https://packagist.org/packages.json // works!

or

wget https://packagist.org/packages.json // works!

But

php -r "echo file_get_contents('https://packagist.org/packages.json');"

results "failed to open stream: Cannot assign requested address in Command line code on line 1"

curl https://packagist.org/packages.json ----> works
php -r "echo file_get_contents('https://packagist.org/packages.json');" ----------> fails to open stream
php -r "echo curl_exec(curl_init('https://packagist.org/packages.json'));" ---------> works

I see ntlmaps-console and view request from "curl", but it's no requests in console from "file_get_contents".

In php allow_url_open => on

I found similar problem: https://github.com/composer/composer/issues/2169

But I can't disable IPv6 in Docker for test the solution.

I try run "sysctl", but "bash: sysctl: command not found"

I try set

sysctls:
  - net.ipv6.conf.all.disable_ipv6=1
  - net.ipv6.conf.default.disable_ipv6=1
  - net.ipv6.conf.lo.disable_ipv6=1

in docker-compose.yml for service, but it didn't solve the problem

I run this container on VPS and this work on VPS.

How can I solve this problem on Windows + NTLM?

My docker-compose.yml: https://pastebin.com/PfsgzrLs

  • 写回答

1条回答 默认 最新

  • duanqiao2225 2018-11-07 08:00
    关注

    Solution for file_get_contents():

        $context = stream_context_create([
            'http' => [
                'proxy' => 'tcp://10.0.75.1:3112', // 3112 - proxy port on host-mashine
                'request_fulluri' => true
            ]
        ]);
    
        echo file_get_contents('https://ya.ru', false, $context);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决