The best choice for running docker-compose inside docker in docker is using the docker/compose image as bellow:
job-x:
image: docker/compose
script:
- docker-compose version
A real and full example of this is using docker-compose to deploy with specific installed runner on a server as bellow:
image: docker:stable
services:
- docker:dind
stages:
- build
- deploy
before_script:
# resolve TAG
# Default branch leaves tag latest
# All other branches are tagged with the escaped branch name (commit ref slug)
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
TAG="latest"
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = '$TAG'"
else
TAG="$CI_COMMIT_REF_SLUG"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $TAG"
fi
docker-build:
stage: build
script:
- echo "user ${CI_REGISTRY_USER}"
- echo "registry ${CI_REGISTRY}"
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from "$CI_REGISTRY_IMAGE:${TAG}" -t "$CI_REGISTRY_IMAGE:${TAG}" .
- docker push "$CI_REGISTRY_IMAGE:${TAG}"
when: manual
deploy-staging:
image: docker/compose
stage: deploy
variables:
IMAGE: $CI_REGISTRY_IMAGE
TAG: $TAG
HOST_PORT: $HOST_PORT
script:
- docker-compose version
- docker-compose -f docker-compose.yml up -d --no-build
when: manual
The docker-compose.yml file seems like:
version: "3.7"
services:
web:
image: $IMAGE:$TAG
build:
context: .
ports:
- $HOST_PORT:8000
pip install docker-compose
throwserror: command 'gcc' failed with exit status 1
– Bewail