Next.js Discord

Discord Forum

Set next app to listen on all local networks inside docker

Answered
African Slender-snouted Crocodil… posted this in #help-forum
Open in Discord
African Slender-snouted CrocodileOP
I have next js app in an environment where the container has multiple networks attached. It so happens that it listens on the incorrect network. How can I set the app to listen on all network hosts?
Example:
services:
  # Routing with Caddy
  caddy:
    build:
      context: .
      dockerfile: caddy.Dockerfile
    ports:
      - 80:80
      - 443:443
    environment:
      - CADDY_INGRESS_NETWORKS=caddy
    networks:
      - caddy
  # ... other apps on app-tier network
  app-emails:
    image: ghcr.io/...
    env_file:
      - app-emails.env
    depends_on:
      - redis-apl
    networks:
      - app-tier
      - caddy
    labels:
      caddy: app-emails.site.com
      caddy.reverse_proxy: "{{upstreams 3000}}"

networks:
  app-tier:
  caddy:

docker inspect {container}
"Networks": {
  "app-tier": {
    "Aliases": [
      "app-emails-1",
      "app-emails"
    ],
    "Gateway": "192.168.16.1",
    "IPAddress": "192.168.16.7",
    "DNSNames": [
      "app-emails-1",
      "app-emails",
      "177fd9c4dfb6"
    ]
  },
  "caddy": {
    "Aliases": [
      "app-emails-1",
      "app-emails"
    ],
    "Gateway": "192.168.0.1",
    "IPAddress": "192.168.0.11",
    "DNSNames": [
      "app-emails-1",
      "app-emails",
      "177fd9c4dfb6"
    ]
  }
}


And the app outputs:
app-emails-1 |   ▲ Next.js 14.2.3
app-emails-1 |   - Local:        http://177fd9c4dfb6:3000
app-emails-1 |   - Network:      http://192.168.16.7:3000
app-emails-1 |
app-emails-1 |  ✓ Starting...
app-emails-1 |  ✓ Ready in 389ms
Answered by African Slender-snouted Crocodile
Aight in dockerfile I had to do
CMD HOSTNAME="0.0.0.0" node server.js

instead of
ENV HOSTNAME="0.0.0.0" 
CMD node server.js

but it says 0.0.0.0:3000 now. Will see if that fixes my issue.
View full answer

4 Replies

African Slender-snouted CrocodileOP
I need it to listen on the caddy network, or ideally just listen to both of them
But rn it listens only on app-tier network, meaning my reverse proxy can't route to the app inside container
African Slender-snouted CrocodileOP
Aight in dockerfile I had to do
CMD HOSTNAME="0.0.0.0" node server.js

instead of
ENV HOSTNAME="0.0.0.0" 
CMD node server.js

but it says 0.0.0.0:3000 now. Will see if that fixes my issue.
Answer
African Slender-snouted CrocodileOP
ok fixed it