# Using docker-compose
# Build image
You can also use docker-compose
for defining and running multi-container. The example below show how you can use docker-compose
for our demo project.
jobs:
- name: Docker in Docker
stage: test
image: docker:20.10.17
services:
- docker:20.10.17-dind
before_script:
- apk add docker-compose
script:
- cp .env.example .env
- docker-compose up -d
- docker-compose exec -T app composer install
- docker-compose exec -T app php artisan key:generate
- docker-compose exec -T app php artisan migrate
- docker-compose exec -T app ./vendor/bin/phpunit
First things first, you need to install docker-compose
into your container. Then you can manage your container with docker-compose
command. Our example is just create containers for php, redis, postgres and test connection between them.
The most important thing you need to know when mounting directory in container is you must add or copy files when building image. If you use volumes
in docker-compose.yml
, nothing will be mounted because any volumes that are mounted in the "docker-in-docker" case is still referenced from the HOST, and not from the container. Therefore, the actual path mounted from the CI container "does not exist" in the HOST.