docker 对接器-组成,yml-yaml:找不到预期的':'

bn31dyow  于 2022-12-03  发布在  Docker
关注(0)|答案(2)|浏览(325)

我正在尝试按照本指南从0创建一个docker-compose.yml文件。
当我尝试运行容器时,出现以下错误:yaml: line 29: could not find expected ':'
我已经阅读了所有地方,我发现缩进的问题,但我还没能告诉为什么我的文件不会运行,任何帮助将是非常感激.我的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
# More Info on how to use this: https://github.com/htpcBeginner/docker-traefik/pull/228

# 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'

我已经尝试检查缩进,并更改一些环境变量定义,例如:TZ: $TZ- TZ=$TZ

w6mmgewl

w6mmgewl1#

在我的VSCode上,您的代码显示了29个错误。
这里是一个没有的版本,请尝试会发生什么:

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
# More Info on how to use this: https://github.com/htpcBeginner/docker-traefik/pull/228

# 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'
olhwl3o2

olhwl3o22#

好的!我发现了问题所在,因为我是按照指南发布的,它有代码块,你可以复制/粘贴部分的docker-compose文件。
我使用nano修改文件使用SSH连接到我的家庭服务器,我越来越厌倦使用,所以我粘贴我的代码在VSCode上,发现一些空白的地方不是空格,但U+00 a0字符,我只是用查找和替换工具将此字符更改为空格字符,它的工作!
感谢大家的快速回复

相关问题