带有NTLM-proxy的Docker中的PHP:无法分配请求的地址 [英] PHP in Docker with NTLM-proxy: Cannot assign requested address

查看:109
本文介绍了带有NTLM-proxy的Docker中的PHP:无法分配请求的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有带Docker 18.06.0-ce-win72(19098)的Windows-10.在我们的网络中,使用NTLM代理,因此docker通过 Ntlmaps 进入Internet(我也尝试使用 Cntlm ,结果相同).我使用docker-compose运行基于php:7.2-fpm的映像.我进入容器

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

并运行命令:

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

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

但是

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

结果"无法打开流:无法在第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

我看到了ntlmaps-console并查看了来自"curl"的请求,但是控制台中没有来自"file_get_contents"的请求.

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

在php中 allow_url_open =>

我发现了类似的问题: https://github.com/composer/composer/issues/2169

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

但是我不能在Docker中禁用IPv6来测试解决方案.

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

我尝试运行" sysctl ",但是" bash:sysctl:找不到命令"

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

我尝试设置

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

在docker-compose.yml中提供服务,但无法解决问题

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

我在VPS上运行此容器,并且在VPS上运行.

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

如何在Windows + NTLM上解决此问题?

How can I solve this problem on Windows + NTLM?

我的docker-compose.yml: https://pastebin.com/PfsgzrLs

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

推荐答案

file_get_contents()的解决方案:

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);

这篇关于带有NTLM-proxy的Docker中的PHP:无法分配请求的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆