我在主机上使用以下命令创建了Docker网络:
docker network create -d macvlan \
--subnet=192.168.2.0/24 \
--gateway=192.168.2.1 \
-o parent=eth0 pub_net
Docker 网络如下所示:
[root@192-168-2-70 shell]# docker network ls
NETWORK ID NAME DRIVER SCOPE
935ae8b52eb2 bridge bridge local
81577f72f606 host host local
846d54a2c7da none null local
158428b19c4d pub_net macvlan local
[root@192-168-2-70 shell]#
可以通过以下命令启动指定IP的Docker容器:
docker run --net=pub_net --ip=192.168.2.10 --name hadoop0 --hostname hadoop0 -d -P hadoop-cluster-hadoop0:v1.1
但是,当我将上述命令转换为docker-compose文件时,如下所示:
version: '3'
services:
hadoop-cluster-hadoop0:
container_name: hadoop0
restart: always
networks:
pub_net:
ipv4_address: 192.168.2.10
volumes:
- /tmp/hadoop0/logs:/tmp
extra_hosts:
- "hadoop0:192.168.1.10"
- "hadoop1:192.168.1.11"
- "hadoop2:192.168.1.12"
- "dbus-n1:192.168.2.81"
image: 'hadoop-cluster-hadoop0:v1.1'
networks:
put_net:
external: true
发生了以下错误。
[root@192-168-2-70 shell]# docker-compose up -d
WARNING: Some networks were defined but are not used by any service: put_net
ERROR: Service "hadoop-cluster-hadoop0" uses an undefined network "pub_net"
[root@192-168-2-70 shell]#
请问有人可以帮我纠正 Docker Compose 文件吗?如何在 Docker Compose 文件中创建 Docker 网络,而不是先前创建?
非常感谢您的帮助!!!
--subnet=192.168.2.0/24
--gateway=192.168.2.1
-o parent=eth0 pub_net - Ladenjet