Dockerfile Build Arguments
In this lesson, we will explore using build arguments to paramerterize an image build.
Use the --build-arg flag when building an image:
--build-arg [NAME]=[VALUE]
Use the ARG instruction in the Dockerfile:
ARG [NAME]=[DEFAULT_VALUE]
Step 1: Navigate to the args directory:
mkdir argscd argsStep 2: Clone the weather-app:
git clone https://github.com/nishanthkumarpathi/content-weather-app.git srcStep 3: Create the Dockerfile:
vi DockerfileStep 4: Create an image for the weather-app
Dockerfile:
FROM node
LABEL org.label-schema.version=v1.1
ARG SRC_DIR=/var/node
RUN mkdir -p $SRC_DIR
ADD src/ $SRC_DIR
WORKDIR $SRC_DIR
RUN npm install
EXPOSE 3000
CMD ./bin/wwwStep 5: Build the weather-app image:
Step 6: Inspect the image:
Step 7: Create the weather-app container:
Step 8: Verify that the container is working by executing curl:
In case if you dont find curl in your system, then do the following.
Last updated