docker-compose.yml
8800
version: '2'
services:
echo-server:
image: luisbebop/echo-server
container_name: echo-server
ports:
- "8800:8800"
超级简单的东西。如果我跑步
docker-compose up
echo "Hello World" | nc 127.0.0.1 8800
然后我看到回声。
然而:
如果我在docker容器中通过GitLab runner运行相同的撰写场景,它就会失败。
https://gitlab.com/gitlab-org/gitlab-ce/issues/26566
.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
以及
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
因此,这些端口似乎在docker容器中不可用,docker容器负责docker compose服务。我做错什么了吗?
不要
,可用于该容器。
Host (My Mac) -> GitLab CI Container -> Docker Compose Container exposing 8800
^ Not here ^ I want port 8800 accessible here
此外,如果我将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