andyandy
andyandy

Reputation: 1624

docker-compose.yml invalid: app.build contains an invalid type, it should be a string

Running $ docker-compose up when I have my docker-compose.yml as the following, everything works as expected:

app:
  build: . 

However when I have docker-compose.yml as (which appears to valid within the docker-compose reference):

app:
  build:
    context: .

I get the following error:

$ docker-compose up
ERROR: The Compose file './docker-compose.yml' is invalid because:
app.build contains an invalid type, it should be a string

I've also tried context: "." with no joy. Please help! Many thanks.

Upvotes: 28

Views: 29637

Answers (3)

BenKoshy
BenKoshy

Reputation: 35595

A picture will better show the right way.

The Wrong Way

the wrong version

The Right Way

  • Delete the dashes

the right way

Credit:

Upvotes: 1

F.M.F.
F.M.F.

Reputation: 2292

I got this error when I accidentally used dashes before my build entries (incorrect):

  build:
      - context: ../crafter
      - dockerfile: Dockerfile

However, correct would be (without the dashes):

  build:
      context: ../crafter
      dockerfile: Dockerfile

Upvotes: 3

six8
six8

Reputation: 2990

The format you're using is for Version 2. You're currently using Version 1 format.

For Version 1, Docker Compose expects a string:

app:
  build: .

For Version 2, Docker Compose expects a string or object, but you must specify that your Docker Compose file is Version 2:

version: '2'
services:
  app:
    build:
      context: .

Upvotes: 40

Related Questions