使用的是 Docker executor 去跑的构建,他反馈说构建容器内部无法访问 minio 的 9000 端口,我大致看了下,发现 service 的 alias 实际上用的是 docker run 的 –link 实现的,也就是容器的 hosts 文件里添加记录指向容器IP,官方文档 service 字段 也是如此说明
排错过程
故障现象
构建过程是 7a9ff9c8ee95 无法访问 minio 里的 9000 端口,直接用 ip,不用 alias 别名都无法访问
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7a9ff9c8ee95 83daaac121e6 "sh -c 'if [ -x /usr…" 41 seconds ago Up 40 seconds runner-s4f3kt7-project-15927-concurrent-0-eed4eb59d5dfa521-build-2 883faff17a2d e59a4655709b "/usr/bin/dumb-init …" 42 seconds ago Exited (0) 41 seconds ago runner-s4f3kt7-project-15927-concurrent-0-eed4eb59d5dfa521-predefined-1 2662fd58cad5 e59a4655709b "/usr/bin/dumb-init …" 43 seconds ago Exited (0) 42 seconds ago runner-s4f3kt7-project-15927-concurrent-0-eed4eb59d5dfa521-predefined-0 139e1a01b50f 9546ca122d3a "docker-entrypoint.s…" About a minute ago Up About a minute 3306/tcp runner-s4f3kt7-project-15927-concurrent-0-eed4eb59d5dfa521-mysql-1 de4647deead4 c15374551d3a "/usr/bin/docker-ent…" About a minute ago Up About a minute 9000/tcp runner-s4f3kt7-project-15927-concurrent-0-eed4eb59d5dfa521-minio__minio-0 $ docker inspect de46 | grep -i pid "Pid": 23888, "PidMode": "", "PidsLimit": 0, $ nsenter --net -t 23888 curl 172.25.0.2:9000 <?xml version="1.0" encoding="UTF-8"?> <Error><Code>AccessDenied</Code><Message>Access Denied.</Message><Resource>/</Resource><RequestId>17127033A4D00006</RequestId><HostId>ec1fb8ef-f0f0-488e-a71e-da444933f2ed</HostId></Error> $ docker exec -ti 7a9ff9c8ee95 curl 172.25.0.2:9000 curl: (7) Failed to connect to 172.25.0.2 port 9000: Connection refused
$ curl 172.25.0.2:9000 curl: (7) Failed to connect to 172.25.0.2 port 9000: Connection refused $ nsenter --net -t 23888 curl 172.25.0.2:9000 <?xml version="1.0" encoding="UTF-8"?> <Error><Code>AccessDenied</Code><Message>Access Denied.</Message><Resource>/</Resource><RequestId>17127033A4D00006</RequestId><HostId>ec1fb8ef-f0f0-488e-a71e-da444933f2ed</HostId></Error>
为了排除 minio 服务问题,清理掉上面的容器后,用官方的 nginx 镜像测试下:
1 2 3 4 5 6 7 8 9
$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES $ docker run -d --name t1 --rm -p 81:80 nginx:alpine 91fa481376cbbbdf04dd7ed027048ad20f40eee18f4e7d916d9edba8da102412 $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 91fa481376cb nginx:alpine "/docker-entrypoint.…" About a minute ago Up About a minute 0.0.0.0:81->80/tcp t1 $ docker inspect t1 | grep IPAddress "IPAddress": "172.25.0.2",
发现访问还是有问题
1 2 3 4 5 6 7 8
$ curl 172.25.0.2 curl: (7) Failed to connect to 172.25.0.2 port 80: Connection refused $ ip link set docker0 promisc on $ curl 172.25.0.2 curl: (7) Failed to connect to 172.25.0.2 port 80: Connection refused
$ docker run -d --rm -p 81:80 nginx:alpine a0952e42f6a0da9d1969b327e696022c2dea041061cee2fbf080134037c9c93b $ docker run -d --rm -p 82:80 nginx:alpine dcf7d4635f1379b321603760c71a94bf70b1b954bb5528d384f7f9d38d4ed005 $ docker run -d --rm -p 83:80 nginx:alpine 44d5611125bb773ecc24baf760d4ba19f90a33c0b5c802e6afbeee462f200df0 $ docker run -d --rm -p 84:80 nginx:alpine 145b99fea102f71bc99132f2ae5aa8401f890df5d10177964df3e3f4e3fd8281 $ curl localhost:82 curl: (56) Recv failure: Connection reset by peer $ curl localhost:83 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p>
<p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p> </body> </html>