docker 中的容器间网络通信被阻止

docker 中的容器间网络通信被阻止

我从docker开始,并决定在容器中启动我的gitlab实例,以及gitlab-ci-多运行器执行我的 CI 构建(只是为了测试流程的可能性)。

启动 gitlab 实例非常简单,使用sameersbn/docker-gitlab在 github 上。

当我尝试运行 gitlab-ci-multi-runner 时出现了问题,它需要通过主机上的容器间网络向 gitlab 进行授权。

docker-compose up因此我尝试使用以下命令启动运行器容器docker-compose.yml

GitlabCIMultiRunner:
  image: sameersbn/gitlab-ci-multi-runner:0.5.5
  external_links:
    - dockergitlab_gitlab_1
    - dockergitlab_redis_1
    - dockergitlab_postgresql_1
  volumes:
    - /opt/gitlab-ci-multi-runner:/home/gitlab_ci_multi_runner/data
  environment:
    - CI_SERVER_URL=http://172.17.42.1:10080/ci
    - RUNNER_TOKEN=7004aa61f9b54fff738c
    - RUNNER_DESCRIPTION=first_runner2
    - RUNNER_EXECUTOR=shell
  restart: always

(我尝试将端口改为 80,但结果相同)


ifconfig
docker0   Link encap:Ethernet  HWaddr 02:42:67:fb:25:f0  
          inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:67ff:fefb:25f0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:75897 errors:0 dropped:0 overruns:0 frame:0
          TX packets:76897 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:6044672 (6.0 MB)  TX bytes:182094199 (182.0 MB)

eth1      Link encap:Ethernet  HWaddr XX:XX:XX:XX:XX:XX  
          inet6 addr: fe80::76d4:35ff:febf:e59b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:157786 errors:0 dropped:0 overruns:0 frame:0
          TX packets:91095 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:228008432 (228.0 MB)  TX bytes:7527000 (7.5 MB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:27113 errors:0 dropped:0 overruns:0 frame:0
          TX packets:27113 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1492710 (1.4 MB)  TX bytes:1492710 (1.4 MB)

lxcbr0    Link encap:Ethernet  HWaddr ba:8b:63:fc:b4:74  
          inet addr:10.0.3.1  Bcast:10.0.3.255  Mask:255.255.255.0
          inet6 addr: fe80::b88b:63ff:fefc:b474/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:133 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:23031 (23.0 KB)

veth0e49f88 Link encap:Ethernet  HWaddr 22:74:21:72:0f:aa  
          inet6 addr: fe80::2074:21ff:fe72:faa/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:13 errors:0 dropped:0 overruns:0 frame:0
          TX packets:24 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:986 (986.0 B)  TX bytes:5191 (5.1 KB)

veth665256b Link encap:Ethernet  HWaddr b6:fa:d0:ba:87:f1  
          inet6 addr: fe80::b4fa:d0ff:feba:87f1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:346 errors:0 dropped:0 overruns:0 frame:0
          TX packets:466 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:281005 (281.0 KB)  TX bytes:96373 (96.3 KB)

veth907894c Link encap:Ethernet  HWaddr be:ba:12:22:67:92  
          inet6 addr: fe80::bcba:12ff:fe22:6792/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:653 errors:0 dropped:0 overruns:0 frame:0
          TX packets:643 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:50409 (50.4 KB)  TX bytes:170680 (170.6 KB)

vethd4d2b56 Link encap:Ethernet  HWaddr d2:ea:76:1a:63:51  
          inet6 addr: fe80::d0ea:76ff:fe1a:6351/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1017 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1077 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:272555 (272.5 KB)  TX bytes:344684 (344.6 KB)

运行该容器时我会得到:

docker-compose up
Creating dockergitlabcimultirunner_GitlabCIMultiRunner_1...
Attaching to dockergitlabcimultirunner_GitlabCIMultiRunner_1
GitlabCIMultiRunner_1 | time="2015-09-26T20:35:08Z" level=error msg="Couldn't execute POST against http://172.17.42.1:10080/ci/api/v1/runners/register.json: Post http://172.17.42.1:10080/ci/api/v1/runners/register.json: dial tcp 172.17.42.1:10080: i/o timeout" 
GitlabCIMultiRunner_1 | time="2015-09-26T20:35:08Z" level=error msg="7004aa61 Registering runner... failed" 
GitlabCIMultiRunner_1 | time="2015-09-26T20:35:08Z" level=fatal msg="Failed to register this runner. Perhaps you are having network problems" 
dockergitlabcimultirunner_GitlabCIMultiRunner_1 exited with code 0
Gracefully stopping... (press Ctrl+C again to force)
Stopping dockergitlabcimultirunner_GitlabCIMultiRunner_1... done

我可以在 wireshark 中看到数据包发往 gitlab,但它没有回复任何内容:

在此处输入图片描述

我需要说一下,gitlab 运行没有任何问题,我可以从我的主机访问它。

ufw已启用转发:

cat /etc/default/ufw
# /etc/default/ufw
#

# Set to yes to apply rules to support IPv6 (no means only IPv6 on loopback
# accepted). You will need to 'disable' and then 'enable' the firewall for
# the changes to take affect.
IPV6=yes

# Set the default input policy to ACCEPT, DROP, or REJECT. Please note that if
# you change this you will most likely want to adjust your rules.
DEFAULT_INPUT_POLICY="DROP"

# Set the default output policy to ACCEPT, DROP, or REJECT. Please note that if
# you change this you will most likely want to adjust your rules.
DEFAULT_OUTPUT_POLICY="ACCEPT"

# Set the default forward policy to ACCEPT, DROP or REJECT.  Please note that
# if you change this you will most likely want to adjust your rules
DEFAULT_FORWARD_POLICY="ACCEPT"

最令人沮丧的是,我昨天已经让它工作了,但现在我很困惑,因为我没有改变任何东西。

Gitlab的容器文件:https://github.com/sameersbn/docker-gitlab

答案1

我设法通过禁用 ufw 来使其工作。

$ sudo ufw disable

肯定有更好的方法,如果您知道的话请在此处发布。

相关内容