Docker Compose v2.17.3 から、 dockerfile_inline
構文で compose.yaml
の中に Dockerfile をインライン記述できるようになった。
そこで突然だが、 Docker クイズ!!
以下の compose.yaml
をビルドしたら、 /out.txt
には何が出力されているだろうか?
services:
inline:
build:
context: .
dockerfile_inline: |
FROM alpine
ARG arg3="dockerfile"
ARG argDupl="dockerfile"
RUN export arg2=buildcontainer \
&& export argDupl=buildcontainer \
&& cat <<EOS > /out.txt
--------
arg2=$arg2
arg3=$arg3
arg2=\$arg2
arg3=\$arg3
EOS
RUN cat /out.txt
docker compose --progress=plain build --no-cache
オプションを付けてビルドし、 /out.txt
のダンプがどうなるか見てみよう。
果たして、正解は…?
ドロドロドロドロドロドロ (ドラムロール音)
\デーン!!!/
#6 [inline 3/3] RUN cat /out.txt
#6 0.496 --------
#6 0.496 arg2=
#6 0.496 arg3=
#6 0.496 arg2=arg3=--------
#6 DONE 0.5s
正解できただろうか?