microsoft / containerregistry

Microsoft Artifact Registry description and related FAQ
398 stars 90 forks source link

Image mcr.microsoft.com/windows/nanoserver:1809 does not accept args #101

Open Antonytm opened 2 years ago

Antonytm commented 2 years ago

Description:

I am not able to pass any arguments to mcr.microsoft.com/windows/nanoserver:1809 image.

I want to build a few images based on mcr.microsoft.com/windows/nanoserver:1809 with small differences. In order to achieve it, I want to pass build arguments to my dockerbuild file. But it looks like this image doesn't accept any arguments.

Steps to reproduce:

  1. Create dockerbuild file
# escape=`

ARG BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:1809
ARG BUILD_IMAGE=mcr.microsoft.com/dotnet/framework/sdk:4.8

FROM ${BUILD_IMAGE} AS builder

ARG VAR1
ARG VAR2
RUN echo 0 $env:VAR1
RUN echo 0 $env:VAR2

FROM ${BASE_IMAGE} AS prep
ARG VAR1
ARG VAR2
RUN echo 1 $env:VAR1
RUN echo 1 $env:VAR2

FROM ${BUILD_IMAGE} AS builder1

ARG VAR1
ARG VAR2
RUN echo 2 $env:VAR1
RUN echo 2 $env:VAR2

FROM ${BASE_IMAGE} AS prep1
ARG VAR1
ARG VAR2
RUN echo 3 $env:VAR1
RUN echo 3 $env:VAR2
  1. Run docker build command:
    docker build -t test . --build-arg VAR1=var1 --build-arg VAR2=var2 --no-cache

Actual result:

Output in the console:

docker build -t test . --build-arg VAR1=var1 --build-arg VAR2=var2 --no-cache
Sending build context to Docker daemon  1.303GB
Step 1/22 : ARG BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:1809
Step 2/22 : ARG BUILD_IMAGE=mcr.microsoft.com/dotnet/framework/sdk:4.8
Step 3/22 : FROM ${BUILD_IMAGE} AS builder
 ---> c1e2ba0a9132
Step 4/22 : ARG VAR1
 ---> Running in 96128c752fd4
Removing intermediate container 96128c752fd4
 ---> ba7b625d2089
Step 5/22 : ARG VAR2
 ---> Running in 85753cea15ce
Removing intermediate container 85753cea15ce
 ---> 42f179ca9710
Step 6/22 : RUN echo 0 $env:VAR1
 ---> Running in 65a36c345cb6
0
var1
Removing intermediate container 65a36c345cb6
 ---> ed69f88c741b
Step 7/22 : RUN echo 0 $env:VAR2
 ---> Running in 7f71725a7c0e
0
var2
Removing intermediate container 7f71725a7c0e
 ---> bf1001138c3a
Step 8/22 : FROM ${BASE_IMAGE} AS prep
 ---> 8572826a0d1a
Step 9/22 : ARG VAR1
 ---> Running in 2b423174f01e
Removing intermediate container 2b423174f01e
 ---> 2167dac1186a
Step 10/22 : ARG VAR2
 ---> Running in 4b1b1a1a2376
Removing intermediate container 4b1b1a1a2376
 ---> ea69eaae1bb9
Step 11/22 : RUN echo 1 $env:VAR1
 ---> Running in e1575f42aa54
1 $env:VAR1
Removing intermediate container e1575f42aa54
 ---> 40a421cbe548
Step 12/22 : RUN echo 1 $env:VAR2
 ---> Running in 8a05a0e97768
1 $env:VAR2
Removing intermediate container 8a05a0e97768
 ---> 404f282eb976
Step 13/22 : FROM ${BUILD_IMAGE} AS builder1
 ---> c1e2ba0a9132
Step 14/22 : ARG VAR1
 ---> Running in 4a0a3af54835
Removing intermediate container 4a0a3af54835
 ---> 538b27cd58ac
Step 15/22 : ARG VAR2
 ---> Running in e04cdd0c33f5
Removing intermediate container e04cdd0c33f5
 ---> 9bf9eae1a4ca
Step 16/22 : RUN echo 2 $env:VAR1
 ---> Running in c65676db5e70
2
var1
Removing intermediate container c65676db5e70
 ---> dc568a106c37
Step 17/22 : RUN echo 2 $env:VAR2
 ---> Running in 3deee036ba34
2
var2
Removing intermediate container 3deee036ba34
 ---> 578febf2aa29
Step 18/22 : FROM ${BASE_IMAGE} AS prep1
 ---> 8572826a0d1a
Step 19/22 : ARG VAR1
 ---> Running in 846faa98698f
 ---> ebb85740313c
Step 20/22 : ARG VAR2
 ---> Running in 40f9e6d77dab
Removing intermediate container 40f9e6d77dab
 ---> 2b7ad10e4e2c
Step 21/22 : RUN echo 1 $env:VAR1
 ---> Running in d0167dd0960e
1 $env:VAR1
Removing intermediate container d0167dd0960e
 ---> 84678a808687
Step 22/22 : RUN echo 1 $env:VAR2
 ---> Running in ceb3be2fb973
1 $env:VAR2
Removing intermediate container ceb3be2fb973
 ---> fa19470530ff
Successfully built fa19470530ff
Successfully tagged test:latest

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
PS C:\source\Dianoga> docker build -t test . --build-arg VAR1=var1 --build-arg VAR2=var2 --no-cache
Sending build context to Docker daemon  1.303GB
Step 1/22 : ARG BASE_IMAGE=mcr.microsoft.com/windows/nanoserver:1809
Step 2/22 : ARG BUILD_IMAGE=mcr.microsoft.com/dotnet/framework/sdk:4.8
Step 3/22 : FROM ${BUILD_IMAGE} AS builder
 ---> c1e2ba0a9132
Step 4/22 : ARG VAR1
 ---> Running in cc153b16356f
Removing intermediate container cc153b16356f
 ---> 2964d7d90875
Step 5/22 : ARG VAR2
 ---> Running in c0b03ad3c19a
Removing intermediate container c0b03ad3c19a
 ---> 872ae9e7c557
Step 6/22 : RUN echo 0 $env:VAR1
 ---> Running in b309495ff690
0
var1
Removing intermediate container b309495ff690
 ---> 95fe4796e0f3
Step 7/22 : RUN echo 0 $env:VAR2
 ---> Running in d17e2c81b149
0
var2
Removing intermediate container d17e2c81b149
 ---> 226b1cb33cd1
Step 8/22 : FROM ${BASE_IMAGE} AS prep
 ---> 8572826a0d1a
Step 9/22 : ARG VAR1
 ---> Running in b764e10bfa3f
Removing intermediate container b764e10bfa3f
 ---> 3be22846ca1e
Step 10/22 : ARG VAR2
 ---> Running in ebdd2cfc000c
Removing intermediate container ebdd2cfc000c
 ---> b4c438d0b6a4
Step 11/22 : RUN echo 1 $env:VAR1
 ---> Running in 0dd8728ca1e7
1 $env:VAR1
Removing intermediate container 0dd8728ca1e7
 ---> 9d0fb558cea7
Step 12/22 : RUN echo 1 $env:VAR2
 ---> Running in 83de57691bf9
1 $env:VAR2
Removing intermediate container 83de57691bf9
 ---> 8fef4f2e3fe4
Step 13/22 : FROM ${BUILD_IMAGE} AS builder1
 ---> c1e2ba0a9132
Step 14/22 : ARG VAR1
 ---> Running in abc0203b4f2a
Removing intermediate container abc0203b4f2a
 ---> 8fa3ec8c07f8
Step 15/22 : ARG VAR2
 ---> Running in 0a5bfe443aeb
Removing intermediate container 0a5bfe443aeb
 ---> 31279c670f5b
Step 16/22 : RUN echo 2 $env:VAR1
 ---> Running in bebdffbf200c
2
var1
Removing intermediate container bebdffbf200c
 ---> 8d9b69c6cd75
Step 17/22 : RUN echo 2 $env:VAR2
 ---> Running in 1179815f27c9
2
var2
Removing intermediate container 1179815f27c9
 ---> 8ab40813ce73
Step 18/22 : FROM ${BASE_IMAGE} AS prep1
 ---> 8572826a0d1a
Step 19/22 : ARG VAR1
 ---> Running in 7e165014efb9
Removing intermediate container 7e165014efb9
 ---> 37bb3f12da37
Step 20/22 : ARG VAR2
 ---> Running in 0a1a0818b3bd
Removing intermediate container 0a1a0818b3bd
 ---> 858263f9dd72
Step 21/22 : RUN echo 3 $env:VAR1
 ---> Running in 918a9c3e66bd
3 $env:VAR1
Removing intermediate container 918a9c3e66bd
 ---> 8e056313a772
Step 22/22 : RUN echo 3 $env:VAR2
 ---> Running in 7ca95ee8addb
3 $env:VAR2
Removing intermediate container 7ca95ee8addb
 ---> fffd574af7bb
Successfully built fffd574af7bb
Successfully tagged test:latest

Steps with mcr.microsoft.com/windows/nanoserver:1809 image don't accept any args. Neither VAR1, nor VAR2 could not be accessed in step with that image.

Expected result:

Steps with mcr.microsoft.com/windows/nanoserver:1809 image should accept arg in the same way as mcr.microsoft.com/dotnet/framework/sdk:4.8.

Antonytm commented 2 years ago

I figured out how to achieve what I need. If mcr.microsoft.com/windows/nanoserver:1809 is used then arguments should be used in %arg% format. If mcr.microsoft.com/dotnet/framework/sdk:4.8 is used then arguments should be used in $env:arg format.

Is this difference documented anywhere?