DockerFileビルド時に引数で変数を渡す場合はARG
ENVの場合、Dockerfile内の途中で書き換えることができる
1 2 3 4 5 6 7 8 9 |
yuta@DESKTOP-V36210S:/mnt/c/container/Docker/test$ cat Dockerfile FROM alpine ARG ARGTEST=1 ENV ENVTEST=aaa RUN echo $ARGTEST RUN echo $ENVTEST yuta@DESKTOP-V36210S:/mnt/c/container/Docker/test$ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
yuta@DESKTOP-V36210S:/mnt/c/container/Docker/test$ docker build --build-arg ARGTEST="666" --rm . Sending build context to Docker daemon 2.048kB Step 1/5 : FROM alpine ---> a187dde48cd2 Step 2/5 : ARG ARGTEST=1 ---> Using cache ---> e9466e527a97 Step 3/5 : ENV ENVTEST=aaa ---> Using cache ---> 41a897b281e3 Step 4/5 : RUN echo $ARGTEST ---> Running in 4a5aed9cc706 666 Removing intermediate container 4a5aed9cc706 ---> 8023877d59ff Step 5/5 : RUN echo $ENVTEST ---> Running in 716e54e6dbc0 aaa Removing intermediate container 716e54e6dbc0 ---> 73c68f8b4ad4 Successfully built 73c68f8b4ad4 yuta@DESKTOP-V36210S:/mnt/c/container/Docker/test$ |
https://techblog.recochoku.jp/1979