gopkg.in/docker/docker.v23@v23.0.11/Dockerfile.windows (about)

     1  # escape=`
     2  
     3  # -----------------------------------------------------------------------------------------
     4  # This file describes the standard way to build Docker in a container on Windows
     5  # Server 2016 or Windows 10.
     6  #
     7  # Maintainer: @jhowardmsft
     8  # -----------------------------------------------------------------------------------------
     9  
    10  
    11  # Prerequisites:
    12  # --------------
    13  #
    14  # 1. Windows Server 2016 or Windows 10 with all Windows updates applied. The major 
    15  #    build number must be at least 14393. This can be confirmed, for example, by 
    16  #    running the following from an elevated PowerShell prompt - this sample output 
    17  #    is from a fully up to date machine as at mid-November 2016:
    18  #
    19  #    >> PS C:\> $(gin).WindowsBuildLabEx
    20  #    >> 14393.447.amd64fre.rs1_release_inmarket.161102-0100
    21  #
    22  # 2. Git for Windows (or another git client) must be installed. https://git-scm.com/download/win.
    23  #
    24  # 3. The machine must be configured to run containers. For example, by following
    25  #    the quick start guidance at https://msdn.microsoft.com/en-us/virtualization/windowscontainers/quick_start/quick_start or
    26  #    https://github.com/docker/labs/blob/master/windows/windows-containers/Setup.md
    27  #
    28  # 4. If building in a Hyper-V VM: For Windows Server 2016 using Windows Server
    29  #    containers as the default option, it is recommended you have at least 1GB 
    30  #    of memory assigned; For Windows 10 where Hyper-V Containers are employed, you
    31  #    should have at least 4GB of memory assigned. Note also, to run Hyper-V 
    32  #    containers in a VM, it is necessary to configure the VM for nested virtualization.
    33  
    34  # -----------------------------------------------------------------------------------------
    35  
    36  
    37  # Usage:
    38  # -----
    39  #
    40  #  The following steps should be run from an (elevated*) Windows PowerShell prompt. 
    41  #
    42  #  (*In a default installation of containers on Windows following the quick-start guidance at
    43  #    https://msdn.microsoft.com/en-us/virtualization/windowscontainers/quick_start/quick_start,
    44  #    the docker.exe client must run elevated to be able to connect to the daemon).
    45  #
    46  # 1. Clone the sources from github.com:
    47  #
    48  #    >>   git clone https://github.com/docker/docker.git C:\gopath\src\github.com\docker\docker
    49  #    >>   Cloning into 'C:\gopath\src\github.com\docker\docker'...
    50  #    >>   remote: Counting objects: 186216, done.
    51  #    >>   remote: Compressing objects: 100% (21/21), done.
    52  #    >>   remote: Total 186216 (delta 5), reused 0 (delta 0), pack-reused 186195
    53  #    >>   Receiving objects: 100% (186216/186216), 104.32 MiB | 8.18 MiB/s, done.
    54  #    >>   Resolving deltas: 100% (123139/123139), done.
    55  #    >>   Checking connectivity... done.
    56  #    >>   Checking out files: 100% (3912/3912), done.
    57  #    >>   PS C:\>
    58  #
    59  #
    60  # 2. Change directory to the cloned docker sources:
    61  #
    62  #    >>   cd C:\gopath\src\github.com\docker\docker 
    63  #
    64  #
    65  # 3. Build a docker image with the components required to build the docker binaries from source
    66  #    by running one of the following:
    67  #
    68  #    >>   docker build -t nativebuildimage -f Dockerfile.windows .          
    69  #    >>   docker build -t nativebuildimage -f Dockerfile.windows -m 2GB .    (if using Hyper-V containers)
    70  #
    71  #
    72  # 4. Build the docker executable binaries by running one of the following:
    73  #
    74  #    >>   $DOCKER_GITCOMMIT=(git rev-parse --short HEAD)
    75  #    >>   docker run --name binaries -e DOCKER_GITCOMMIT=$DOCKER_GITCOMMIT nativebuildimage hack\make.ps1 -Binary
    76  #    >>   docker run --name binaries -e DOCKER_GITCOMMIT=$DOCKER_GITCOMMIT -m 2GB nativebuildimage hack\make.ps1 -Binary    (if using Hyper-V containers)
    77  #
    78  #
    79  # 5. Copy the binaries out of the container, replacing HostPath with an appropriate destination 
    80  #    folder on the host system where you want the binaries to be located.
    81  #
    82  #    >>   docker cp binaries:C:\gopath\src\github.com\docker\docker\bundles\docker.exe C:\HostPath\docker.exe
    83  #    >>   docker cp binaries:C:\gopath\src\github.com\docker\docker\bundles\dockerd.exe C:\HostPath\dockerd.exe
    84  #
    85  #
    86  # 6. (Optional) Remove the interim container holding the built executable binaries:
    87  #
    88  #    >>    docker rm binaries
    89  #
    90  #
    91  # 7. (Optional) Remove the image used for the container in which the executable
    92  #    binaries are build. Tip - it may be useful to keep this image around if you need to
    93  #    build multiple times. Then you can take advantage of the builder cache to have an
    94  #    image which has all the components required to build the binaries already installed.
    95  #
    96  #    >>    docker rmi nativebuildimage
    97  #
    98  
    99  # -----------------------------------------------------------------------------------------
   100  
   101  
   102  #  The validation tests can only run directly on the host. This is because they calculate
   103  #  information from the git repo, but the .git directory is not passed into the image as
   104  #  it is excluded via .dockerignore. Run the following from a Windows PowerShell prompt
   105  #  (elevation is not required): (Note Go must be installed to run these tests)
   106  #
   107  #    >>   hack\make.ps1 -DCO -PkgImports -GoFormat
   108  
   109  
   110  # -----------------------------------------------------------------------------------------
   111  
   112  
   113  #  To run unit tests, ensure you have created the nativebuildimage above. Then run one of
   114  #  the following from an (elevated) Windows PowerShell prompt:
   115  #
   116  #    >>   docker run --rm nativebuildimage hack\make.ps1 -TestUnit
   117  #    >>   docker run --rm -m 2GB nativebuildimage hack\make.ps1 -TestUnit    (if using Hyper-V containers)
   118  
   119  
   120  # -----------------------------------------------------------------------------------------
   121  
   122  
   123  #  To run unit tests and binary build, ensure you have created the nativebuildimage above. Then 
   124  #  run one of the following from an (elevated) Windows PowerShell prompt:
   125  #
   126  #    >>   docker run nativebuildimage hack\make.ps1 -All
   127  #    >>   docker run -m 2GB nativebuildimage hack\make.ps1 -All    (if using Hyper-V containers)
   128  
   129  # -----------------------------------------------------------------------------------------
   130  
   131  
   132  # Important notes:
   133  # ---------------
   134  #
   135  # Don't attempt to use a bind mount to pass a local directory as the bundles target
   136  # directory. It does not work (golang attempts for follow a mapped folder incorrectly).
   137  # Instead, use docker cp as per the example.
   138  #
   139  # go.zip is not removed from the image as it is used by the Windows CI servers
   140  # to ensure the host and image are running consistent versions of go.
   141  #
   142  # Nanoserver support is a work in progress. Although the image will build if the 
   143  # FROM statement is updated, it will not work when running autogen through hack\make.ps1. 
   144  # It is suspected that the required GCC utilities (eg gcc, windres, windmc) silently
   145  # quit due to the use of console hooks which are not available.
   146  #
   147  # The docker integration tests do not currently run in a container on Windows, predominantly
   148  # due to Windows not supporting privileged mode, so anything using a volume would fail.
   149  # They (along with the rest of the docker CI suite) can be run using 
   150  # https://github.com/kevpar/docker-w2wCIScripts/blob/master/runCI/Invoke-DockerCI.ps1.
   151  #
   152  # -----------------------------------------------------------------------------------------
   153  
   154  
   155  # The number of build steps below are explicitly minimised to improve performance.
   156  
   157  # Extremely important - do not change the following line to reference a "specific" image, 
   158  # such as `mcr.microsoft.com/windows/servercore:ltsc2022`. If using this Dockerfile in process
   159  # isolated containers, the kernel of the host must match the container image, and hence
   160  # would fail between Windows Server 2016 (aka RS1) and Windows Server 2019 (aka RS5).
   161  # It is expected that the image `microsoft/windowsservercore:latest` is present, and matches
   162  # the hosts kernel version before doing a build. 
   163  FROM microsoft/windowsservercore
   164  
   165  # Use PowerShell as the default shell
   166  SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
   167  
   168  ARG GO_VERSION=1.20.13
   169  ARG GOTESTSUM_VERSION=v1.8.2
   170  ARG GOWINRES_VERSION=v0.3.0
   171  ARG CONTAINERD_VERSION=v1.6.28
   172  
   173  # Environment variable notes:
   174  #  - GO_VERSION must be consistent with 'Dockerfile' used by Linux.
   175  #  - CONTAINERD_VERSION must be consistent with 'hack/dockerfile/install/containerd.installer' used by Linux.
   176  #  - FROM_DOCKERFILE is used for detection of building within a container.
   177  ENV GO_VERSION=${GO_VERSION} `
   178      CONTAINERD_VERSION=${CONTAINERD_VERSION} `
   179      GIT_VERSION=2.11.1 `
   180      GOPATH=C:\gopath `
   181      GO111MODULE=off `
   182      FROM_DOCKERFILE=1 `
   183      GOTESTSUM_VERSION=${GOTESTSUM_VERSION} `
   184      GOWINRES_VERSION=${GOWINRES_VERSION}
   185  
   186  RUN `
   187    Function Test-Nano() { `
   188      $EditionId = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name 'EditionID').EditionId; `
   189      return (($EditionId -eq 'ServerStandardNano') -or ($EditionId -eq 'ServerDataCenterNano') -or ($EditionId -eq 'NanoServer')); `
   190    }`
   191    `
   192    Function Download-File([string] $source, [string] $target) { `
   193      if (Test-Nano) { `
   194        $handler = New-Object System.Net.Http.HttpClientHandler; `
   195        $client = New-Object System.Net.Http.HttpClient($handler); `
   196        $client.Timeout = New-Object System.TimeSpan(0, 30, 0); `
   197        $cancelTokenSource = [System.Threading.CancellationTokenSource]::new(); `
   198        $responseMsg = $client.GetAsync([System.Uri]::new($source), $cancelTokenSource.Token); `
   199        $responseMsg.Wait(); `
   200        if (!$responseMsg.IsCanceled) { `
   201          $response = $responseMsg.Result; `
   202          if ($response.IsSuccessStatusCode) { `
   203            $downloadedFileStream = [System.IO.FileStream]::new($target, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write); `
   204            $copyStreamOp = $response.Content.CopyToAsync($downloadedFileStream); `
   205            $copyStreamOp.Wait(); `
   206            $downloadedFileStream.Close(); `
   207            if ($copyStreamOp.Exception -ne $null) { throw $copyStreamOp.Exception } `
   208          } `
   209        } else { `
   210        Throw ("Failed to download " + $source) `
   211        }`
   212      } else { `
   213        [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; `
   214        $webClient = New-Object System.Net.WebClient; `
   215        $webClient.DownloadFile($source, $target); `
   216      } `
   217    } `
   218    `
   219    setx /M PATH $('C:\git\cmd;C:\git\usr\bin;'+$Env:PATH+';C:\gcc\bin;C:\go\bin;C:\containerd\bin'); `
   220    `
   221    Write-Host INFO: Downloading git...; `
   222    $location='https://www.nuget.org/api/v2/package/GitForWindows/'+$Env:GIT_VERSION; `
   223    Download-File $location C:\gitsetup.zip; `
   224    `
   225    Write-Host INFO: Downloading go...; `
   226    $dlGoVersion=$Env:GO_VERSION -replace '\.0$',''; `
   227    Download-File "https://go.dev/dl/go${dlGoVersion}.windows-amd64.zip" C:\go.zip; `
   228    `
   229    Write-Host INFO: Downloading compiler 1 of 3...; `
   230    Download-File https://raw.githubusercontent.com/moby/docker-tdmgcc/master/gcc.zip C:\gcc.zip; `
   231    `
   232    Write-Host INFO: Downloading compiler 2 of 3...; `
   233    Download-File https://raw.githubusercontent.com/moby/docker-tdmgcc/master/runtime.zip C:\runtime.zip; `
   234    `
   235    Write-Host INFO: Downloading compiler 3 of 3...; `
   236    Download-File https://raw.githubusercontent.com/moby/docker-tdmgcc/master/binutils.zip C:\binutils.zip; `
   237    `
   238    Write-Host INFO: Extracting git...; `
   239    Expand-Archive C:\gitsetup.zip C:\git-tmp; `
   240    New-Item -Type Directory C:\git | Out-Null; `
   241    Move-Item C:\git-tmp\tools\* C:\git\.; `
   242    Remove-Item -Recurse -Force C:\git-tmp; `
   243    `
   244    Write-Host INFO: Expanding go...; `
   245    Expand-Archive C:\go.zip -DestinationPath C:\; `
   246    `
   247    Write-Host INFO: Expanding compiler 1 of 3...; `
   248    Expand-Archive C:\gcc.zip -DestinationPath C:\gcc -Force; `
   249    Write-Host INFO: Expanding compiler 2 of 3...; `
   250    Expand-Archive C:\runtime.zip -DestinationPath C:\gcc -Force; `
   251    Write-Host INFO: Expanding compiler 3 of 3...; `
   252    Expand-Archive C:\binutils.zip -DestinationPath C:\gcc -Force; `
   253    `
   254    Write-Host INFO: Removing downloaded files...; `
   255    Remove-Item C:\gcc.zip; `
   256    Remove-Item C:\runtime.zip; `
   257    Remove-Item C:\binutils.zip; `
   258    Remove-Item C:\gitsetup.zip; `
   259    `
   260    Write-Host INFO: Downloading containerd; `
   261    Install-Package -Force 7Zip4PowerShell; `
   262    $location='https://github.com/containerd/containerd/releases/download/'+$Env:CONTAINERD_VERSION+'/containerd-'+$Env:CONTAINERD_VERSION.TrimStart('v')+'-windows-amd64.tar.gz'; `
   263    Download-File $location C:\containerd.tar.gz; `
   264    New-Item -Path C:\containerd -ItemType Directory; `
   265    Expand-7Zip C:\containerd.tar.gz C:\; `
   266    Expand-7Zip C:\containerd.tar C:\containerd; `
   267    Remove-Item C:\containerd.tar.gz; `
   268    Remove-Item C:\containerd.tar; `
   269    `
   270    # Ensure all directories exist that we will require below....
   271    $srcDir = """$Env:GOPATH`\src\github.com\docker\docker\bundles"""; `
   272    Write-Host INFO: Ensuring existence of directory $srcDir...; `
   273    New-Item -Force -ItemType Directory -Path $srcDir | Out-Null; `
   274    `
   275    Write-Host INFO: Configuring git core.autocrlf...; `
   276    C:\git\cmd\git config --global core.autocrlf true;
   277  
   278  RUN `
   279    Function Install-GoTestSum() { `
   280      $Env:GO111MODULE = 'on'; `
   281      $tmpGobin = "${Env:GOBIN_TMP}"; `
   282      $Env:GOBIN = """${Env:GOPATH}`\bin"""; `
   283      Write-Host "INFO: Installing gotestsum version $Env:GOTESTSUM_VERSION in $Env:GOBIN"; `
   284      &go install "gotest.tools/gotestsum@${Env:GOTESTSUM_VERSION}"; `
   285      $Env:GOBIN = "${tmpGobin}"; `
   286      $Env:GO111MODULE = 'off'; `
   287      if ($LASTEXITCODE -ne 0) {  `
   288        Throw '"gotestsum install failed..."'; `
   289      } `
   290    } `
   291    `
   292    Install-GoTestSum
   293  
   294  RUN `
   295    Function Install-GoWinres() { `
   296      $Env:GO111MODULE = 'on'; `
   297      $tmpGobin = "${Env:GOBIN_TMP}"; `
   298      $Env:GOBIN = """${Env:GOPATH}`\bin"""; `
   299      Write-Host "INFO: Installing go-winres version $Env:GOWINRES_VERSION in $Env:GOBIN"; `
   300      &go install "github.com/tc-hib/go-winres@${Env:GOWINRES_VERSION}"; `
   301      $Env:GOBIN = "${tmpGobin}"; `
   302      $Env:GO111MODULE = 'off'; `
   303      if ($LASTEXITCODE -ne 0) {  `
   304        Throw '"go-winres install failed..."'; `
   305      } `
   306    } `
   307    `
   308    Install-GoWinres
   309  
   310  # Make PowerShell the default entrypoint
   311  ENTRYPOINT ["powershell.exe"]
   312  
   313  # Set the working directory to the location of the sources
   314  WORKDIR ${GOPATH}\src\github.com\docker\docker
   315  
   316  # Copy the sources into the container
   317  COPY . .