Environment variables not picked up when using docker to build project

Project id: 6b106510-a373-44f1-9ffe-d7b7199cf99a I'm changing the way my node js to built to use docker, when running the build command in the docker file I'm getting errors around environment variables not being set. They exist however in the railway variables. My docker file
# Use a Node.js base image
FROM node:21-alpine

# Install ffmpeg
RUN apk update && apk add --no-cache ffmpeg curl openrc

# Install Tailscale
RUN curl -fsSL https://tailscale.com/install.sh | sh

# Set the working directory inside the container
WORKDIR /app

# Copy the project files to the container's working directory
COPY . .

# Install Node.js dependencies
RUN yarn install

# Your custom build command
RUN npx prisma db push --schema=src/lib/prisma/schema.prisma && npx prisma generate --schema=src/lib/prisma/schema.prisma && yarn build

# Make the start script executable
RUN chmod +x start.sh

# Start Tailscale and your application via the start script
CMD ["./start.sh"]
# Use a Node.js base image
FROM node:21-alpine

# Install ffmpeg
RUN apk update && apk add --no-cache ffmpeg curl openrc

# Install Tailscale
RUN curl -fsSL https://tailscale.com/install.sh | sh

# Set the working directory inside the container
WORKDIR /app

# Copy the project files to the container's working directory
COPY . .

# Install Node.js dependencies
RUN yarn install

# Your custom build command
RUN npx prisma db push --schema=src/lib/prisma/schema.prisma && npx prisma generate --schema=src/lib/prisma/schema.prisma && yarn build

# Make the start script executable
RUN chmod +x start.sh

# Start Tailscale and your application via the start script
CMD ["./start.sh"]
The error I'm seeing on the failed build.
#11 [7/8] RUN npx prisma db push --schema=src/lib/prisma/schema.prisma && npx prisma generate --schema=src/lib/prisma/schema.prisma && yarn build



#11 1.922 Prisma schema loaded from src/lib/prisma/schema.prisma



#11 1.929 Datasource "db": PostgreSQL database

#11 1.932



#11 1.932 Error: Prisma schema validation - (get-config wasm)

#11 1.932 Error code: P1012

#11 1.932 error: Environment variable not found: DATABASE_URL.

#11 1.932 --> schema.prisma:7

#11 1.932 |

#11 1.932 6 | provider = "postgresql"

#11 1.932 7 | url = env("DATABASE_URL")

#11 1.932 |

#11 1.932
#11 [7/8] RUN npx prisma db push --schema=src/lib/prisma/schema.prisma && npx prisma generate --schema=src/lib/prisma/schema.prisma && yarn build



#11 1.922 Prisma schema loaded from src/lib/prisma/schema.prisma



#11 1.929 Datasource "db": PostgreSQL database

#11 1.932



#11 1.932 Error: Prisma schema validation - (get-config wasm)

#11 1.932 Error code: P1012

#11 1.932 error: Environment variable not found: DATABASE_URL.

#11 1.932 --> schema.prisma:7

#11 1.932 |

#11 1.932 6 | provider = "postgresql"

#11 1.932 7 | url = env("DATABASE_URL")

#11 1.932 |

#11 1.932
Solution:
you would need to bring the needed variables into the build with the ARG keyword, like so
ARG DATABASE_URL
ARG DATABASE_URL
and so on for only the variables you need during build...
Jump to solution
13 Replies
Percy
Percy10mo ago
Project ID: 6b106510-a373-44f1-9ffe-d7b7199cf99a
Solution
Brody
Brody10mo ago
you would need to bring the needed variables into the build with the ARG keyword, like so
ARG DATABASE_URL
ARG DATABASE_URL
and so on for only the variables you need during build
ebitybatata
ebitybatataOP10mo ago
Are other variables going to be available during runtime?
Brody
Brody10mo ago
yep!
ebitybatata
ebitybatataOP10mo ago
do you have any thoughts/comments about the usage of tailscale to inspect the running deployment?
Brody
Brody10mo ago
yes i do: why?
ebitybatata
ebitybatataOP10mo ago
I need to be able to inspect files on the running instance, to run recovery operations as well. I haven't deployed it yet. But hopefully I'll be able to ssh in.
Brody
Brody10mo ago
i think need is the wrong word here, im sure you can do what you want to without ssh
ebitybatata
ebitybatataOP10mo ago
We save files locally (temporarily) before processing, if the workflow fails we need to manually recover/inspect the files.
Brody
Brody10mo ago
thats definitely a use case for sure, though in an ideal world that manual intervention wouldn’t be needed
ebitybatata
ebitybatataOP10mo ago
Yup, for sure. Working towards that ideal world 🙂 If I'm using a docker image, where does the "custom command run", what directory or which context?
Custom Start Command
Command that will be run to start new deployments. Docs↗
Custom Start Command
Command that will be run to start new deployments. Docs↗
Brody
Brody10mo ago
it would be ran in whatever the image sets the workdir to, it is also ran in exec mode and it overwrites the entrypoint and cmd
ebitybatata
ebitybatataOP10mo ago
Ah I see this makes sense.
Want results from more Discord servers?
Add your server