首页 > 解决方案 > AWS Elastic Beanstalk Docker 容器端口映射

问题描述

我有与 Elastic Beanstalk 多个 Docker-container-env 上的端口映射相关的问题。

我的 Dockerrun.aws.json 看起来像这样:

{
  "AWSEBDockerrunVersion": 2,
  "containerDefinitions": [
    {
      "name": "web",
      "image": "exampleimage",
      "hostname": "web",
      "essential": true,
      "memory": 128,
      "portMappings": [
        {
          "hostPort": 3000,
          "containerPort": 80
        }
      ]
    }
  ]
}

我的网络 dockerfile 看起来像这样:

FROM node:alpine as builder

WORKDIR '/app'
COPY ./package.json ./
RUN npm install
COPY . .

FROM nginx
EXPOSE 80
COPY --from=builder /app/build /usr/share/nginx/html
# at the end its a nginx images

这是否意味着我的 docker 容器在端口 80 上运行,而我在主机端口 3000 上运行?

如果在我的 AWS Elastic Beanstalk 上,端点就像

url-something-like-this-xxxx.com

如何访问容器?

url-something-like-this-xxxx:3000.com。??

太感谢了!

标签: amazon-web-servicesdockeramazon-elastic-beanstalk

解决方案


访问协议指定的端口以外的其他端口的正确语法是://:示例

在端口 3000 上通过 http 访问网站

http://some-url.com:3000

在端口 8443 上通过 https 访问网站

https://some-url.com:8443

还要确保附加到您的实例或负载均衡器的安全组允许从您的 IP 地址或 0.0.0.0/0 访问端口 3000(如果您希望它是公共的)

链接到更新安全组的指南。

https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html#AddRemoveRules


推荐阅读