Redwood API in docker stuck in IPv6

Hi,

I am trying to get redwood to work from within a container (not a swarm). I have the web side working properly out of 8910, but the API side is failing because the host = “0.0.0.0” doesn’t seem to be passed to the API side when in dev mode (yarn rw dev). To be clear, I want dev mode, not concerned with production from within this docker container.

The error I get is:

api | API listening on http://localhost:8911/
api | GraphQL endpoint at /graphql
api | node:internal/errors:496
api |     ErrorCaptureStackTrace(err);
api |     ^
api | 
api | Error: listen EAFNOSUPPORT: address family not supported :::8911
api |     at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
api |     at __node_internal_uvExceptionWithHostPort (node:internal/errors:593:12)
api |     at Server.setupListenHandle [as _listen2] (node:net:1800:21)
api |     at listenInCluster (node:net:1865:12)
api |     at doListen (node:net:2014:7)
api |     at process.processTicksAndRejections (node:internal/process/task_queues:83:21) {
api |   code: 'EAFNOSUPPORT',
api |   errno: -97,
api |   syscall: 'listen',
api |   address: '::',
api |   port: 8911
api | }

Seems like it might have something to do with this:

packages/api-server/src/server.ts

export const startServer = ({
  port = 8911,
  socket,
  fastify,
}: HttpServerParams) => {
  const host = process.env.NODE_ENV === 'production' ? '0.0.0.0' : '::'
  const serverPort = socket ? parseInt(socket) : port

  fastify.listen({ port: serverPort, host })

I tried setting the NODE_ENV to production, but I guess that doesn’t hold when running yarn rw dev.

I think question is why, in dev mode, isn’t the API obeying the host = “0.0.0.0” attribute from the toml file? Or is there a way to override the fastify dev server to force a hostname?

Thanks in advance!

Hi @John

Both @dom and @Josh-Walker-GM are actively working to improve Docker support and are likely able to help point you in the right direction.

I’m not even sure this is a docker question… I think it’s just “how do I force the dev server to run over IPv4” (specifically the API side)?

This portion of the docs didn’t seem to work:

[web]
  host = '0.0.0.0'
[api]
  host = '0.0.0.0'

Hi John,
I have some experience getting redwood to work properly in docker - would you be able to post the dockerfile(s) you’re using along with the command you’re using to start up the container? If you’re using docker-compose I’d need to see your docker-compose.yaml as well.

In my experience if you’re not hosting both sides in the same container you need to replace localhost with host.docker.internal or whatever you’ve named your api service for the proxy to work in a lot of cases, but I’d need more info about your specific setup to get a better idea :slight_smile:

2 Likes

@john to answer your original question of why yarn rw dev isn’t obeying the api.host key in redwood.toml, it’s simply because it’s not hooked up at all. (i.e. it’s a bug on our end.)

The reason setting NODE_ENV=production doesn’t work is that the code for yarn rw dev sets it to development, overwriting anything you set at the CLI etc:

In working on Docker, I learned the hard way again that our server options leave a lot to be desired. But I’ve definitely got dev working via compose. (I’m not sure if that qualifies as a swarm.) Have you tried the yarn rw exp setup-docker command? The compose files for dev and prod should just work, provided you specify necessary env vars.