简体   繁体   English

无法访问在docker中创建的docker-compose容器

[英]Unable to access docker-compose containers created inside docker

I have a docker-compose.yml file that starts up a simple HTTP echo service on port 8800 . 我有一个docker-compose.yml文件,它在端口8800上启动一个简单的HTTP echo服务。

version: '2'

services:
    echo-server:
        image: luisbebop/echo-server
        container_name: echo-server
        ports:
        - "8800:8800"

Super simple stuff. 超级简单的东西。 If I run docker-compose up and run on my local machine: 如果我运行docker-compose up并在我的本地机器上运行:

echo "Hello World" | nc 127.0.0.1 8800

Then I see the echo. 然后我看到回声。 However: If I run this same compose scenario inside a docker container, through the GitLab runner, it fails. 但是:如果我在docker容器中运行同一个compose场景,通过GitLab运行器,它会失败。

I've tried to garner attention for this issue at GitLab here, but with limited results: https://gitlab.com/gitlab-org/gitlab-ce/issues/26566 我试图在GitLab上引起关注这个问题,但结果有限: https//gitlab.com/gitlab-org/gitlab-ce/issues/26566

My .gitlab-ci.yml file looks like: 我的.gitlab-ci.yml文件看起来像:

---

stages:
  - docker_test

services:
  - docker:dind

docker_test:
  stage: docker_test
  image: docker:latest
  script:
  - docker version
  - apk update
  - apk add py-pip
  - pip install docker-compose
  - docker-compose up -d
  - sleep 10
  - netstat -tulpn
  - docker-compose port echo-server 8800
  - echo "Hello world" | nc 127.0.0.1 8800

And the output of gitlab-ci-multi-runner exec docker --docker-privileged docker_test is: gitlab-ci-multi-runner exec docker --docker-privileged docker_test是:

$ netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name

$ docker-compose port echo-server 8800
0.0.0.0:8800

$ echo "Hello world" | nc 127.0.0.1 8800
ERROR: Build failed: exit code 1

So it seems like these ports aren't available inside the docker container, which is in charge of the docker-compose services. 因此看起来这些端口在docker容器中不可用,它负责docker-compose服务。 Am I doing something wrong? 难道我做错了什么?

I do not want the ports exposed at the host level, rather I just want the ports opened by the docker container running the build , available to that container. 希望在主机级别暴露端口,而只是希望运行构建的docker容器打开的端口可用于该容器。

Host (My Mac) -> GitLab CI Container -> Docker Compose Container exposing 8800

  ^ Not here        ^ I want port 8800 accessible here 

Edit: Further, if I attach a shell to the running CI container, I see: 编辑:此外,如果我将shell附加到正在运行的CI容器,我看到:

/ # docker ps
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                    NAMES
ab192edf5872        luisbebop/echo-server   "/opt/echo-server/..."   2 minutes ago       Up About a minute   0.0.0.0:8800->8800/tcp   echo-server
/ # netstat -nltup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name

So it "sees" the container, and the port mappings look okay, but the port isn't actually listening. 所以它“看到”容器,并且端口映射看起来没问题,但端口实际上并没有正在侦听。

The container is running on the "docker host" which is, in your case, the other container that is supporting the Gitlab build: 容器正在“docker host”上运行,在您的情况下,这是支持Gitlab构建的另一个容器:

services:
  - docker:dind

If I'm not wrong, its host name is docker . 如果我没错,它的主机名是docker So access as this: 所以访问如下:

echo "Hello world" | nc docker 8800

To figure out what is the host of the docker daemon, use this: 要弄清楚docker守护程序的主机是什么,请使用:

script:
  - echo $DOCKER_HOST

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM