如何修复我的 docker-compose.yml?- 不支持的服务配置选项:'database'



我今天是第一次。我一整天都在想问题出在哪里。

docker-compose version 1.28.5, build 324b023a

我运行:Docker-compose up -d

得到:错误:撰写文件'./docker-撰写。Yml '无效,因为:不支持的服务配置选项。teslamate:"数据库">

version: "3"
services:
teslamate:
image: teslamate/teslamate
restart: always
environment:
- ENCRYPTION_KEY= <Insert Key>
- DB_USER=teslamate
- DB_PASS= <Insert password>
- DB_NAME=teslamate
- DB_HOST=database
- MQTT_HOST=mosquitto
- VIRTUAL_HOST=<Insert IP address>
# if you're going to access the UI from another machine replace
# "localhost" with the hostname / IP address of the docker host.
- TZ=US # (optional) replace to use local time in debug logs. See    "Configuration".
ports:
- 4000:4000
volumes:
- ./import:/opt/app/import
cap_drop:
- all
database:
image: postgres:14
restart: always
environment:
- POSTGRES_USER=teslamate
- POSTGRES_PASSWORD= <Insert password>
- POSTGRES_DB=teslamate
volumes:
- teslamate-db:/var/lib/postgresql/data
grafana:
image: teslamate/grafana
restart: always
environment:
- DATABASE_USER=teslamate
- DATABASE_PASS= goforit
- DATABASE_NAME=teslamate
- DATABASE_HOST=database
ports:
- 3000:3000
volumes:
- teslamate-grafana-data:/var/lib/grafana
mosquitto:
image: eclipse-mosquitto:2
restart: always
command: mosquitto -c /mosquitto-no-auth.conf
# ports:
#   - 1883:1883
volumes:
- mosquitto-conf:/mosquitto/config
- mosquitto-data:/mosquitto/data
volumes:
teslamate-db:
teslamate-grafana-data:
mosquitto-conf:
mosquitto-data:

谁能告诉我出了什么事?谢谢你,

这只是一个html缩进问题。你的服务teslamate、database、grafana和mosquito需要有相同的缩进,否则database会被视为teslamate的属性,而不是docker-compose的有效属性。

version: "3"
services:
teslamate:
image: teslamate/teslamate
restart: always
environment:
- ENCRYPTION_KEY= <Insert Key>
- DB_USER=teslamate
- DB_PASS= <Insert password>
- DB_NAME=teslamate
- DB_HOST=database
- MQTT_HOST=mosquitto
- VIRTUAL_HOST=<Insert IP address>
# if you're going to access the UI from another machine replace
# "localhost" with the hostname / IP address of the docker host.
- TZ=US # (optional) replace to use local time in debug logs. See    "Configuration".
ports:
- 4000:4000
volumes:
- ./import:/opt/app/import
cap_drop:
- all
database:
image: postgres:14
restart: always
environment:
- POSTGRES_USER=teslamate
- POSTGRES_PASSWORD= <Insert password>
- POSTGRES_DB=teslamate
volumes:
- teslamate-db:/var/lib/postgresql/data
grafana:
image: teslamate/grafana
restart: always
environment:
- DATABASE_USER=teslamate
- DATABASE_PASS= goforit
- DATABASE_NAME=teslamate
- DATABASE_HOST=database
ports:
- 3000:3000
volumes:
- teslamate-grafana-data:/var/lib/grafana
mosquitto:
image: eclipse-mosquitto:2
restart: always
command: mosquitto -c /mosquitto-no-auth.conf
# ports:
#   - 1883:1883
volumes:
- mosquitto-conf:/mosquitto/config
- mosquitto-data:/mosquitto/data
volumes:
teslamate-db:
teslamate-grafana-data:
mosquitto-conf:
mosquitto-data: