gitlan ce online,gitlab-ci.yml,docker dind无法使用暴露的端口访问容器(curl:连接被拒绝)

时间:2019-01-30 17:22:49

标签: docker gitlab gitlab-ci gitlab-ci-runner dind

我正在尝试使用管道来测试我的nodejs代码。 想法是使用一个已经在内部使用的容器,即具有我个人配置的SonarQube,进行镜像,然后推送到GitLab上的私人仓库中。

无论如何,似乎我可以使用它,并使用docker:dind运行,但是当需要使用容器中包含的服务时,出现了一些问题。 即使使用docker ps似乎已正确绑定暴露端口,我也无法访问http://IP:9000端点。

我想念什么?可以使用共享跑步者吗?

谢谢, 洛伦佐

这是我gitlab-ci.yml中的工作

sec_dev_static:
  stage: sec_dev_static
  image: gitlab/dind:latest
  variables:
    DOCKER_DRIVER: overlay
  services:
    - docker:dind
  before_script:
    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
    - docker run -d --name sonarqube -p 9000:9000 registry.gitlab.com/<my sonarqube custom image>
    - docker inspect sonarqube | grep "IPAddress"
    - docker ps -a
    - sleep 20  ==> I added this sleep (if it has any sense, because sonarqube takes time to start)
  script:
    - echo "Quality check"
    - "ping -c 4 localhost"
    - "curl -X GET http://127.0.0.1:9000" ==> only to test if it is up and running...

这是日志

Status: Downloaded newer image for registry.gitlab.com/<my sonarqube custom image>

$ docker inspect sonarqube | grep "IPAddress"
            "SecondaryIPAddresses": null,
            "IPAddress": "172.18.0.2",
                    "IPAddress": "172.18.0.2",
$ docker ps -a
CONTAINER ID        IMAGE                                                                   COMMAND             CREATED                  STATUS                  PORTS        
aaaaaaaaaaaa        registry.gitlab.com/<my sonarqube custom image>   "./bin/run.sh"      Less than a second ago   Up Less than a second   0.0.0.0:9000->9000/tcp, 9092/tcp
$ sleep 20
$ echo "Quality check"
Quality check

$ ping -c 4 localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.047 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.044 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.040 ms
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.032 ms

--- localhost ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3064ms
rtt min/avg/max/mdev = 0.032/0.040/0.047/0.009 ms
$ curl -X GET http://127.0.0.1:9000
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (52) Empty reply from server
ln: failed to create symbolic link '/sys/fs/cgroup/systemd/name=systemd': Operation not permitted
/usr/local/bin/wrapdocker: line 113:    52 Killed                  docker daemon $DOCKER_DAEMON_ARGS &> /var/log/docker.log
Timed out trying to connect to internal docker host.
ERROR: Job failed: exit code 1

最后,容器似乎不可用/无法到达/尚未准备就绪。

0 个答案:

没有答案
相关问题