在浏览器中可用的Docker容器,但无法使用curl命令访问。

我有一个正在运行的GitLab容器。运行命令:
sudo docker run --detach \
  --hostname gitlab.domain.com \
  --publish 8888:80 --publish 2222:22 \
  --name gitlab \
  --restart always \
  --volume /home/apps/gitlab/config:/etc/gitlab \
  --volume /home/apps/gitlab/logs:/var/log/gitlab \
  --volume /home/apps/gitlab/data:/var/opt/gitlab \
  gitlab/gitlab-ce:latest
gitlab应用程序正常运行,并且可以通过在浏览器中输入http://192.168.1.141:8888来从本地网络访问。(服务器的内部IP和端口在docker run中定义) docker ps -a命令的PORTS部分:
443/tcp, 0.0.0.0:2222->22/tcp, 0.0.0.0:8888->80/tcp
服务器上的开放端口:
~$ netstat -l | grep 8888
tcp6     0     0     [::]:8888     [::]:*     LISTEN
我在我的电脑上的/etc/hosts文件中添加了192.168.1.141 gitlab.domain.com,并希望在运行在服务器端口80上的Apache中设置代理。 我的想法是只需输入gitlab.domain.com就可以查看GitLab网站。 但是我没有成功,所以我尝试从主机服务器上使用curl命令来访问容器。以下两个命令都没有成功: curl http://localhost:8888
curl http://192.168.1.141:8888 结果为:
~$ curl http://localhost:8888 -v
*   Trying 127.0.0.1:8888...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8888 (#0)
> GET / HTTP/1.1
> Host: localhost:8888
> User-Agent: curl/7.66.0
> Accept: */*
> 
有没有想法为什么会发生这种情况?如何从主机服务器连接到GitLab页面? 如果我在我的电脑上执行curl 192.168.1.141:8888,它可以正常工作。
$ curl 192.168.1.141:8888 -v
* Rebuilt URL to: 192.168.1.141:8888/
*   Trying 192.168.1.141...
* TCP_NODELAY set
* Connected to 192.168.1.141 (192.168.1.141) port 8888 (#0)
> GET / HTTP/1.1
> Host: 192.168.1.141:8888
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 302 Found
< Server: nginx
< Date: Sun, 03 Nov 2019 16:27:53 GMT
< Content-Type: text/html; charset=utf-8
< Content-Length: 105
< Connection: keep-alive
< Cache-Control: no-cache
< Location: http://192.168.1.141:8888/users/sign_in
< Referrer-Policy: strict-origin-when-cross-origin
< Set-Cookie: experimentation_subject_id=ImQyMThkOWI4LWM2MjQtNGM5ZS1hOTZiLTc4YTFhN2U3YjhmNSI%3D--a9d45810de1608210d337df71cbad8c0ac10de16; path=/; expires=Thu, 03 Nov 2039 16:27:53 -0000
< X-Content-Type-Options: nosniff
< X-Download-Options: noopen
< X-Frame-Options: DENY
< X-Permitted-Cross-Domain-Policies: none
< X-Request-Id: LnCSv7rcW6a
< X-Runtime: 0.010182
< X-Ua-Compatible: IE=edge
< X-Xss-Protection: 1; mode=block
< Strict-Transport-Security: max-age=31536000
< Referrer-Policy: strict-origin-when-cross-origin
< 
* Connection #0 to host 192.168.1.141 left intact
<html><body>You are being <a href="http://192.168.1.141:8888/users/sign_in">redirected</a>.</body></html>
1个回答

是防火墙的问题。停止防火墙后,curl正常工作。

哪个防火墙?Docker主机还是Docker容器? - cristianmtr
如果我没记错的话,那是内部网络防火墙。 - Andrej S