Consume machine environment variables during build from dockerfile

Hi, I would like to know if it is possible to consume environment variables during build time inside the dockerfile.

The image is being created in a micro service running in kubernetes. It needs to consume the micro service environment variable (not secret) to compile an Angular project and then to copy the corresponding dist folder to nginx html directory.

The variable I would like to consume is $COUNTRY

Here is the dockerfile:

FROM node:10-alpine as builder
RUN echo $COUNTRY

WORKDIR /app
COPY . /app
RUN cd /app && npm install
RUN cd /app && npm run build-$COUNTRY

FROM nginx:alpine

RUN rm -rf /usr/share/nginx/html/*
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=builder /app/dist/$COUNTRY/. /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]

Thanks in advance.

You might want to check https://docs.docker.com/engine/reference/commandline/build/#set-build-time-variables---build-arg :slight_smile: