a year ago
I'm struggling to get private networking working. I'm not super familiar with this, so I might be missing something super obvious.
My setup:
Service A: Next.js service running in a docker container
Service B: Node.js Express service running in a docker container
I'm trying to get Service A to make a request to Service B via private networking but struggling to get this to work.
I've followed the docs and setup IPv6 on Service B with:
app.listen(port, "::", () => {
console.log(`Server is running on ${port}`);
});
I've also set ENABLE_ALPINE_PRIVATE_NETWORKING=true on Service B
Dockerfile on Service B:
FROM --platform=linux/amd64 node:18-slim
# Install dependencies for Chromium and other necessary tools
RUN apt-get update \
&& apt-get install -y wget gnupg ca-certificates procps libxss1 \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
# Install Chrome to get all the OS level dependencies
&& apt-get install -y google-chrome-stable \
&& rm -rf /var/lib/apt/lists/* \
&& wget --quiet https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -O /usr/sbin/wait-for-it.sh \
&& chmod +x /usr/sbin/wait-for-it.sh
# Set working directory
WORKDIR /app
# Copy package.json and package-lock.json files
COPY package*.json ./
# Install node dependencies
RUN npm install
# Copy the rest of the application code
COPY . .
ARG PORT=3001
# Expose the port
EXPOSE ${PORT}
# Build the TypeScript project
RUN npm run build
# Command to run the application
CMD ["npm", "run", "start"]
I can see in my logs that Service A is making requests to the correct URL: http://${{api.RAILWAY_PRIVATE_DOMAIN}}:${{api.PORT}} but it just doesn't seem to be working.
As a workaround, I'm currently using the public domain of Service B which is working fine, but would like to use private networking if possible.
Any help is appreciated!
Full error in Service A when trying to call Service B:Failed to fetch html: TypeError: fetch failed
at node:internal/deps/undici/undici:12502:13
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async i (/app/.next/server/app/api/v1/scrape/route.js:3:5144)
at async eN (/app/.next/server/app/api/v1/scrape/route.js:1:35951)
at async eS (/app/.next/server/app/api/v1/scrape/route.js:3:1470)
at async /app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:34754
at async eS.execute (/app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:25901)
at async eS.handle (/app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:36008)
at async doRender (/app/node_modules/next/dist/server/base-server.js:1377:42)
at async cacheEntry.responseCache.get.routeKind (/app/node_modules/next/dist/server/base-server.js:1599:28) {
[cause]: Error: getaddrinfo ENOTFOUND modest-quietude.railway.internal
at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:120:26)
at GetAddrInfoReqWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'modest-quietude.railway.internal'
}
}
7 Replies
a year ago
Very well written question, unfortunately you left out a bit of key information, the actual error you are getting when trying to call service B via the private network.
a year ago
Oops - just added the full error message
a year ago
At what point in service A's lifecycle does it call service B? at the start or later?
Is service A deployed with a Dockerfile? if so, does it use an alpine image?
a year ago
Service A calls Service B when Service A receives a request. I've tried making multiple requests to Service A over the course of ~30 minutes post deployment. Fwiw, I also tried adding sleep 3 to the start command of Service A without success.
Service A does use an alpine image. However Service B does not use an Alpine image and it's Service A making a POST request to Service B where the issue is occurring. Do i need to add ENABLE_ALPINE_PRIVATE_NETWORKING=true
to service A?
a year ago
If service A is based on an alpine image and is the service that is making the network request, then it does need that environment variable.
FWIW, the private network has some major flaws right now (needing that variable for alpine images, and needing a sleep 3) but this will all be fixed and you won't need either of those workarounds with runtime v2 that's currently being worked on!
Status changed to Solved railway[bot] • 12 months ago
a year ago
It works now!Thank you so much - I had tried adding the flag on Service B, but it didn't occur to me to add it to Service A.
Looking forward to the revamp, super impressed with everything so far as well as the velocity in the weekly changelog!