编写Docker-Compose.yml遇报错:yaml: line 29: could not find expected ':'
问题解决:Docker Compose YAML解析错误
yaml: line 29: could not find expected ':' 问题描述
从零创建docker-compose.yml文件时,运行容器出现YAML解析错误,提示行29找不到预期的冒号。尝试调整缩进、修改环境变量定义格式均未解决问题,当前yaml内容如下:
version: "3.9" ########################### NETWORKS # You may customize the network subnet (192.168.89.0/24) below as you please. # Docker Compose version 3.5 or higher required to define networks this way. networks: default: driver: bridge npm_proxy: name: npm_proxy driver: bridge ipam: config: - subnet: 192.168.89.0/24 ########################### EXTENSION FIELDS # Helps eliminate repetition of sections # Common environment values x-environment: &default-tz-puid-pgid TZ: $TZ PUID: $PUID PGID: $PGID # Keys common to some of the core services that we always to automatically restart on failure x-common-keys-core: &common-keys-core networks: - npm_proxy security_opt: - no-new-privileges:true restart: always # Keys common to some of the dependent services/apps x-common-keys-apps: &common-keys-apps networks: - npm_proxy security_opt: - no-new-privileges:true restart: unless-stopped # Keys common to some of the services in media-services.txt x-common-keys-media: &common-keys-media networks: - npm_proxy security_opt: - no-new-privileges:true restart: "no" ########################### SERVICES services: ################ FRONTENDS # Nginx Proxy Manager - Reverse Proxy with LetsEncrypt npm: <<: *common-keys-core # See EXTENSION FIELDS at the top container_name: nginx-proxy-manager image: 'jc21/nginx-proxy-manager:latest' # For Static IP networks: # For Static IP npm_proxy: ipv4_address: 192.168.89.254 # You can specify a static IP # For Dynamic IP # networks: # - npm_proxy ports: - '80:80' # Public HTTP Port. Port Forwarding on Router is ON. - '443:443' # Public HTTPS Port. Port Forwarding on Router is ON. - '81:81' # Admin Web Port. Port Forwarding on Router is OFF. Internal Home Network Access only - 192.168.89.254:81. volumes: - $DOCKERDIR/appdata/npm/config:/config - $DOCKERDIR/appdata/npm/letsencrypt:/etc/letsencrypt - $DOCKERDIR/appdata/npm/data:/data environment: DB_SQLITE_FILE: "/config/database.sqlite" DISABLE_IPV6: 'true'
错误原因
你的YAML文件中误用了HTML实体编码,而非YAML原生语法:
&需替换为&(YAML锚点标识)<<需替换为<<(YAML合并键标识)
YAML解析器无法识别这些HTML实体,因此抛出语法错误。
修复后的docker-compose.yml
version: "3.9" ########################### NETWORKS # You may customize the network subnet (192.168.89.0/24) below as you please. # Docker Compose version 3.5 or higher required to define networks this way. networks: default: driver: bridge npm_proxy: name: npm_proxy driver: bridge ipam: config: - subnet: 192.168.89.0/24 ########################### EXTENSION FIELDS # Helps eliminate repetition of sections # Common environment values x-environment: &default-tz-puid-pgid TZ: $TZ PUID: $PUID PGID: $PGID # Keys common to some of the core services that we always to automatically restart on failure x-common-keys-core: &common-keys-core networks: - npm_proxy security_opt: - no-new-privileges:true restart: always # Keys common to some of the dependent services/apps x-common-keys-apps: &common-keys-apps networks: - npm_proxy security_opt: - no-new-privileges:true restart: unless-stopped # Keys common to some of the services in media-services.txt x-common-keys-media: &common-keys-media networks: - npm_proxy security_opt: - no-new-privileges:true restart: "no" ########################### SERVICES services: ################ FRONTENDS # Nginx Proxy Manager - Reverse Proxy with LetsEncrypt npm: <<: *common-keys-core # See EXTENSION FIELDS at the top container_name: nginx-proxy-manager image: 'jc21/nginx-proxy-manager:latest' # For Static IP networks: # For Static IP npm_proxy: ipv4_address: 192.168.89.254 # You can specify a static IP # For Dynamic IP # networks: # - npm_proxy ports: - '80:80' # Public HTTP Port. Port Forwarding on Router is ON. - '443:443' # Public HTTPS Port. Port Forwarding on Router is ON. - '81:81' # Admin Web Port. Port Forwarding on Router is OFF. Internal Home Network Access only - 192.168.89.254:81. volumes: - $DOCKERDIR/appdata/npm/config:/config - $DOCKERDIR/appdata/npm/letsencrypt:/etc/letsencrypt - $DOCKERDIR/appdata/npm/data:/data environment: DB_SQLITE_FILE: "/config/database.sqlite" DISABLE_IPV6: 'true'
内容的提问来源于stack exchange,提问作者Miguel Giraldo
相关产品推荐
相关产品推荐

