gitlab-ci.yml & docker-in-docker (dind) & curl returns 连接在共享运行器上被拒绝
gitlab-ci.yml & docker-in-docker (dind) & curl returns connection refused on shared runner
我正在尝试创建一个简单的 GitLab CI,我在其中使用 docker-compose up 启动一个容器,然后尝试使用 curl 访问它,最后使用 [=32 将其拆除=]-写下来。 docker-compose up 旋转起来非常好,我可以使用 docker ps -a 看到容器向上,但是当我卷曲时,我得到 "connection refused".
这是我的gitlab-ci.yml
image: docker
services:
- docker:dind
before_script:
- apk add --update python py-pip python-dev && pip install docker-compose
- apk add --update curl && rm -rf /var/cache/apk/*
stages:
- test
test:
stage: test
script:
- docker-compose up -d
- docker ps -a
- curl http://localhost:5000/api/values
- docker-compose down
这是跑步者的日志
Image for service testwebapp was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating test-container ...
Creating test-container ... done
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3423adfb1f3b mytestwebapp "dotnet TestWebApp.d…" 1 second ago Up Less than a second 0.0.0.0:5000->5000/tcp test-container
$ curl http://localhost:5000/api/values
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (7) Failed to connect to localhost port 5000: Connection refused
ERROR: Job failed: exit code 7
Docker撰写:
version: '3.4'
services:
testwebapp:
image: mytestwebapp
build:
context: .
dockerfile: TestWebApp/Dockerfile
container_name: test-container
Docker 撰写覆盖:
version: '3.4'
services:
testwebapp:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:5000
ports:
- "5000:5000"
更新您的 gitlab-ci.yml
文件:
在运行curl
之前设置sleep 15
。 15 是您的服务应该准确启动的任意时间段(以秒为单位)。
接下来有2个选项:https://docs.gitlab.com/ee/ci/services/#how-services-are-linked-to-the-job:
选项 1:
像这样 curl http://docker:5000/api/values
将 curl http://localhost:5000/api/values
中的 localhost
替换为 docker
选项 2:
services:
- name: docker:dind
alias: localhost
我正在尝试创建一个简单的 GitLab CI,我在其中使用 docker-compose up 启动一个容器,然后尝试使用 curl 访问它,最后使用 [=32 将其拆除=]-写下来。 docker-compose up 旋转起来非常好,我可以使用 docker ps -a 看到容器向上,但是当我卷曲时,我得到 "connection refused".
这是我的gitlab-ci.yml
image: docker
services:
- docker:dind
before_script:
- apk add --update python py-pip python-dev && pip install docker-compose
- apk add --update curl && rm -rf /var/cache/apk/*
stages:
- test
test:
stage: test
script:
- docker-compose up -d
- docker ps -a
- curl http://localhost:5000/api/values
- docker-compose down
这是跑步者的日志
Image for service testwebapp was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating test-container ...
Creating test-container ... done
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3423adfb1f3b mytestwebapp "dotnet TestWebApp.d…" 1 second ago Up Less than a second 0.0.0.0:5000->5000/tcp test-container
$ curl http://localhost:5000/api/values
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (7) Failed to connect to localhost port 5000: Connection refused
ERROR: Job failed: exit code 7
Docker撰写:
version: '3.4'
services:
testwebapp:
image: mytestwebapp
build:
context: .
dockerfile: TestWebApp/Dockerfile
container_name: test-container
Docker 撰写覆盖:
version: '3.4'
services:
testwebapp:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:5000
ports:
- "5000:5000"
更新您的 gitlab-ci.yml
文件:
在运行
curl
之前设置sleep 15
。 15 是您的服务应该准确启动的任意时间段(以秒为单位)。接下来有2个选项:https://docs.gitlab.com/ee/ci/services/#how-services-are-linked-to-the-job:
选项 1:
像这样 curl http://docker:5000/api/values
curl http://localhost:5000/api/values
中的 localhost
替换为 docker
选项 2:
services:
- name: docker:dind
alias: localhost