1、新建网络
$ sudo docker network create --driver bridge --subnet=172.18.12.0/16 --gateway=172.18.1.1 mynet
1d394e30e6fb5dfe3d5b7429d203380777f5be8d92ab21db79ec90389a1f72b0
列出网络
$ sudo docker network list
NETWORK ID NAME DRIVER SCOPE
5ba142af9c4b bridge bridge local
761402dc22b5 host host local
1d394e30e6fb mynet bridge local
0b54d8192b87 none null local
查看网络信息
$ sudo docker network inspect mynet
[
{
"Name": "mynet",
"Id": "1d394e30e6fb5dfe3d5b7429d203380777f5be8d92ab21db79ec90389a1f72b0",
"Created": "2019-05-10T16:16:04.780755336+08:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.18.12.0/16",
"Gateway": "172.18.1.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {},
"Labels": {}
}
]
2、启动容器定义网络
$ sudo docker run -itd --name testserver --network=mynet --ip 172.18.12.1 -p 8080:8080 -v /data/webApps/testserver/logs:/logs -v /data/webApps/testserver/attachFiles:/attachFiles --name testserver testserver:1.0
查看容器网络地址
$ sudo docker inspect ContainerID | grep "IPAddress\":