API和前端之间的Docker Swarm网络

时间:2018-09-10 16:12:56

标签: docker networking swarm

我对Docker Swarm有问题。

我已经创建了三个容器(db,back和web)。

Spring image是API REST,我想使用image web_prod(ReactJS)调用路由/用户。

在Swarm中,我有3名经理和3名工人。 所有服务(数据库,后台,Web)都已连接到网络(覆盖)编排。

我可以使用URL http://tasks.back:4000/users(与其他容器-)卷曲我的api,但是当我使用网络图像调用此地址时,没有任何结果。这个另一个容器在我的经理中运行(适当/卷曲)。

可能是集群和服务之间的问题。

检查我的服务网络:

docker@manager1:~$ docker service inspect web
[
    {
        "ID": "pfby9bxijwyopg3avz9omq7a2",
        "Version": {
            "Index": 413
        },
        "CreatedAt": "2018-09-10T13:58:26.4776156Z",
        "UpdatedAt": "2018-09-10T14:15:41.1509202Z",
        "Spec": {
            "Name": "web",
            "Labels": {},
            "TaskTemplate": {
                "ContainerSpec": {
                    "Image": "mirha/orchestration-web:0.3@sha256:b11278539b75e9ec315c3f865e70ca594d264f03abd8587262ea4496cf166f85",
                    "Env": [
                        "POSTGRES_DB=homefamily",
                        "POSTGRES_USER=postgres",
                        "POSTGRES_PASSWORD=postgres"
                    ],
                    "Init": false,
                    "StopGracePeriod": 10000000000,
                    "DNSConfig": {},
                    "Isolation": "default"
                },
                "Resources": {
                    "Limits": {},
                    "Reservations": {}
                },
                "RestartPolicy": {
                    "Condition": "any",
                    "Delay": 5000000000,
                    "MaxAttempts": 0
                },
                "Placement": {
                    "Platforms": [
                        {
                            "Architecture": "amd64",
                            "OS": "linux"
                        }
                    ]
                },
                "Networks": [
                    {
                        "Target": "cpcqcwcbxq7k6l33aa82g346m"
                    }
                ],
                "ForceUpdate": 0,
                "Runtime": "container"
            },
            "Mode": {
                "Replicated": {
                    "Replicas": 1
                }
            },
            "UpdateConfig": {
                "Parallelism": 1,
                "FailureAction": "pause",
                "Monitor": 5000000000,
                "MaxFailureRatio": 0,
                "Order": "stop-first"
            },
            "RollbackConfig": {
                "Parallelism": 1,
                "FailureAction": "pause",
                "Monitor": 5000000000,
                "MaxFailureRatio": 0,
                "Order": "stop-first"
            },
            "EndpointSpec": {
                "Mode": "vip",
                "Ports": [
                    {
                        "Protocol": "tcp",
                        "TargetPort": 3000,
                        "PublishedPort": 80,
                        "PublishMode": "ingress"
                    }
                ]
            }
        },
        "PreviousSpec": {
            "Name": "web",
            "Labels": {},
            "TaskTemplate": {
                "ContainerSpec": {
                    "Image": "mirha/orchestration-web:0.3@sha256:ead6e01788e51c9fbc31047772d380b639ea0c3e5f0b094695c5cfda2f42032c",
                    "Env": [
                        "POSTGRES_DB=homefamily",
                        "POSTGRES_USER=postgres",
                        "POSTGRES_PASSWORD=postgres"
                    ],
                    "Init": false,
                    "DNSConfig": {},
                    "Isolation": "default"
                },
                "Resources": {
                    "Limits": {},
                    "Reservations": {}
                },
                "Placement": {
                    "Platforms": [
                        {
                            "Architecture": "amd64",
                            "OS": "linux"
                        }
                    ]
                },
                "Networks": [
                    {
                        "Target": "cpcqcwcbxq7k6l33aa82g346m"
                    }
                ],
                "ForceUpdate": 0,
                "Runtime": "container"
            },
            "Mode": {
                "Replicated": {
                    "Replicas": 1
                }
            },
            "EndpointSpec": {
                "Mode": "vip",
                "Ports": [
                    {
                        "Protocol": "tcp",
                        "TargetPort": 3000,
                        "PublishedPort": 80,
                        "PublishMode": "ingress"
                    }
                ]
            }
        },
        "Endpoint": {
            "Spec": {
                "Mode": "vip",
                "Ports": [
                    {
                        "Protocol": "tcp",
                        "TargetPort": 3000,
                        "PublishedPort": 80,
                        "PublishMode": "ingress"
                    }
                ]
            },
            "Ports": [
                {
                    "Protocol": "tcp",
                    "TargetPort": 3000,
                    "PublishedPort": 80,
                    "PublishMode": "ingress"
                }
            ],
            "VirtualIPs": [
                {
                    "NetworkID": "w09wuwh6tt8bnlf6bsvtb0idq",
                    "Addr": "10.0.0.10/24"
                },
                {
                    "NetworkID": "cpcqcwcbxq7k6l33aa82g346m",
                    "Addr": "10.0.2.17/24"
                }
            ]
        },
        "UpdateStatus": {
            "State": "completed",
            "StartedAt": "2018-09-10T14:11:51.1926981Z",
            "CompletedAt": "2018-09-10T14:15:41.1509088Z",
            "Message": "update completed"
        }
    }
]

检查我的背部

[
    {
        "ID": "uiesfpo3usn9z01cel30no930",
        "Version": {
            "Index": 463
        },
        "CreatedAt": "2018-09-10T12:49:03.0005436Z",
        "UpdatedAt": "2018-09-10T15:19:38.1407773Z",
        "Spec": {
            "Name": "back",
            "Labels": {},
            "TaskTemplate": {
                "ContainerSpec": {
                    "Image": "mirha/spring:5@sha256:ec12cc9cbff861656313f8835976d841204bea54bc8096d3346166c26fdcddaf",
                    "Hostname": "back.api",
                    "Env": [
                        "POSTGRES_DB=homefamily",
                        "POSTGRES_USER=postgres",
                        "POSTGRES_PASSWORD=postgres"
                    ],
                    "Init": false,
                    "StopGracePeriod": 10000000000,
                    "DNSConfig": {},
                    "Isolation": "default"
                },
                "Resources": {
                    "Limits": {},
                    "Reservations": {}
                },
                "RestartPolicy": {
                    "Condition": "any",
                    "Delay": 5000000000,
                    "MaxAttempts": 0
                },
                "Placement": {
                    "Platforms": [
                        {
                            "Architecture": "amd64",
                            "OS": "linux"
                        }
                    ]
                },
                "Networks": [
                    {
                        "Target": "cpcqcwcbxq7k6l33aa82g346m"
                    }
                ],
                "ForceUpdate": 0,
                "Runtime": "container"
            },
            "Mode": {
                "Replicated": {
                    "Replicas": 1
                }
            },
            "UpdateConfig": {
                "Parallelism": 1,
                "FailureAction": "pause",
                "Monitor": 5000000000,
                "MaxFailureRatio": 0,
                "Order": "stop-first"
            },
            "RollbackConfig": {
                "Parallelism": 1,
                "FailureAction": "pause",
                "Monitor": 5000000000,
                "MaxFailureRatio": 0,
                "Order": "stop-first"
            },
            "EndpointSpec": {
                "Mode": "vip",
                "Ports": [
                    {
                        "Protocol": "tcp",
                        "TargetPort": 4000,
                        "PublishedPort": 4000,
                        "PublishMode": "ingress"
                    }
                ]
            }
        },
        "PreviousSpec": {
            "Name": "back",
            "Labels": {},
            "TaskTemplate": {
                "ContainerSpec": {
                    "Image": "mirha/spring:5@sha256:ec12cc9cbff861656313f8835976d841204bea54bc8096d3346166c26fdcddaf",
                    "Hostname": "back.api",
                    "Env": [
                        "POSTGRES_DB=homefamily",
                        "POSTGRES_USER=postgres",
                        "POSTGRES_PASSWORD=postgres"
                    ],
                    "Init": false,
                    "DNSConfig": {},
                    "Isolation": "default"
                },
                "Resources": {
                    "Limits": {},
                    "Reservations": {}
                },
                "Placement": {
                    "Platforms": [
                        {
                            "Architecture": "amd64",
                            "OS": "linux"
                        }
                    ]
                },
                "Networks": [
                    {
                        "Target": "cpcqcwcbxq7k6l33aa82g346m"
                    }
                ],
                "ForceUpdate": 0,
                "Runtime": "container"
            },
            "Mode": {
                "Replicated": {
                    "Replicas": 1
                }
            },
            "EndpointSpec": {
                "Mode": "vip"
            }
        },
        "Endpoint": {
            "Spec": {
                "Mode": "vip",
                "Ports": [
                    {
                        "Protocol": "tcp",
                        "TargetPort": 4000,
                        "PublishedPort": 4000,
                        "PublishMode": "ingress"
                    }
                ]
            },
            "Ports": [
                {
                    "Protocol": "tcp",
                    "TargetPort": 4000,
                    "PublishedPort": 4000,
                    "PublishMode": "ingress"
                }
            ],
            "VirtualIPs": [
                {
                    "NetworkID": "cpcqcwcbxq7k6l33aa82g346m",
                    "Addr": "10.0.2.10/24"
                },
                {
                    "NetworkID": "w09wuwh6tt8bnlf6bsvtb0idq",
                    "Addr": "10.0.0.13/24"
                }
            ]
        },
        "UpdateStatus": {
            "State": "completed",
            "StartedAt": "2018-09-10T15:19:29.0789613Z",
            "CompletedAt": "2018-09-10T15:19:38.1407656Z",
            "Message": "update completed"
        }
    }
]

在同一网络上的其他容器中出现:

docker@manager1:~$ docker run --rm -it --net=orchestration --name curl appropriate/curl http://tasks.back:4000/application

{"ip":"10.0.2.29","name":"back.api","id":null,"version":null}

如果您对此有个想法(当我在浏览器中通过图像网络调用api时没有结果) 我尝试使用管理器(192.168.25.80:4000),本地主机,图像名称等IP地址...

谢谢

0 个答案:

没有答案