Hosting 2 domains under 1 EC2 instance?

Hi everyone, I was wondering if it is possible to use traefik to setup https for 2 services, hosted in 1 EC2 instance? Here is my docker-compose.yml file. And currently with this, I was able to get https://server-prod.myserver.com to run successfully, but for the other https://server-dev.myserver.com im getting 502 bad gateway error.

# docker-compose.yml
version: '2'
services:
  
  app:
    platform: linux/amd64
    build:
      context: .
      dockerfile: Dockerfile
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.app.rule=Host(`server-prod.myserver.com`)"
      - "traefik.http.routers.app.entrypoints=websecure"
      - "traefik.http.routers.app.tls.certresolver=letsencrypt"
    ports:
      - 3000:3000
      - 9229:9229
    depends_on:
      - traefik
    env_file:
      - ./.env.prod
    command: sh -c 'npm run start'
    restart: unless-stopped
  
  app-dev:
    platform: linux/amd64
    build:
      context: .
      dockerfile: Dockerfile
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.app-dev.rule=Host(`server-dev.myserver.com`)"
      - "traefik.http.routers.app-dev.entrypoints=websecure"
      - "traefik.http.routers.app-dev.tls.certresolver=letsencrypt"
    ports:
      - 3001:3001
    depends_on:
      - traefik
    env_file:
      - ./.env.dev
    command: sh -c 'npm run start'
    restart: unless-stopped
    
  traefik:
    image: traefik:v2.5
    container_name: traefik
    command:
      - "--providers.docker"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.letsencrypt.acme.email=filberttt@hotmail.com"
      - "--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json"
      - "--certificatesresolvers.letsencrypt.acme.httpchallenge=true"
      - "--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=web"
      - "--log.level=DEBUG"
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./letsencrypt:/letsencrypt
      - /var/run/docker.sock:/var/run/docker.sock:ro

Use a Docker network, don’t expose ports except for Traefik, tell Traefik via labels which target service port to use. See simple Traefik example.

PS: its recommended to use a current Traefik release version.

Thanks, using external docker networks and telling traefik to target which ports each service use worked!