python - Compose 文件 '.\docker-compose.yml' 无效,因为:顶级属性“db”无效
问题描述
我的 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.
我的 docker-compose.yml 文件有问题。主要是那个部分” 指定支持的版本(例如“2.2”或“3.3”)并将您的服务定义放在services
键下,或者省略version
键并将您的服务定义放在文件的根目录以使用版本 1。关于 Compose 文件格式版本,请参阅https://docs.docker.com/compose/compose-file/"。请帮助进行更改以使其正常工作。谢谢
解决方案
推荐阅读
- google-tag-manager - 动态产品列表 GTM 标记删除空产品
- angularjs - AngularJS - 表单上的 ng-pattern 对于某些特殊符号(如美元符号)失败
- javascript - Javascript点击事件停止锚href链接
- javascript - 使用 Video.js 预览有关更改输入文件的视频
- javascript - 当另一个元素动态应用类时更改元素的样式
- php - mySQL > 限制相同数量的返回值
- hybris - 如何知道 Hybris 中现有扩展的模板名称
- angular - NativeScript Google Maps SDK - 标记随机跳跃 W/多个 MapViews
- java - RCP 应用程序中的通知小部件
- javascript - For循环 - 如何引用状态中的对象?