R
Railway11mo ago
Abner

Dockerfile with node alpine can't access database internal network

When I up a Dockerfile with a normal image from node, this is work, but when I up a Dockerfile with an image alpine they can't access the same database in internal network, someone can help me ?
No description
Solution:
you are right, but they aren't running anything that uses the private network during build, their issues is because they are using an alpine image. https://docs.railway.app/guides/private-networking#workaround-for-alpine-based-images...
Jump to solution
24 Replies
Percy
Percy11mo ago
Project ID: 8e7a534e-bfc1-40ca-a40a-9695fda79d5a
Abner
AbnerOP11mo ago
8e7a534e-bfc1-40ca-a40a-9695fda79d5a
Adam
Adam11mo ago
I may be wrong, but I believe private networking is not available during build, so you wouldn’t be able to reference a db in a dockerfile @Brody lmk if that’s right not sure what you’re doing in said dockerfile that requires a database. Can you elaborate on your use case?
Abner
AbnerOP11mo ago
In my case I'm just using the dockerfile to configure the node version and then execute commands in the terminal through a .sh file, as I'm using Prisma I need to perform the generate and deploy commands, sorry for not explaining it before. I can put here Dockerfile for you see ?
Adam
Adam11mo ago
for sure, go for it please wrap it in backticks so it shows as code
Abner
AbnerOP11mo ago
# Use the official Node.js image as the base image
FROM node:20-alpine

# Set the working directory in the container
WORKDIR /usr/src/app

# Copy package.json and package-lock.json to the working directory
COPY package.json package-lock.json ./

# Install dependencies
RUN apk update && apk add bash
RUN npm install

# Copy the rest of the application code
COPY . .

# Expose the port the application will run on
EXPOSE 3000

# Command to start the application
CMD ["bash","migrate-and-start.sh"]
# Use the official Node.js image as the base image
FROM node:20-alpine

# Set the working directory in the container
WORKDIR /usr/src/app

# Copy package.json and package-lock.json to the working directory
COPY package.json package-lock.json ./

# Install dependencies
RUN apk update && apk add bash
RUN npm install

# Copy the rest of the application code
COPY . .

# Expose the port the application will run on
EXPOSE 3000

# Command to start the application
CMD ["bash","migrate-and-start.sh"]
migrate-and-start.sh:
#!/bin/sh
npm run build
npx prisma generate
npx prisma migrate deploy
npm run start:dev
#!/bin/sh
npm run build
npx prisma generate
npx prisma migrate deploy
npm run start:dev
Adam
Adam11mo ago
Try removing your start command from your Dockerfile and add it as a start command in your Railway service or in a railway.json https://docs.railway.app/guides/config-as-code Right now you're starting your service in your dockerfile, which would start it in your build steph which is why it's failing.
Abner
AbnerOP11mo ago
hummm that makes sense , but when i change the image ( FROM) for a version normal node like node:21 it's work and i don't recive this erros ( i don't know why )
Adam
Adam11mo ago
I wouldn’t know why either
Abner
AbnerOP11mo ago
i try use a config as code, but i don't know i do this corret skskksks
Abner
AbnerOP11mo ago
it's right ?
No description
Abner
AbnerOP11mo ago
No description
Solution
Brody
Brody11mo ago
you are right, but they aren't running anything that uses the private network during build, their issues is because they are using an alpine image. https://docs.railway.app/guides/private-networking#workaround-for-alpine-based-images
Brody
Brody11mo ago
go back to this dockerfile (no need for a railway.json) and a tip, you don't need to install bash, just use sh instead
Abner
AbnerOP11mo ago
ho it's work !!!!!
Brody
Brody11mo ago
you added the alpine specific variable right?
Abner
AbnerOP11mo ago
Thanks so much @Adam and @Brody, you guys are awesome you say that rigth ENABLE_ALPINE_PRIVATE_NETWORKING=true ?
Brody
Brody11mo ago
I'm just now noticing this, please please do not run a development server on railway
Abner
AbnerOP11mo ago
you say about
npm run start:dev
npm run start:dev
?
Brody
Brody11mo ago
yes
Abner
AbnerOP11mo ago
Even if it is a development environment ?
Brody
Brody11mo ago
development servers cost more to run and come with increased instabilities and much lower performance
Abner
AbnerOP11mo ago
oww ok, i don't have no idea about that, i will change that
Brody
Brody11mo ago
sounds good
Want results from more Discord servers?
Add your server