docker compose 中的缩进问题

docker compose 中的缩进问题

在此处输入图片描述

ubuntuserver@ubuntu:~/Nginx-Reverse-Proxy/proxy$
ubuntuserver@ubuntu:~/Nginx-Reverse-Proxy/proxy$ cat docker-compose.yml
version: "2"

services:
  proxy:
  build:
    context: ./
  networks:
    - example1
    - example2
  ports:
    - 80:80
    - 443:443

networks:
  example1:
    external:
      name: example1_default
  example2:
    external:
      name: example2_default



ubuntuserver@ubuntu:~/Nginx-Reverse-Proxy/proxy$
ubuntuserver@ubuntu:~/Nginx-Reverse-Proxy/proxy$ docker-compose build
ERROR: In file './docker-compose.yml', service 'networks' must be a mapping not an array.
ubuntuserver@ubuntu:~/Nginx-Reverse-Proxy/proxy$

答案1

您需要将所有内容缩进proxy一个级别。否则它们会被视为不同的服务。

services:
  proxy:
    build:
      context: ./
    networks:
      - example1
      - example2
    ports:
      - 80:80
      - 443:443

相关内容