docker-compose版本3语法

时间:2018-11-03 14:08:36

标签: docker docker-compose qnap

我正在从网络上的各种docker-compose示例构建docker容器堆栈,并且不断遇到尝试在docker-compose文件版本之间“转换”的麻烦。

在此讨论中,我试图“转换” QNAP容器站Qnet网络驱动程序示例[1]:

version: '2'
services:
  qnet_dhcp:
    image: alpine
    command: ifconfig eth0
    networks:
      - qnet-dhcp

  qnet_static:
    image: alpine
    command: ifconfig eth0
    networks:
      qnet-static:
        ipv4_address: 192.168.80.119

networks:
  qnet-dhcp:
    driver: qnet
    ipam:
      driver: qnet
      options:
        iface: "eth0"

  qnet-static:
    driver: qnet
    ipam:
      driver: qnet
      options:
        iface: "eth0"
      config:
        - subnet: 192.168.80.0/23
          gateway: 192.168.80.254

我已经做到了这一点(我无法上班的qnet-static部分):

version: "3"
services:
  qnet_dhcp:
    image: alpine
    command: ifconfig eth0
    networks:
      - qnet-dhcp

networks:
  qnet-dhcp:
    driver: qnet
    driver_opts:
        iface: "eth0"

此“编译”但在运行它(在QNAP TVS-1282T上)时出现错误:

[/share/data/appdata] # docker-compose up -d
Creating network "appdata_qnet-dhcp" with driver "qnet"
Creating appdata_qnet_dhcp_1 ... error

ERROR: for appdata_qnet_dhcp_1  Cannot start service qnet_dhcp: failed to create endpoint appdata_qnet_dhcp_1 owork appdata_qnet-dhcp: NetworkDriver.CreateEndpoint: invalid literal for int() with base 16: ''

ERROR: for qnet_dhcp  Cannot start service qnet_dhcp: failed to create endpoint appdata_qnet_dhcp_1 on network ta_qnet-dhcp: NetworkDriver.CreateEndpoint: invalid literal for int() with base 16: ''
ERROR: Encountered errors while bringing up the project.

有人可以澄清与此示例相关的docker-compose文件版本2和版本3之间的更改吗?

[1] https://qnap-dev.github.io/container-station-api/qnet.html#docker-compose

2 个答案:

答案 0 :(得分:0)

我有一个类似的问题,暂时,我使用了以下解决方法。

  1. 我手动创建网络:

    docker network create -d qnet --ipam-driver = qnet --ipam-opt = iface = bond0 qnet-dhcp

  2. 然后像下面这样在我的docker-compose文件中使用它:

networks: qnet-dhcp: external: name: qnet-dhcp

答案 1 :(得分:0)

我仅通过对docker-compose.yml使用版本“ 2.4”来解决了这个问题:

version: "2.4"
services:
  qnet_dhcp:
    image: alpine
    command: ifconfig eth0
    mac_address: 02:42:ac:11:65:43 # you can even set a mac address!
    mem_limit: 512000000 # memory limit to 512mb
    cpus: 0.5
    networks:
      - qnet-dhcp

networks:
  qnet-dhcp:
    driver: qnet
    ipam:
      driver: qnet
      options:
        iface: "eth0"

在大多数情况下,很容易将版本“ 3”改回版本“ 2.4”。它在我的QNAP上运行完美。通过设置mac地址,我的fritz框将为容器提供始终相同的ip地址。