Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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:

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.

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

My .gitlab-ci.yml file looks like:

---

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:

$ 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. 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.

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:

/ # 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.

like image 332
Craig Otis Avatar asked Jul 29 '17 12:07

Craig Otis


People also ask

Is docker compose included in docker?

If you have Docker Desktop, you've got a full Docker installation, including Compose.

How do I bring down docker compose containers?

docker-compose down - command will stop running containers, but it also removes the stopped containers as well as any networks that were created. You can take down one step further and add the -v flag to remove all volumes too.


1 Answers

The container is running on the "docker host" which is, in your case, the other container that is supporting the Gitlab build:

services:
  - docker:dind

If I'm not wrong, its host name is docker. So access as this:

echo "Hello world" | nc docker 8800

To figure out what is the host of the docker daemon, use this:

script:
  - echo $DOCKER_HOST
like image 158
Robert Avatar answered Sep 22 '22 18:09

Robert