asadow
(Asadow)
January 10, 2024, 1:52pm
1
Why is it that the below Dockerfile sets the working directory while ignoring the ARG?
ARG TOPIC=esa
FROM asadow/dev_env_r:4.3.2
RUN apt-get update […]
WORKDIR /home/{$TOPIC}
When I start a container from this image, I am in the “home” directory, and no “esa” folder exists.
rimelek
(Ákos Takács)
January 10, 2024, 6:40pm
2
https://docs.docker.com/engine/reference/builder/#arg
Arguments must be after the FROM instruction. ARG before the FROM instrution can only be used in the FROM instruction. And I don’t think {$TOPIC}
is a valid syntax, but I could be wrong. The documented and definitely working syntax is ${TOPIC}
or just simply $TOPIC
1 Like
asadow
(Asadow)
January 10, 2024, 6:45pm
3
Ah, thank you!
Do you know why there is no build error, however? Why would WORKDIR /home/$TOPIC simply ignore $TOPIC?
Apologies with the syntax.
rimelek
(Ákos Takács)
January 10, 2024, 6:54pm
4
It is explained in the same documentation I linked in my previous post.
Prior to its definition by an ARG
instruction, any use of a variable results in an empty string.
In other words, it works like variables in a shell, so unset variables will be used as empty string. You can use this syntax to avoid it:
WORKDIR /home/${TOPIC:?}
Or add a custom error message:
WORKDIR /home/${TOPIC:?Do not leave it empty}
1 Like
asadow
(Asadow)
January 10, 2024, 7:08pm
5
Many lessons learned. Thanks again.