Can't access MYSQL privately from Nodejs app

I am getting error.
at async Sequelize.authenticate (/app/node_modules/sequelize/lib/sequelize.js:457:5) {

parent: Error: getaddrinfo ENOTFOUND mysql.railway.internal

at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26) {

errno: -3008,

code: 'ENOTFOUND',

syscall: 'getaddrinfo',

hostname: 'mysql.railway.internal',

fatal: true

},

original: Error: getaddrinfo ENOTFOUND mysql.railway.internal

at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26) {

errno: -3008,

code: 'ENOTFOUND',

syscall: 'getaddrinfo',

hostname: 'mysql.railway.internal',

fatal: true

}

}
at async Sequelize.authenticate (/app/node_modules/sequelize/lib/sequelize.js:457:5) {

parent: Error: getaddrinfo ENOTFOUND mysql.railway.internal

at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26) {

errno: -3008,

code: 'ENOTFOUND',

syscall: 'getaddrinfo',

hostname: 'mysql.railway.internal',

fatal: true

},

original: Error: getaddrinfo ENOTFOUND mysql.railway.internal

at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26) {

errno: -3008,

code: 'ENOTFOUND',

syscall: 'getaddrinfo',

hostname: 'mysql.railway.internal',

fatal: true

}

}
Solution:
for an alpine based docker image, please see this docs section https://docs.railway.app/guides/private-networking#workaround-for-alpine-based-images
Jump to solution
10 Replies
Percy
Percy10mo ago
Project ID: ed9d81eb-a192-462c-8cf6-bf7778244e57
KeshariPiyush24
KeshariPiyush2410mo ago
This is my dockerfile
# use a smaller base image
FROM node:lts-alpine AS base

# set working directory
WORKDIR /app

# copy package files and install dependencies
COPY package*.json ./
RUN npm ci --omit=dev --quiet

# copy source code and build app
FROM base AS build
COPY . .
RUN npm i typescript
RUN npm i tsc-alias
RUN npm run build
RUN npm prune --production

# create final image
FROM base AS final
COPY --from=build ./app/config ./config
COPY --from=build ./app/dist ./dist
COPY --from=build ./app/node_modules ./node_modules

# set environment variables
EXPOSE 3000

CMD sh -c "sleep 3 && npm start"
# use a smaller base image
FROM node:lts-alpine AS base

# set working directory
WORKDIR /app

# copy package files and install dependencies
COPY package*.json ./
RUN npm ci --omit=dev --quiet

# copy source code and build app
FROM base AS build
COPY . .
RUN npm i typescript
RUN npm i tsc-alias
RUN npm run build
RUN npm prune --production

# create final image
FROM base AS final
COPY --from=build ./app/config ./config
COPY --from=build ./app/dist ./dist
COPY --from=build ./app/node_modules ./node_modules

# set environment variables
EXPOSE 3000

CMD sh -c "sleep 3 && npm start"
KeshariPiyush24
KeshariPiyush2410mo ago
No description
Solution
Brody
Brody10mo ago
for an alpine based docker image, please see this docs section https://docs.railway.app/guides/private-networking#workaround-for-alpine-based-images
LeoLeo
LeoLeo8mo ago
I didn't find a rule about texting in someone else's thread, I hope it's ok for me to add to this, if not I apologize Project ID: 4cc0d132-ab38-44ae-8c5c-8bfc804592eb I had the same error as Piyush about reaching mysql on private networking from nodejs (expressjs) I applied the alpine workaround, meaning that I've set that env variable on nodejs now I'm getting a different error, a connection timeout I've read this in the docs: "Note that using this workaround will cause the 100ms DNS initialization delay to impact both public and private networking." could it be it?
No description
No description
Brody
Brody8mo ago
nixpacks or dockerfile?
LeoLeo
LeoLeo8mo ago
nixpacks
Brody
Brody8mo ago
then the alpine variable is not applicable, please add a 3 second sleep to your start script
LeoLeo
LeoLeo8mo ago
awesome, it lives! thank you mate I'm guessing it was the same problem = private networking dns wasn't up fast enough? and the fact that I got a different error after setting the alpine variable was a coincidence?
Brody
Brody8mo ago
the docs say 100ms but in reality it's more like 2 seconds
Want results from more Discord servers?
Add your server