DockerSwarm内部IP测试

1 创建docker 服务

docker service create --name web --publish 80:80 --replicas 3 10.128.222.245:5000/nginx

2 查看服务状态

docker@manager:~$ docker service ps web 
ID                  NAME                IMAGE                              NODE                DESIRED STATE       CURRENT STATE           ERROR               PORTS
l2tse8a3xf3a        web.1               10.128.222.245:5000/nginx:latest   worker1             Running             Running 6 minutes ago                       
orywlpaw5oo8        web.2               10.128.222.245:5000/nginx:latest   worker2             Running             Running 6 minutes ago                       
xfrtfthr0ueo        web.3               10.128.222.245:5000/nginx:latest   manager             Running             Running 6 minutes ago  

3 查看容器内部ip

docker@manager:~$ docker ps
CONTAINER ID        IMAGE                                      COMMAND                  CREATED             STATUS              PORTS                NAMES
57b20d3c0320        10.128.222.245:5000/nginx:latest           "nginx -g 'daemon ..."   7 minutes ago       Up 7 minutes        80/tcp               web.3.xfrtfthr0ueosa2bsli9hpvw3
1b50dab07f71        10.128.222.245:5000/nginx                  "nginx -g 'daemon ..."   28 minutes ago      Up 28 minutes       0.0.0.0:80->80/tcp   web
33c1b449f4a6        10.128.222.245:5000/eureka-server:latest   "java -Djava.secur..."   33 minutes ago      Up 33 minutes                            eureka-server.1.4hc3n110ciwtisd388yxuk423
docker@manager:~$ docker inspect web.3.xfrtfthr0ueosa2bsli9hpvw3
 "Networks": {
                "ingress": {
                    "IPAMConfig": {
                        "IPv4Address": "192.168.1.16"
                    },
                    *
                    *
                    *
   "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "7e148d81df78986733a57f5f93075f2937f93ad70592091c0b13f5615b9b6e80",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "80/tcp": null
            },
docker@manager:~$ docker port web.3.xfrtfthr0ueosa2bsli9hpvw3 
docker@manager:~$ 

通过inspect命令能够看到节点上的80端口,但是通过docker port 无法查看到任何端口映射

docker@manager:~$ docker port --help

Usage:	docker port CONTAINER [PRIVATE_PORT[/PROTO]]

List port mappings or a specific mapping for the container

Options:
      --help   Print usage

服务发布在默认的overlay网络(ingress)上,该网络节点之间能够互相通信,但是无法解析容器名。自定义overlay网络支持将容器名解析成ip(Docker DNS)

Containers connected to the default bridge network can communicate with each other by IP address. Docker does not support automatic service discovery on the default bridge network. If you want containers to be able to resolve IP addresses by container name, you should use user-defined networks instead. You can link two containers together using the legacy docker run --link option, but this is not recommended in most cases.

参考链接:https://docs.docker.com/engine/userguide/networking/#user-defined-networks

结论:Swam服务能够通过主机10.128.223.234(235,236):80端口访问web服务,无法通过集群的内部ip访问web服务。默认overlay网络支持跨节点访问

你可能感兴趣的:(Docker,DockerSwarm)