We have seen the WORKDIR instruction used in some of the examples used to demonstrate other instructions. It is sort of like a combination of the Linux cd and mkdir commands. The WORKDIR instruction will change the current working directory in the image to the value provided in the instruction. If any segment of the path in the parameter of the WORKDIR instruction does not yet exist, it will be created as part of the execution of the instruction. The syntax for the WORKDIR instruction is as follows:
# WORKDIR instruction syntax
WORKDIR instruction syntax
WORKDIR /path/to/workdir
The WORKDIR instruction can use ENV or ARG parameter values for all or part of its parameter. A Dockerfile can have more than one WORKDIR instruction, and each subsequent WORKDIR instruction will be relative to the previous one (if a relative path is used). Here is an example that...