Docker网络连通

Docker网络联通

docker0怎么打通自定义网络呢?--核心命令 docker network connect

# 查看正在运行的镜像
docker ps
CONTAINER ID   IMAGE     COMMAND             CREATED          STATUS          PORTS                                         NAMES
897a4b76472d   tomcat    "catalina.sh run"   5 seconds ago    Up 2 seconds    0.0.0.0:55004->8080/tcp, :::55004->8080/tcp   tomcat02
5f2584795e0b   tomcat    "catalina.sh run"   10 seconds ago   Up 8 seconds    0.0.0.0:55003->8080/tcp, :::55003->8080/tcp   tomcat01
283b394949d0   tomcat    "catalina.sh run"   14 minutes ago   Up 14 minutes   0.0.0.0:55002->8080/tcp, :::55002->8080/tcp   tomcat-net-02
d18bedc300d7   tomcat    "catalina.sh run"   14 minutes ago   Up 14 minutes   0.0.0.0:55001->8080/tcp, :::55001->8080/tcp   tomcat-net-01

# 测试下tomcat01(docker0)是否能ping通tomcat-net-01(自定义网络mynet)的
docker exec -it tomcat01 ping tomcat-net-01
ping: tomcat-net-01: Name or service not known

核心命令

docker network connect --help

Usage:  docker network connect [OPTIONS] NETWORK CONTAINER

Connect a container to a network

Options:
      --alias strings           Add network-scoped alias for the container
      --driver-opt strings      driver options for the network
      --ip string               IPv4 address (e.g., 172.30.100.104)
      --ip6 string              IPv6 address (e.g., 2001:db8::33)
      --link list               Add link to another container
      --link-local-ip strings   Add a link-local address for the container

# 联通docker0的一个容器到自定义网络
docker network connect mynet tomcat01
# 查看下自定义网络的是否有tomcat01
docker network inspect mynet
"Containers": {
            "283b394949d0230ce159e675f12f765fa6e7c9978d8103521d75da5b95ffde46": {
                "Name": "tomcat-net-02",
                "EndpointID": "784507211c5661cae82fc7461d866af69669bc440d48e821e31144b5fd4a7877",
                "MacAddress": "02:42:c0:a8:00:03",
                "IPv4Address": "192.168.0.3/16",
                "IPv6Address": ""
            },
            "5f2584795e0bb6673da5b7817cf4546f79420ef72618124def976cfff5954727": {
                "Name": "tomcat01",
                "EndpointID": "b8ab7a19aefecb187cd07291ea7eaea6e6a825d2e7d1ae1b54baa273b008c498",
                "MacAddress": "02:42:c0:a8:00:04",
                "IPv4Address": "192.168.0.4/16",
                "IPv6Address": ""
            },
            "d18bedc300d7f7f5e854875ac88594b56311bb417c223cd89f8fed02178a614e": {
                "Name": "tomcat-net-01",
                "EndpointID": "7ddc1493e42c89ef3793bdfcc273df3c8513693d342a613c670846ac2101a302",
                "MacAddress": "02:42:c0:a8:00:02",
                "IPv4Address": "192.168.0.2/16",
                "IPv6Address": ""
            }
        }

# 一个容器两个ip地址! 
上一篇:IE浏览器访问JavaWeb网址变为了搜索引擎搜索此网址


下一篇:《Linux7配置Unbound实现简单的DNS域名解析 | CSDN创作打卡》