I have a case where I want to do a quick healthcheck on a docker-compose up -d
where I can successfully curl the endpoint being created by the compose file.
Here is what the relevant parts of my file look like:
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
I have tried all types of things like http://dockerhost
, http://docker
, http://nginx
, --use-aliases
, -p 80:80
. The docker-compose run -d nginx
and curl --fail http://localhost
works fine on my computer, just doesn't work here, also here is some output that might help you help me.
$ 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
This all works locally, but doesn't appear to work in gitlab-ci. Cross posted from https://github.com/tmaier/docker-compose/issues/14.
Per request from a commenter, here is some additional debug info:
$ 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
Instead of referencing
http://localhost
you should usehttp://docker
.