我有一个案例,我想对一个docker-compose up -d
可以成功卷曲由撰写文件创建的端点进行快速运行状况检查。
这是我文件的相关部分的样子:
compose:
stage: compose
image: tmaier/docker-compose:latest
services:
- docker:dind
before_script:
- apk update
- apk add -y curl
- docker info
- docker-compose --version
- echo $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin registry.gitlab.com
script:
- cd docker/compose/
- docker-compose run --use-aliases -d nginx
- cat /etc/hosts
- curl --fail http://localhost
我已经尝试过所有类型的东西,比如http://dockerhost
, http://docker
, http://nginx
, --use-aliases
, -p 80:80
。docker-compose run -d nginx
和在我的curl --fail http://localhost
计算机上工作正常,只是在这里不起作用,这里还有一些输出可以帮助你帮助我。
$ cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.3 docker fe41d99555a4 runner-0277ea0f-project-8964623-concurrent-0-docker-0
172.17.0.4 runner-0277ea0f-project-8964623-concurrent-0
$ curl --fail http://localhost
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (7) Failed to connect to localhost port 80: Connection refused
这一切都在本地工作,但似乎在 gitlab-ci 中不起作用。交叉从https://github.com/tmaier/docker-compose/issues/14发布。
根据评论者的要求,这里有一些额外的调试信息:
$ docker-compose port nginx 80
0.0.0.0:80
$ docker-compose port django 8000
0.0.0.0:8000
$ docker ps
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ea9c0d0f8aba celery_worker "/start_celery.sh -d…" 4 seconds ago Up 1 second compose_celery-beat_1_3cc1424b6246
6f5adc306f08 celery_beat "/start_celery.sh -d…" 4 seconds ago Up 1 second compose_celery-worker_1_82f9d734734b
4d8d18ee0aa0 nginx "nginx -g 'daemon of…" 4 seconds ago Up 1 second 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp compose_nginx_1_d6a895d7ea5a
0e3f43da2694 django "/start.sh -docker" 4 seconds ago Up 3 seconds 0.0.0.0:8000->8000/tcp compose_django_1_c7d04b2e58cb
260a04a50134 redis:3.0-alpine "docker-entrypoint.s…" 5 seconds ago Up 4 seconds 0.0.0.0:6379->6379/tcp compose_redis_1_d6cf5f09d98a
49097614e743 postgres:10-alpine "docker-entrypoint.s…" 5 seconds ago Up 4 seconds (health: starting) 5432/tcp compose_hoarder-datastore_1_a7db557d6f4c