Using Build Arguments in Docker Build

Michael Roma on Jan 8, 2019

Example Dockerfile for building an Angular 6 project

base ===============================

FROM nginx:1.13.3-alpine AS base

clean up

RUN rm -rf /usr/share/nginx/html/*

builder ============================

FROM node:10 AS builder

build dependencies

WORKDIR /app RUN npm install -g @angular/cli@6.2.3 COPY package.json /app RUN npm install

build

ARG BUILDCONF COPY . /app RUN ng build –configuration=${BUILDCONF}

final ==============================

FROM base AS final

setup server

WORKDIR /app COPY docker/default.conf /etc/nginx/conf.d/ COPY –from=builder /app/dist /usr/share/nginx/html CMD [“nginx”, “-g”, “daemon off;”]

In the dockerfile above, the line for ng build takes a build arg \({BUILDCONF} <pre lang="bash"> RUN ng build --configuration=\){BUILDCONF} You can pass this build arg through the docker build command using the –build-arg parameter
docker build -t my-app:build –build-arg BUILDCONF=$BUILD_CONFIG .