Dockerfile ARG始终为空
我花了相当多的时间来做到这一点。 我想要实现的是将连接string作为docker-compose的构buildparameter passing给dockerfile。 下面是一个简单的代码片段,它重现了这个问题。 Write-Host ${SOMEARG}
的输出始终为空。
有下面的dockerfile:
FROM microsoft/iis ARG SOMEARG=test SHELL ["powershell", "-command"] RUN Write-Host 'HERE:';` Write-Host ${SOMEARG}
我有输出:
Step 1/4 : FROM microsoft/iis ---> 85fb57957cf1 Step 2/4 : ARG SOMEARG=test ---> Running in 84a7fc37994c Removing intermediate container 84a7fc37994c ---> 2099e56f466f Step 3/4 : SHELL ["powershell", "-command"] ---> Running in 61852677a26a Removing intermediate container 61852677a26a ---> b934f778c13b Step 4/4 : RUN Write-Host 'HERE:'; Write-Host ${SOMEARG} ---> Running in 3fde911ecdc1 HERE: Removing intermediate container 3fde911ecdc1 ---> 5331ce22c3ec Successfully built 5331ce22c3ec
其实这个在这里解决了 。
由于您使用的是Windows容器,因此应使用%%
引用构build参数,因为cmd是默认的shell。
FROM microsoft/iis ARG SOMEARG=test SHELL ["powershell", "-command"] RUN Write-Host 'HERE:';` Write-Host %SOMEARG%