How can I use ENV variables when deploying a Dockerfile?

I have set all my ENV variables in railway. However, the dockerfile does not recognize them. Any ideas how I should do it?
11 Replies
Percy
Percy12mo ago
Project ID: N/A
imIgnacio
imIgnacio12mo ago
So for example, It should be ARG REACT_APP_GOOGLE_TOKEN ??
Brody
Brody12mo ago
yep!
imIgnacio
imIgnacio12mo ago
And would the varialbes be used automatically? I mean, just by having ARG VARIABLE is enough to use them app wide? (I don't know docker much) Also, can I use nixpacks in docker?
Brody
Brody12mo ago
all service variables are aviable at runtime theres nothing you need to do for that, you only need to follow the info in the docs if you need the variables at build time
Also, can I use nixpacks in docker?
explain?
imIgnacio
imIgnacio12mo ago
I want to use NIXPACKS_APT_PKGS=gconf-service libgbm-dev libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils from what I understand, they will get installed?
Brody
Brody12mo ago
can you send me your current dockerfile? please enclose this in triple backticks
imIgnacio
imIgnacio12mo ago
# Use a base image, for example, Ubuntu
FROM node:16

# Railway environment
ARG RAILWAY_ENVIRONMENT

# Specify the ENV variables
ARG GOOGLE_MAPS_API_KEY
ARG JWT_SECRET
ARG MONGODB_URI
ARG NIXPACKS_APT_PKGS
ARG NODE_ENV
ARG VITE_APP_MAPBOX_TOKEN

# Set the timezone
ENV TZ=America/Santiago

# Update package lists and install any necessary packages
RUN apt-get update && \
apt-get install -y \
tzdata

# Configure the timezone
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

WORKDIR /app

# Copy package.json and package-lock.json for the server
COPY server/package*.json ./server/
RUN cd server && npm install

# Copy package.json and package-lock.json for the client
COPY client/package*.json ./client/
RUN cd client && npm install

COPY . .

# Build the server application
RUN cd server && npm run tsc

# Build the client application
RUN cd client && npm run build

# Expose the port on which your app will run
EXPOSE 3000

# Define the default command to start your app
CMD ["npm", "run", "start"]
# Use a base image, for example, Ubuntu
FROM node:16

# Railway environment
ARG RAILWAY_ENVIRONMENT

# Specify the ENV variables
ARG GOOGLE_MAPS_API_KEY
ARG JWT_SECRET
ARG MONGODB_URI
ARG NIXPACKS_APT_PKGS
ARG NODE_ENV
ARG VITE_APP_MAPBOX_TOKEN

# Set the timezone
ENV TZ=America/Santiago

# Update package lists and install any necessary packages
RUN apt-get update && \
apt-get install -y \
tzdata

# Configure the timezone
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

WORKDIR /app

# Copy package.json and package-lock.json for the server
COPY server/package*.json ./server/
RUN cd server && npm install

# Copy package.json and package-lock.json for the client
COPY client/package*.json ./client/
RUN cd client && npm install

COPY . .

# Build the server application
RUN cd server && npm run tsc

# Build the client application
RUN cd client && npm run build

# Expose the port on which your app will run
EXPOSE 3000

# Define the default command to start your app
CMD ["npm", "run", "start"]
Brody
Brody12mo ago
these are apt packages, just use them in the dockerfile like how are you for tzdata
imIgnacio
imIgnacio12mo ago
Thanks!!
Want results from more Discord servers?
Add your server