我有一个正在运行的 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从浏览器在本地网络上访问。(docker run 中定义的服务器内部 IP 和端口)
端口部分docker ps -a
:
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
我添加192.168.1.141 gitlab.domain.com
到/etc/hosts
我的计算机上,并想在服务器端口 80 上运行的 apache 中设置一个代理。我的想法是仅通过输入来查看 gitlab 站点gitlab.domain.com
。
我没有成功,所以我尝试从主机服务器卷曲容器。这些都不起作用:
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>