d-_-b
d-_-b

Reputation: 23171

Start a single docker-compose service without validating other service options

I have a docker-compose.yml file which contains a few services.

I want to run only one service ("api") on a server, and don't have any of the mandatory directories/files that are specified in the other service ("www")

I've tried docker-compose up --no-build api, but it still warns me:

ERROR: build path /path/invalid-path either does not exist...

How can I start up a single service while ignoring or not validating the other services?

Is the only answer to create multiple docker-compose files for each scenario?

api:
    build: 
        image: api:latest
    env_file: 
      - '.env'
    volumes:
      - "./volume:/volume"
    ports:
      - "${API_PORT}:${API_PORT}"
    expose:
      - "${API_PORT}"
www:
    build:
        context: ./invalid-path <--- this does not exist on this server
    env_file:
        - '.env'
    volumes:
        - "./invalid-volume:/path"

Upvotes: 1

Views: 595

Answers (3)

DazWilkin
DazWilkin

Reputation: 40091

I think (!?) the issue is that docker-compose is attempting to validate the entire spec before running the service.

Because the validation fails, it's not permitting you to run the single service (even though this could run).

If the spec validated, you would be able to e.g. docker-compose up api.

In this case, your only solution appears to be to partition the services across separate spec files.

Upvotes: 1

Delta George
Delta George

Reputation: 4226

You could try something like this:

yq r docker-compose.yml services.api | yq p - services.api | yq w - version '"3.0"' | docker-compose -f - up

Upvotes: 1

Shashank V
Shashank V

Reputation: 11193

Entire spec is validated by docker-compose. So yes, you need to split your compose file into multiple files.

Upvotes: 1

Related Questions