简体   繁体   English

为什么docker容器不监听端口,我不能从另一个容器ping它

[英]Why docker container does not listen the port and I can't ping it from another container

I need to ping one container (k4fntr_sl_listener) from another and I try to do it with container name and ports but it is not working.我需要从另一个容器 ping 一个容器 (k4fntr_sl_listener),我尝试使用容器名称和端口来执行此操作,但它不起作用。

networks:
  backend-network:
    driver: bridge
  frontend-network:
    driver: bridge

volumes:
   redis-data:
   pg-data:

services:
  &app-service app: &app-service-template
    container_name: k4fntr_app
    build:
      context: ./docker/php-fpm
      args:
        UID: ${UID?Use your user ID}
        GID: ${GID?Use your group ID}
        USER: ${USER?Use your user name}
    user: "${UID}:${GID}"
    hostname: *app-service
    volumes:
      - /etc/passwd/:/etc/passwd:ro
      - /etc/group/:/etc/group:ro
      - ./:/var/www/k4fntr
    environment:
      APP_ENV: "${APP_ENV}"
      CONTAINER_ROLE: app
      FPM_PORT: &php-fpm-port 9000
      FPM_USER: "${UID:-1000}"
      FPM_GROUP: "${GID:-1000}"
    depends_on:
      - redis
      - database
    networks:
      - backend-network

  &queue-service queue:
    <<: *app-service-template
    container_name: k4fntr_queue
    restart: always
    hostname: *queue-service
    depends_on:
      - app
    environment:
      CONTAINER_ROLE: queue

  &schedule-service schedule:
    <<: *app-service-template
    container_name: k4fntr_schedule
    restart: always
    hostname: *schedule-service
    depends_on:
      - app
    environment:
      CONTAINER_ROLE: scheduler

  &sportlevel-listener sportlevel_listener:
    <<: *app-service-template
    container_name: k4fntr_sl_listener
    restart: always
    hostname: *sportlevel-listener
    ports:
      - "8999:8999"
    depends_on:
      - app
    environment:
      CONTAINER_ROLE: sl_listener

As I can see the container mapping ports正如我所看到的容器映射端口

在此处输入图片说明

I also can see that containers in one network我还可以看到一个网络中的容器

docker network inspect fntr_backend-network码头工人网络检查 fntr_backend-network

"Containers": {
            "20057689b3921b3a4b1ee99f015b89b033cf072934f4cbbf63934b38b3b63203": {
                "Name": "k4fntr_php-fpm",
                "EndpointID": "700f507b0ae0eb830d5922f646ea459e67e2f5cc878867a6c15114ff9bcb202c",
                "MacAddress": "02:42:c0:a8:80:07",
                "IPv4Address": "192.168.128.7/20",
                "IPv6Address": ""
            },
            "30b4ac098109c512065082d42f6594569cd51b69937e502686b6fc91c9b410ff": {
                "Name": "k4fntr_echo",
                "EndpointID": "c5e96fa17ac3f932b93bc98ffd19d9f1ba60d71deabe82c5a9c53fe9c67e8020",
                "MacAddress": "02:42:c0:a8:80:05",
                "IPv4Address": "192.168.128.5/20",
                "IPv6Address": ""
            },
            "3ea5a601c4c0d803864cd420a7e4d689f2a985b27c5ba4c9c58a872e91945a0f": {
                "Name": "k4fntr_app",
                "EndpointID": "cc2a7dfbd0059f7483398684c9b969c2edf90178a7e38b311c9dce107a22fb61",
                "MacAddress": "02:42:c0:a8:80:06",
                "IPv4Address": "192.168.128.6/20",
                "IPv6Address": ""
            },
            "a176fed5488fc02e3bb819393ada72f710c7d3435876f0326d5f55214a2e1df9": {
                "Name": "k4fntr_queue",
                "EndpointID": "4d85ef092a69a9f1c3362eec99c193dc3e94f09682a37f0486596ba12fa70b1e",
                "MacAddress": "02:42:c0:a8:80:09",
                "IPv4Address": "192.168.128.9/20",
                "IPv6Address": ""
            },
            "a689d0b480fd0f68e0f2385f73b75788714698af5d5466fefc7d65a7dcb39dbb": {
                "Name": "k4fntr_mail",
                "EndpointID": "d29306a336018773e8937cabafa06774cc5ef3cef7eaa7e62a5ba2eba403bbf0",
                "MacAddress": "02:42:c0:a8:80:03",
                "IPv4Address": "192.168.128.3/20",
                "IPv6Address": ""
            },
            "a772c494e567017e7315df5fe67aeb45b4ee75ba8e555c4ef671f909928caa30": {
                "Name": "k4fntr_database",
                "EndpointID": "7d6c43b4d97485c49bbd8ded016b298d80b52d82bed3b69447293b8d5aabb8ce",
                "MacAddress": "02:42:c0:a8:80:04",
                "IPv4Address": "192.168.128.4/20",
                "IPv6Address": ""
            },
            "d2ebc1a9f62455fee874d64ab89d71e867bdbecd546968efbe75b9fea4f0043d": {
                "Name": "k4fntr_schedule",
                "EndpointID": "12aa000ce78b9ec8c881e88face25208c22f02e1aa8e094b4bf03e0cca393da8",
                "MacAddress": "02:42:c0:a8:80:0a",
                "IPv4Address": "192.168.128.10/20",
                "IPv6Address": ""
            },
            "d70d86bb4237f6e46dc1ccd103d8cca7913eeb33bf4c9e331ce7a523cd104648": {
                "Name": "k4fntr_redis",
                "EndpointID": "24ae090c619ede754eda9d406725388abe953f648aa436bfe4226623a0199001",
                "MacAddress": "02:42:c0:a8:80:02",
                "IPv4Address": "192.168.128.2/20",
                "IPv6Address": ""
            },
            "fc14098eeee8d87fe34e78a4117ed7cc7962cf1735dfe93c790024db0126bb38": {
                "Name": "k4fntr_sl_listener",
                "EndpointID": "5483d16d8d542b67aa0d8c9dfa2e2bdd2bbe7633d5324ab8551c451133614d51",
                "MacAddress": "02:42:c0:a8:80:08",
                "IPv4Address": "192.168.128.8/20",
                "IPv6Address": ""
            }
        },

But when I try to ping this container I got issue that connection refused但是当我尝试 ping 这个容器时,我遇到了连接被拒绝的问题

在此处输入图片说明

I also see that the container which I need to ping does not listen port 8999我还看到我需要 ping 的容器没有监听端口 8999

在此处输入图片说明

There is only one listen port from php process. php 进程只有一个监听端口。

How can I solve the problem?我该如何解决问题? And is it possible to ping this php process from another container?是否可以从另一个容器 ping 这个 php 进程? I need it because this container was created only for this php process which I need to ping我需要它,因为这个容器只为这个我需要 ping 的 php 进程创建

So I have found the answer.所以我找到了答案。 In short, the problem was that my process was listening localhost and I could not to ping it.简而言之,问题在于我的进程正在侦听 localhost 而我无法 ping 它。 I changed the script on 0.0.0.0:8096 and changed ports on "8096:8096" and all works fine我更改了 0.0.0.0:8096 上的脚本并更改了“8096:8096”上的端口,一切正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM