我正在从网络上的各种docker compose示例构建我的docker容器堆栈,我在尝试在docker composed文件版本之间"转换"时经常遇到麻烦。
在这个讨论中,我试图"转换"QNAP Container station 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静态部分(:
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-组成
我遇到了类似的问题,目前我使用了以下解决方法。
-
我手动创建网络:
docker network create-d qnet--ipam driver=qnet--ipam opt=iface=bond0 qnet dhcp
-
然后在我的docker撰写文件中使用它,如下所示:
networks:
qnet-dhcp:
external:
name: qnet-dhcp
我只使用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地址。