Search code examples
node.jsssldockeraws-cloudformationdocker-swarm

Docker AWS Certificate Manager SSL NodsJS failure


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

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

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

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

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


Solution

  • 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

    The trick was to add a label to the service and expose port 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

    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