docker容器中意外的未映射端口80

时间:2019-08-21 14:15:14

标签: docker docker-compose

当我运行docker ps时,我看到apphub-ui容器上未映射端口80,我希望它映射到4200,我也看到了。我不明白为什么出现80/tcp,它在我的应用程序中造成了连接拒绝问题。

这是docker ps的输出

docker ps                                                                                                                                                                                                                         10s +59%
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                          NAMES
22cb2b9c28d4        swimlane/apphub-ui:latest    "/usr/bin/reefer -t …"   20 seconds ago      Up 17 seconds       80/tcp, 0.0.0.0:80->4200/tcp   apphub_apphub-ui_1
19a78f93bfe7        swimlane/apphub-api:latest   "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        0.0.0.0:3000->3000/tcp         apphub_apphub-api_1
7b3478e2dcd5        mongo:3.6                    "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        0.0.0.0:27017->27017/tcp       apphub_mongo_1

我的docker-compose文件如下

version: '3.6'

volumes:
  mongo:

services:
  mongo:
    image: mongo:3.6 
    ports:
      - 27017:27017
    volumes:
      - mongo:/data/db

  apphub-api:
    image: swimlane/apphub-api:latest
    ports: 
      - 3000:3000 
    depends_on:
      - mongo

  apphub-ui:
    image: swimlane/apphub-ui:latest
    ports: 
      - 80:4200 
    depends_on:
      - apphub-api
    environment:
      - APPHUB_API_HOST=apphub-api

如果我将ui功能的映射端口更改为4200:4200,并且看不到杂散未映射80,我的应用程序运行正常

1 个答案:

答案 0 :(得分:0)

我感觉到您想将主机上的端口4200映射到容器的端口80。在这种情况下,您应该切换值。即

    ports: 
      - 4200:80