无法向官方Docker容器中运行的gitlab发出请求

时间:2017-07-26 14:03:13

标签: docker gitlab

我正在尝试使用给定here的指令从Docker(gitlab / gitlab-ce,latest)容器运行gitlab。

Docker版本

Docker version 1.12.4, build 1564f02

我先跑

docker run --detach --hostname <myIP> --publish 8000:443--publish 8001:80 --publish 8002:22 --name gitlab --restart always --volume /docker/app/gitlab/config:/etc/gitlab --volume /docker/app/gitlab/logs:/var/log/gitlab --volume /docker/app/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce:latest

然后我编辑了容器的/etc/gitlab/gitlab.rb来设置

external_url 'http://<myIP>:8001'
gitlab_rails['gitlab_shell_ssh_port'] = 8002

然后我用

重新启动容器
docker restart gitlab

现在

当我尝试连接<myIP>:8001时,我收到了(110) Connection timed out

当我尝试使用Docker容器的主机时,我得到了

xxx@xxx:~$ curl localhost:8001
curl: (56) Recv failure: Connection reset by peer

记录(只是结束)

==> /var/log/gitlab/gitlab-workhorse/current <==
2017-07-26_14:53:41.50465 localhost:8001 @ - - [2017-07-26 14:53:41.223110228 +0000 UTC] "GET /help HTTP/1.1" 200 33923 "" "curl/7.53.0" 0.281484

==> /var/log/gitlab/nginx/gitlab_access.log <==
127.0.0.1 - - [26/Jul/2017:14:53:41 +0000] "GET /help HTTP/1.1" 200 33967 "-" "curl/7.53.0"

==> /var/log/gitlab/gitlab-monitor/current <==
2017-07-26_14:53:47.27460 ::1 - - [26/Jul/2017:14:53:47 UTC] "GET /sidekiq HTTP/1.1" 200 3399
2017-07-26_14:53:47.27464 - -> /sidekiq
2017-07-26_14:53:49.22004 ::1 - - [26/Jul/2017:14:53:49 UTC] "GET /database HTTP/1.1" 200 42025
2017-07-26_14:53:49.22007 - -> /database
2017-07-26_14:53:51.48866 ::1 - - [26/Jul/2017:14:53:51 UTC] "GET /process HTTP/1.1" 200 7132
2017-07-26_14:53:51.48873 - -> /process

==> /var/log/gitlab/gitlab-rails/production.log <==
Started GET "/-/metrics" for 127.0.0.1 at 2017-07-26 14:53:55 +0000
Processing by MetricsController#index as HTML
Filter chain halted as :validate_prometheus_metrics rendered or redirected
Completed 404 Not Found in 1ms (Views: 0.7ms | ActiveRecord: 0.0ms)

Docker ps

xxx@xxx:~$ docker ps
CONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS                       PORTS                                                               NAMES
67e013741b6d        gitlab/gitlab-ce:latest   "/assets/wrapper"        2 hours ago         Up About an hour (healthy)   0.0.0.0:8002->22/tcp, 0.0.0.0:8001->80/tcp, 0.0.0.0:8000->443/tcp   gitlab

用netstat

xxx@xxx:~$ netstat --listen
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 localhost:smtp          *:*                     LISTEN     
tcp        0      0 *:2020                  *:*                     LISTEN     
tcp        0      0 *:git                   *:*                     LISTEN     
tcp        0      0 *:43918                 *:*                     LISTEN     
tcp        0      0 *:sunrpc                *:*                     LISTEN     
tcp6       0      0 localhost:smtp          [::]:*                  LISTEN     
tcp6       0      0 [::]:8000               [::]:*                  LISTEN     
tcp6       0      0 [::]:8001               [::]:*                  LISTEN     
tcp6       0      0 [::]:8002               [::]:*                  LISTEN     
tcp6       0      0 [::]:2020               [::]:*                  LISTEN     
tcp6       0      0 [::]:git                [::]:*                  LISTEN     
tcp6       0      0 [::]:sunrpc             [::]:*                  LISTEN     
tcp6       0      0 [::]:http               [::]:*                  LISTEN     
tcp6       0      0 [::]:43730              [::]:*                  LISTEN     
udp        0      0 *:54041                 *:*                                
udp        0      0 *:sunrpc                *:*                                
udp        0      0 *:snmp                  *:*                                
udp        0      0 *:958                   *:*                                
udp        0      0 localhost:969           *:*                                
udp        0      0 *:37620                 *:*                                
udp6       0      0 [::]:54611              [::]:*                             
udp6       0      0 [::]:sunrpc             [::]:*                             
udp6       0      0 localhost:snmp          [::]:*                             
udp6       0      0 [::]:958                [::]:* 

我找不到有什么问题。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

这是docker-compose.yml,对我来说很好用

version: '2'
services:
  gitlab:
    image: gitlab/gitlab-ce:latest
    ports:
      - "8002:22"
      - "8000:8000"
      - "8001:443"
    environment:
      - "GITLAB_OMNIBUS_CONFIG=external_url 'http://192.168.33.100:8000/'"
    volumes:
      - ./config:/etc/gitlab
      - ./logs:/var/log/gitlab
      - ./data:/var/opt/gitlab

问题在于,当您将外部URL配置为<MyIP>:8000时,容器内的侦听端口也会更新为8000.在您的情况下,您将端口8000映射到80并且您应该只将8000映射到8000

请阅读以下网址,了解相同的详情

https://docs.gitlab.com/omnibus/settings/nginx.html#setting-the-nginx-listen-port

如果您需要覆盖此端口,则可以在gitlab.rb

中执行此操作
nginx['listen_port'] = 8081

我更喜欢使用docker-compose文件而不是命令启动Gitlab,因为它易于配置,启动,重启gitlab