Py学习  »  docker

Docker Swarm访问已发布端口上的容器?

Senica Gonzalez • 4 年前 • 1549 次点击  

我见过至少10个这样的问题,但找不到答案。

我要从牧场主搬到码头工人。

我使用docker compose部署了一个堆栈。

我正在使用linux主机。

➜  swarm git:(master) ✗ docker --version
Docker version 20.10.9, build c2ea9bc
➜  swarm git:(master) ✗ docker-compose --version
docker-compose version 1.29.2, build 5becea4c

我遇到的问题是我有一个容器(服务) smtp 监听端口 2525 .在swarm的其他服务中,我需要将此服务称为 smtp:25 不 2525 .当然,我只是做了一个端口映射。但其他服务无法访问端口上的服务 25 只有在 2525 .

注意,为了进行测试,我尝试将映射作为 2526->2525 排除任何特权问题。

我的docker compose条目如下所示:

smtp:
    image: <my repository>
    user: node
    environment:
      - NODE_ENV=production
    privileged: true
    ports:
      - published: 2526
        target: 2525
        protocol: tcp
        mode: ingress # I don't need this on the host, just on the swarm vip.
    deploy:
      replicas: 2
      placement:
        constraints:
          - node.labels.scheme == task
      restart_policy:
        condition: on-failure
        delay: 5s # how long to wait between retarts
        window: 20s # How long to determine if startup has succeeded
    healthcheck:
      test: netstat -l | grep 2525
      interval: 10s
      timeout: 10s
      retries: 10
      start_period: 20s

从busybox容器中,我可以成功地 telnet smtp 2525 但是 telnet smtp 2526 给我 connection refused 。此外,我也无法从smtp容器内部远程登录到smtp:2526。

Docker检查服务显示

 "Endpoint": {
            "Spec": {
                "Mode": "vip",
                "Ports": [
                    {
                        "Protocol": "tcp",
                        "TargetPort": 2525,
                        "PublishedPort": 2526,
                        "PublishMode": "ingress"
                    }
                ]
            },
            "Ports": [
                {
                    "Protocol": "tcp",
                    "TargetPort": 2525,
                    "PublishedPort": 2526,
                    "PublishMode": "ingress"
                }
            ],
            "VirtualIPs": [
                {
                    "NetworkID": "wv8fe0yih5ql9ye09chcl6y1b",
                    "Addr": "10.0.0.41/24"
                },
                {
                    "NetworkID": "5a9tjqidsvphi9lphldit62tm",
                    "Addr": "10.0.2.145/24"
                }
            ]
        }

Netstat透露

~/app $ netstat -tulpn | grep LISTEN
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:2525            0.0.0.0:*               LISTEN      13/node             
tcp        0      0 127.0.0.11:42381        0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:783           0.0.0.0:*               LISTEN      -        

有什么想法吗?我不能这么做吗?

编辑:

我必须让容器在端口25上监听才能让它工作。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/133627
文章 [ 1 ]  |  最新文章 4 年前