撰写文件'。\ docker-compose.yml'无效,因为:无效的顶级属性“ db”

时间:2020-10-05 07:36:18

标签: python django docker docker-compose

我的docker-compose.yml文件包含

    version: '3.8'
    services:
      web:
        build: .
        command: python /code/manage.py runserver 0.0.0.0:8000
        volumes:
          - .:/code
        ports:
          - 8000:8000
        depends_on:
          - db
    db:
      image: postgres
      volumes:
        - postgres_data:/var/lib/postgresql/data/
    volumes:
      postgres_data:

Dockerfile包含

     # Pull base image
        FROM python:3.8.6
        # Set environment variables
        ENV PYTHONDONTWRITEBYTECODE 1
        ENV PYTHONUNBUFFERED 1
        # Set work directory
        WORKDIR /code
        # Install dependencies
        COPY Pipfile Pipfile.lock /code/
        RUN pip install pipenv && pipenv install --system
        # Copy project
        COPY . /code/
    
Using that command to build image and run the containers with one command

    $ docker-compose up -d --build
    

然后gitbash终端抛出该错误

     $ docker-compose up -d --build
        The Compose file '.\docker-compose.yml' is invalid because:
        Invalid top-level property "db". Valid top-level sections for this Compose file are: version, services, networks, volumes, secrets, configs, and extensions starting with "x-".
        
        You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
        For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/
    

据此,我的docker-compose.yml文件中有问题。主要是该部分”要么指定受支持的版本(例如“ 2.2”或“ 3.3”),然后将您的服务定义放在services下键,或省略version键,然后将服务定义放在文件的根目录以使用版本1。 有关Compose文件格式版本的更多信息,请参见https://docs.docker.com/compose/compose-file/"。请帮助进行更改,以使其正常工作。谢谢

[Command and Error][1]
[File 1][2]
[File 2][3]


  [1]: https://i.stack.imgur.com/VFBKb.png
  [2]: https://i.stack.imgur.com/7GWzF.png
  [3]: https://i.stack.imgur.com/TTlL4.png

0 个答案:

没有答案