compose: [BUG] service is required by service but is disabled

Description

v2.19.0 introduced a change that broke a docker compose run command that was working previously (v2.18.1)

The change, I believe, would have come from this PR: https://github.com/docker/compose/pull/10602

docker compose -p unique_name run --rm --no-deps test black --line-length 150 --check app/ tests/

Error: service postgres is required by test but is disabled. Can be enabled by profiles []

I believe this is roughly all that would be required to reproduce, but I haven’t directly tested this as docker mac hasn’t updated docker compose yet:

version: "3"
services:
  test:
    profiles:
      - test
    build:
      context: .
    depends_on:
      postgres

  postgres:
    image: postgres:14-alpine

Steps To Reproduce

No response

Compose Version

v2.19.0

Docker Environment

No response

Anything else?

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 25
  • Comments: 22 (1 by maintainers)

Commits related to this issue

Most upvoted comments

I think the issue is still present on version 2.20.2.

I can confirm that the version v2.18.1 works while 2.19.0 shows the issue. Going back to the older version for CI as suggested by @allanlewis solves the issue.

I’m working around this by adding these steps to my failing job:

    - name: Log Docker Compose version
      run: docker compose version
    - name: Ensure Docker CLI plugins directory exists
      run: mkdir -pv "${HOME}"/.docker/cli-plugins
    - name: Download working version of Docker Compose
      run: wget -nv -O "${HOME}"/.docker/cli-plugins/docker-compose "${DOCKER_COMPOSE_URL}"
      env:
        DOCKER_COMPOSE_URL: https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-linux-x86_64
    - name: Make Docker Compose binary executable
      run: chmod -v +x "${HOME}"/.docker/cli-plugins/docker-compose
    - name: Assert that the version of Docker Compose is as expected
      run: set -o pipefail && docker compose version | tee /dev/stderr | grep -q 'v2\.18\.1$'

It seems to work, and the download is very fast, presumably because it’s all within GitHub.

I’m having this issue on version 2.19.1. Here’s my docker-compose.yaml (env vars and volumes are trimmed for simplicity):

version: "3.8"
name: "name"

services:
  pgadmin:
    container_name: pgadmin
    image: dpage/pgadmin4
    restart: always
    environment: ...
    ports:
      - 8080:80
    volumes: ...

  db:
    image: postgres:alpine
    ports:
      - 5432:5432
    environment: ...
    container_name: postgres
    volumes: ...

  api:
    build: ./api
    image: api_dev
    ports:
      - 3080:3080
    environment: ...
    container_name: api
    volumes: ...
    links:
      - db:postgres

Basically when I’m restarting the api service, I get the error message reported in the issue.

It seems like it specifically fails if the service we want to run with no deps has to be built; this repo has a consistently failing minimal project: https://github.com/luord/dc-test

The only change is from image: busybox to build: . and a Dockerfile with only FROM busybox.

On that note, a workaround that seems to work for me that doesn’t require reinstalling the previous docker version is building the image before docker run, i.e.:

docker compose build foo
docker compose run --no-deps foo

Uhm @bdashrad I don’t think this is the case, in my case the list of profiles is always empty. Furthermore, I noticed this only happens when running docker-compose restart, all other commands seem to be working as expected.

I’m hitting this issue on 2.20.2 as well