docker network

Network

查看网络,容器的默认网络为bridge:

docker network ls

NETWORK ID          NAME                DRIVER              SCOPE
683676f81e6d        bridge              bridge              local               
7dbfac5ee958        harbor_harbor       bridge              local               
bf582c40ad25        host                host                local               
c4e4ab511320        none                null                local

inspect网络可以查看关联到该网络的容器:

docker network inspect harbor_harbor

[
    {
        "Name": "harbor_harbor",
        "Id": "7dbfac5ee958d153ee40a888f9483b994112ae708559bd0d029d035e0b45f497",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1/16"
                }
            ]
        },
        "Internal": false,
        "Containers": {
            "1ca0273ab2d44d3a41c27a9764b00f0e0cf8f332870c9170cdedaa556622b224": {
                "Name": "harbor-adminserver",
                "EndpointID": "018091344e074157901028849094611fb5978bd76fc5677b209cd50d2d3f53ed",
                "MacAddress": "02:42:ac:12:00:04",
                "IPv4Address": "172.18.0.4/16",
                "IPv6Address": ""
            },
            "2639d67fb2d4d43042c6fa1634388f2d8c09a5dbcc85497b3d6c672f0dac966e": {
                "Name": "registry",
                "EndpointID": "e2f43c0e8f053160dcf980411b72bc149ad0f165a01942e7de29e107a48cadcd",
                "MacAddress": "02:42:ac:12:00:03",
                "IPv4Address": "172.18.0.3/16",
                "IPv6Address": ""
            },
            "274f318ca94e9707daac9d6018636a6deeec99f5d96ffe1e0a2762ce88957d30": {
                "Name": "harbor-jobservice",
                "EndpointID": "574ed4ed028ae2f87b5ae74e34fb9e2a4ad0b66b9f828a5edd75590845b28b0a",
                "MacAddress": "02:42:ac:12:00:08",
                "IPv4Address": "172.18.0.8/16",
                "IPv6Address": ""
            },
            "44ea00bd66cebd183c32cf5e8c90b14c07c3d0aab0616044acf0f060d1ab9276": {
                "Name": "harbor-ui",
                "EndpointID": "52cfe368001242e7301632dea18b4c958e41f7bcf1fdb9d5f08cd03f908c8d25",
                "MacAddress": "02:42:ac:12:00:06",
                "IPv4Address": "172.18.0.6/16",
                "IPv6Address": ""
            },
            "70d26e6018d293175df83de3fd6cc478f61c8e4b89dbdf785806628ceff6957c": {
                "Name": "harbor-db",
                "EndpointID": "44d1ecba79c8a2a87c35aad72d99d0459e9de865c13242c7b5c96ff6cba0a96f",
                "MacAddress": "02:42:ac:12:00:05",
                "IPv4Address": "172.18.0.5/16",
                "IPv6Address": ""
            },
            "95688a89a3ec8458f275ba33c0cb0f508d744ffd86db545562c3bb5c6fab3d0c": {
                "Name": "harbor-log",
                "EndpointID": "8860dc76860a5579f622dd0ecf5cb896d7e631cb57d5af51860647cdaa8bafae",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            },
            "ef7a58746d0dd8493a6d2d2a1692be0b0623046898696a10955a16ff7a218578": {
                "Name": "nginx",
                "EndpointID": "f48a79303a9244d141eef6c0cfb6d973e2e240dfcbeb3af0189ffc371c7ad4ee",
                "MacAddress": "02:42:ac:12:00:07",
                "IPv4Address": "172.18.0.7/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

另一种查看的方式

docker inspect --format='{{json .NetworkSettings.Networks}}'  db

剔除网络中的一个容器:

docker network disconnect harbor_harbor nginx

创建自己的网络:

docker network create -d bridge my_bridge

在run的时候指定网络:

docker run -d --net=my_bridge --name db training/postgres

连接已经存在的容器:

docker network connect my_bridge web

在同一网络中允许直接将容器的名称作为host名称。

你可能感兴趣的:(docker network)