我正在尝试在 docker 的容器之间创建连接。一个带有 php5-fpm 的容器,第二个带有 nginx 的容器。
配置为 php5-fpm 默认值,只需少量更改:
listen = 9000
listen.allowed_clients =
和 nginx(/etc/nginx/sites-available/default):
server {
listen 80 default_server;
#listen [::]:80 default_server ipv6only=on;
root /var/www/testing;
index index.php
# Make site accessible from http://localhost/
server_name localhost;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass 192.168.1.2:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
然后我尝试使用https://github.com/jpetazzo/pipework创建连接,这就是为什么fastcgi_pass 192.168.1.2:9000;
。我尝试使用来自容器的 IP 直接,但没有。
当我尝试使用 lynx 打开页面时,我有 BadGateway。
我尝试发布端口 MASTER_PORT=$(sudo docker port $MASTER_ID 9000),但没有任何... ping 没有问题。从 nginx 远程登录到端口 9000 保持打开几秒钟,然后“连接关闭...”
谁能解释我做错了什么?谢谢!
/编辑/我尝试将fastcgi_pass更改为172.17.42.1:9000;(主机上 docker0 的地址),然后在主机上启动 tcpdump:
tcpdump -i docker0 端口 9000
我有:
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on docker0, link-type EN10MB (Ethernet), capture size 65535 bytes
10:24:54.529572 IP 172.17.0.20.40932 > 172.17.42.1.9000: Flags [S], seq 141160046, win 14600, options [mss 1460,sackOK,TS val 1235770 ecr 0,nop,wscale 7], length 0
10:24:54.529594 IP 172.17.42.1.9000 > 172.17.0.20.40932: Flags [S.], seq 2944341886, ack 141160047, win 14480, options [mss 1460,sackOK,TS val 1235770 ecr 1235770,nop,wscale 7], length 0
10:24:54.529605 IP 172.17.0.20.40932 > 172.17.42.1.9000: Flags [.], ack 1, win 115, options [nop,nop,TS val 1235770 ecr 1235770], length 0
10:24:54.530324 IP 172.17.0.20.40932 > 172.17.42.1.9000: Flags [P.], seq 1:665, ack 1, win 115, options [nop,nop,TS val 1235771 ecr 1235770], length 664
10:24:54.530387 IP 172.17.42.1.9000 > 172.17.0.20.40932: Flags [.], ack 665, win 124, options [nop,nop,TS val 1235771 ecr 1235771], length 0
10:24:54.530534 IP 172.17.42.1.44233 > 172.17.0.12.9000: Flags [S], seq 1354597292, win 14600, options [mss 1460,sackOK,TS val 1235771 ecr 0,nop,wscale 7], length 0
10:24:54.530549 IP 172.17.0.12.9000 > 172.17.42.1.44233: Flags [R.], seq 0, ack 1354597293, win 0, length 0
10:24:54.531044 IP 172.17.42.1.9000 > 172.17.0.20.40932: Flags [R.], seq 1, ack 665, win 124, options [nop,nop,TS val 1235771 ecr 1235771], length 0
因此数据包在容器之间传递......但为什么是 BadGateway?