阅读背景:

Docker AWS证书管理器SSL NodsJS失败

来源:互联网 

I have created and deployed a docker swarm cluster NodeJS application using the Cloudformation template provided by Docker.

我使用Docker提供的Cloudformation模板创建并部署了一个docker swarm集群NodeJS应用程序。

My NodeJS application has both ports 80 and 443 mapped to port 3000.

我的NodeJS应用程序将端口80和443都映射到端口3000。

I can confirm that the elastic load balancer has listeners for both ports 80 and 443.

我可以确认弹性负载平衡器有端口80和443的监听器。

Why is it that I can successfully reach my application on http but not on https?

为什么我可以成功通过http而不是https来访问我的应用程序?

for example: https://app.myapp.com/api/health responds successfully but not https://app.myapp.com/api/health

例如:https://app.myapp.com/api/health成功响应但不响应https://app.myapp.com/api/health

1 个解决方案

#1


0  

After digging more through the web and the official docker documentations and forums.

通过网络和官方码头文件和论坛挖掘更多。

I found the following to be really helpful https://docs.docker.com/docker-for-aws/load-balancer/#more-full-examples

我发现以下内容非常有用https://docs.docker.com/docker-for-aws/load-balancer/#more-full-examples

The trick was to add a label to the service and expose port 443.

诀窍是向服务添加标签并公开端口443。

Note that if you are using stack deploy the label should be on the deploy level not on the service level

请注意,如果使用堆栈部署,则标签应位于部署级别而不是服务级别

here's a sample docker compose file used with stack deploy

这是一个与stack deploy一起使用的docker compose文件示例

version: '3.3'

services:
  node:
    image: "8574365892346589.dkr.ecr.eu-central-1.amazonaws.com/app:1.5.1"
    working_dir: /home/node/app
    environment:
      - APP_PORT=3000
      - NODE_ENV=production
    volumes:
      - localstorage:/home/node/app
    ports:
      - "80:3000"
      - "443:3000"
    deploy:
      mode: global
      labels:
        - "com.docker.aws.lb.arn=arn:aws:acm:eu-central-1:873456923456:certificate/blahblahblahblahblahblah"
      update_config:
        parallelism: 2
        delay: 5s
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 5
        window: 120s

volumes:
  localstorage:

notice how the label is under the deploy

注意标签在部署下的情况

Hope that helps

希望有所帮助


分享到: