1

My idea is to have a single docker-compose file that I can configure with --profile db_as_container flag depending on whether I want to have cloud database (MongoDB atlas) or local database-as-container.

Here's my docker-compose.yml:

version: '3'

services:
    app:
        image: '${APP_NAME}:${TAG:-latest}'
        build: .
        ports:
            - '${PORT}:${PORT}'

    mongo_db:
        image: mongo
        container_name: mongo_db_container
        ports:
            - "27017:27017"
        profiles:
            - db_as_container

My docker compose up shell script (dc-up.sh) deduces whether my DB_CONNECTION_STRING is cloud type or local container type and calls appropriate up command.

TAG=${TAG} docker-compose --profile db_as_container up -d --build

vs.

TAG=${TAG} docker-compose up -d --build

And this works locally and does not complain about using profiles.

Problem is when my Gitlab CI runner runs my build script (build-and-push.sh):

TAG=${TAG} docker-compose build

It produces this error:

The Compose file './docker-compose.yml' is invalid because: Unsupported config option for services.mongo_db: 'profiles'

What am I doing wrong here?

2 Answers 2

3

Actually the issue was not the version of the compose file specification, but rather docker-compose itself as i've found out here

Support for service profiles was added in docker-compose version 1.28

Updating from 1.262 to 1.28.6 solved my issue.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh, yeah. I should have seen that your compose file was in version 3. Anyway, good job 👏
1

Only Docker Compose v3 has profiles option. I'm guessing your CI compose version is a lower one.

You will need to upgrade it to version 3.

1 Comment

When checking locally with docker-compose --version, it prints out: docker-compose version 1.29.0, build 07737305. So my question would be, what is the difference between docker-compose CLI version and docker-compose file specification (which i have in my file set to 3)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.