我可以创建一个只创建网络的docker-compose.yaml吗?

我可以创建一个只创建网络的docker-compose.yaml吗?,docker,docker-compose,Docker,Docker Compose,我有一组docker compose文件,用于创建服务和自定义网络。一些撰写文件引用其他文件中的网络 例如: 这个组合文件创建了两个服务和两个网络 现在我有了另一个compose文件,它也使用了这些网络中的一个,并创建了另一个自己的网络: version: '3' services: (...) networks: home: external: name: my_other_service_home iot: driver:

我有一组docker compose文件,用于创建服务和自定义网络。一些撰写文件引用其他文件中的网络

例如:

这个组合文件创建了两个服务和两个网络

现在我有了另一个compose文件,它也使用了这些网络中的一个,并创建了另一个自己的网络:

version: '3'
services:
  (...)

networks:
  home:
    external:
      name:               my_other_service_home
  iot:
    driver: macvlan
    driver_opts:
      parent: enp1s0.12
    ipam:
      config:
      - subnet: 192.168.12.0/24

为了清晰起见,我更愿意在一个单独的文件中创建所有网络。然后在其他compose文件中将它们命名为外部网络

但这并不奏效:

version: '2'

networks:
  iot:
    driver: macvlan
    driver_opts:
      parent: enp1s0.12
    ipam:
      config:
      - subnet: 192.168.12.0/24
  management:
    driver: macvlan
    driver_opts:
      parent: enp1s0.10
    ipam:
      config:
      - subnet: 192.168.10.0/24
  home:
    driver: macvlan
    driver_opts:
      parent: enp1s0
    ipam:
      config:
      - subnet: 192.168.3.0/24
        gateway: 192.168.3.1
该文件被无误地接受了,但我只是得到一条信息,即网络没有被使用,因此没有被创建


有更好的办法吗

在您的
networks.yml
文件中创建一个虚拟服务怎么样,它什么都不做,并且立即退出

大致如下:

创建网络 创建服务 执行
version: '2'

networks:
  iot:
    driver: macvlan
    driver_opts:
      parent: enp1s0.12
    ipam:
      config:
      - subnet: 192.168.12.0/24
  management:
    driver: macvlan
    driver_opts:
      parent: enp1s0.10
    ipam:
      config:
      - subnet: 192.168.10.0/24
  home:
    driver: macvlan
    driver_opts:
      parent: enp1s0
    ipam:
      config:
      - subnet: 192.168.3.0/24
        gateway: 192.168.3.1
# networks.yml
version: '3.7'

services:
  dummy:
    image: alpine
    networks: [hello, sky]

networks:
  sky:
    name: skynet

  hello:
    name: hellonet
# service.yml
version: '3.7'

services:
  service:
    image: alpine
    networks: [sky]

networks:
  sky:
    external:
      name: skynet
$ docker-compose -f networks.yml up
$ docker-compose -f service.yml up