我正在尝试创建一个简单的GitLab CI,在其中我使用docker-compose up旋转一个容器,然后尝试使用curl对其进行访问,最后使用docker-compose down将其拆解。 docker-compose up旋转得非常好,我可以使用docker ps -a看到容器,但是当我卷曲时,我会收到“连接被拒绝”的信息。
这是我的gitlab-ci.yml
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
/home/travis/.rvm/gems/ruby-2.4.1@global/gems/rake- 12.3.0/exe/rake:27:in `<top (required)>'
(See full trace by running task with --trace)
The command "rake" exited with 1.
Done. Your build exited with 1.
这是跑步者的日志
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
Docker Compose:
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
答案 0 :(得分:0)
更新您的gitlab-ci.yml
文件:
sleep 15
之前设置curl
。 15是您可以正确启动服务的任意时间(以秒为单位)。
接下来,有2个选项:
选项1 :
将localhost
中的curl http://localhost:5000/api/values
替换为docker
curl http://docker:5000/api/values
选项2 :
services:
- name: docker:dind
alias: localhost