Sollosa
Sollosa

Reputation: 431

What does following error in docker-compose mean while building for Django?

Below is docker-compose.yml file

docker-compose.yml

services:

 db:
  container_name: djangy-db
  image: postgres

 app:
  container_name: djangy-app
  build:
   context: ./
  command: python manage.py runserver 0.0.0.0:8000
  volumes:
   - ./app:/app
  ports:
   - "8000:8000"
  links:
   - db

and when I run

docker-compose up

I get the following error.

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

Upvotes: 0

Views: 55

Answers (1)

BMitch
BMitch

Reputation: 263469

Without a version in the compose file, docker-compose will default to the version 1 syntax which defines the services at the top level. As a result, it is creating a service named "services" with options "db" and "app", neither of which are valid in the v1 compose file syntax. As the first line, include:

version: '2'

I'm not using the version 3 syntax because you are using build in your compose file, which doesn't work in swarm mode. Links are also being deprecated and you should switch to using docker networks (provided by default with version 2 and higher of the compose file). The resulting file will look like:

version: '2'
services:

 db:
  container_name: djangy-db
  image: postgres

 app:
  container_name: djangy-app
  build:
   context: ./
  command: python manage.py runserver 0.0.0.0:8000
  volumes:
   - ./app:/app
  ports:
   - "8000:8000"

Upvotes: 1

Related Questions