What is the correct way to append a path to a variable in a Dockerfile without triggering any warnings, even if the variable is undefined?
Suppose I want to append a path to a PATH-like environment variable, which may be undefined in the base image (assuming a Linux-based image):
ARG BASE_IMAGE=ubuntu:22.04
FROM $BASE_IMAGE
ENV PATH1=$PATH1:/new-path1
When running docker build, if PATH1 is defined in the base image, it correctly appends the new path to PATH1. However, if PATH1 is not defined in the base image, it gives the following warning:
#1 WARN: UndefinedVar: Usage of undefined variable '$PATH1' (did you mean $PATH?) (line 3)
I tried using Environment replacement to avoid this warning, like this:
ENV PATH1=${PATH1:-}:/new-path1
but it also gave the same warning.