Skip to content

Instantly share code, notes, and snippets.

@Ocramius
Last active Jun 18, 2020
Embed
What would you like to do?
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2
build-test-containers:
image: tiangolo/docker-with-compose
before_script:
- docker info
- docker-compose --version
script:
- cd tests/e2e
- docker-compose up --build -d
- sleep 30
- docker-compose run build-tools entry-point ping -c 4 dependency
version: '3'
services:
mysql:
build:
context: docker/mysql
dockerfile: Dockerfile
networks:
another-test-network:
aliases:
- "db.test"
build-tools:
build:
context: .
dockerfile: docker/build-tools/Dockerfile
depends_on:
- mysql
networks:
another-test-network:
aliases:
- "build-tools.test"
networks:
another-test-network:
$ docker-compose --version
docker-compose version 1.21.0, build 5920eb0
$ cd tests/e2e
$ docker-compose -f docker-compose.ci.yml up --build -d
[SNIP]
Successfully built 473cdf77700b
Successfully tagged e2e_build-tools:latest
Creating e2e_mysql_1 ...
Creating e2e_mysql_1 ... done
Creating e2e_build-tools_1 ...
Creating e2e_build-tools_1 ... done
$ sleep 30
$ docker-compose -f docker-compose.ci.yml run build-tools mysql -h db.test -u root -proot-password -e "SELECT 1;"
Starting e2e_mysql_1 ...
Starting e2e_mysql_1 ... done
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2005 (HY000): Unknown MySQL server host 'db.test' (2)
ERROR: Job failed: exit code 1
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2
build-test-containers:
image: tiangolo/docker-with-compose
before_script:
- docker info
- docker-compose --version
script:
- cd tests/e2e
- docker-compose up --build -d
- sleep 30
- docker-compose run build-tools mysql -h db.test -u root -proot-password -e "SELECT 1;"
version: '3'
services:
dependency:
build:
context: .
dockerfile: Dockerfile
networks:
test-network:
aliases:
- "dependency.test"
entry-point:
build:
context: .
dockerfile: Dockerfile
depends_on:
- dependency
networks:
test-network:
aliases:
- "entry-point.test"
networks:
test-network:
FROM alpine:latest
# This container doesn't do anything besides running commands you give to it
CMD ["sleep", "10000"]
$ docker-compose --version
docker-compose version 1.21.0, build 5920eb0
$ cd docker-is-a-dick
$ docker-compose up --build -d
Creating network "docker-is-a-dick_test-network" with the default driver
Building dependency
Step 1/2 : FROM alpine:latest
latest: Pulling from library/alpine
Digest: sha256:e1871801d30885a610511c867de0d6baca7ed4e6a2573d506bbec7fd3b03873f
Status: Downloaded newer image for alpine:latest
---> 3fd9065eaf02
Step 2/2 : CMD ["sleep", "10000"]
---> Running in 1df6bf145739
Removing intermediate container 1df6bf145739
---> 51475865900e
Successfully built 51475865900e
Successfully tagged docker-is-a-dick_dependency:latest
Building entry-point
Step 1/2 : FROM alpine:latest
---> 3fd9065eaf02
Step 2/2 : CMD ["sleep", "10000"]
---> Using cache
---> 51475865900e
Successfully built 51475865900e
Successfully tagged docker-is-a-dick_entry-point:latest
Creating docker-is-a-dick_dependency_1 ...
Creating docker-is-a-dick_dependency_1 ... done
Creating docker-is-a-dick_entry-point_1 ...
Creating docker-is-a-dick_entry-point_1 ... done
$ docker-compose run entry-point ping -c 4 dependency.test
Starting docker-is-a-dick_dependency_1 ...
Starting docker-is-a-dick_dependency_1 ... done
PING dependency.test (172.19.0.2): 56 data bytes
64 bytes from 172.19.0.2: seq=0 ttl=64 time=0.087 ms
64 bytes from 172.19.0.2: seq=1 ttl=64 time=0.046 ms
64 bytes from 172.19.0.2: seq=2 ttl=64 time=0.036 ms
64 bytes from 172.19.0.2: seq=3 ttl=64 time=0.037 ms
--- dependency.test ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 0.036/0.051/0.087 ms
Job succeeded
@webmutation

This comment has been minimized.

Copy link

@webmutation webmutation commented Aug 1, 2019

are you having problems connecting to docker-compose container in gitlab ci ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment