我正在尝试创建一个简单的 GitLab CI,在其中使用 docker-compose up 启动容器,然后尝试使用 curl 访问它,最后使用 docker-compose down 将其拆除。docker-compose up 旋转得非常好,我可以使用 docker ps -a 看到容器启动,但是当我卷曲时,我得到“连接被拒绝”。
这是我的 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
码头工人组成:
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"