HTTPS does not work when using an existing NLB (network load balancer)

Expected behavior

Run docker compose up, navigate to my domain using HTTPS, and the app loads.

Actual behavior

Run docker compose up, navigate to my domain using HTTPS, and the request hangs. The page never loads and eventually the browser shows “Server Not Found”.

Steps to reproduce the behavior

  1. Create a NLB using the aws CLI as described here in the Docker documentation: Deploying Docker containers on ECS | Docker Documentation
  2. Copy the NLB’s domain and create a CNAME DNS record for my domain
  3. Copy the NLB’s ARN and update the docker-compose.yml file to include x-aws-loadbalancer
  4. Update docker-compose.yml file to specify SSL termination for the NLB as described here in the Docker documentation: Deploying Docker containers on ECS | Docker Documentation
  5. Change to the ecs context using docker context use myecscontext
  6. Run docker compose up and wait for it to complete successfully
  7. Navigate to my domain using HTTPS

The final docker-compose.yml file ends up with the following AWS configuration:

x-aws-loadbalancer: ${AWS_LOAD_BALANCER}

x-aws-cloudformation:
  Resources:
    AppTCP80Listener:
      Properties:
        Certificates:
          - CertificateArn: ${AWS_SSL_CERTIFICATE}
        Protocol: HTTPS
        Port: 443

Additional Information

The steps described above work as expected if I do not specify x-aws-loadbalancer and instead let Docker / AWS create a new load balancer; however, I want to use an existing NLB so that I don’t need to update my domain’s CNAME record between each deployment.