github.com/flavio/docker@v0.1.3-0.20170117145210-f63d1a6eec47/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:\go\src\github.com\docker\docker 49 # >> Cloning into 'C:\go\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:\go\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 run --name binaries nativebuildimage hack\make.ps1 -Binary 75 # >> docker run --name binaries -m 2GB nativebuildimage hack\make.ps1 -Binary (if using Hyper-V containers) 76 # 77 # 78 # 5. Copy the binaries out of the container, replacing HostPath with an appropriate destination 79 # folder on the host system where you want the binaries to be located. 80 # 81 # >> docker cp binaries:C:\go\src\github.com\docker\docker\bundles\docker.exe C:\HostPath\docker.exe 82 # >> docker cp binaries:C:\go\src\github.com\docker\docker\bundles\dockerd.exe C:\HostPath\dockerd.exe 83 # 84 # 85 # 6. (Optional) Remove the interim container holding the built executable binaries: 86 # 87 # >> docker rm binaries 88 # 89 # 90 # 7. (Optional) Remove the image used for the container in which the executable 91 # binaries are build. Tip - it may be useful to keep this image around if you need to 92 # build multiple times. Then you can take advantage of the builder cache to have an 93 # image which has all the components required to build the binaries already installed. 94 # 95 # >> docker rmi nativebuildimage 96 # 97 98 # ----------------------------------------------------------------------------------------- 99 100 101 # The validation tests can either run in a container, or directly on the host. To run in a 102 # container, ensure you have created the nativebuildimage above. Then run one of the 103 # following from an (elevated) Windows PowerShell prompt: 104 # 105 # >> docker run --rm nativebuildimage hack\make.ps1 -DCO -PkgImports -GoFormat 106 # >> docker run --rm -m 2GB nativebuildimage hack\make.ps1 -DCO -PkgImports -GoFormat (if using Hyper-V containers) 107 108 # To run the validation tests on the host, from the root of the repository, run the 109 # following from a Windows PowerShell prompt (elevation is not required): (Note Go 110 # must be installed to run these tests) 111 # 112 # >> hack\make.ps1 -DCO -PkgImports -GoFormat 113 114 # ----------------------------------------------------------------------------------------- 115 116 117 # To run unit tests, ensure you have created the nativebuildimage above. Then run one of 118 # the following from an (elevated) Windows PowerShell prompt: 119 # 120 # >> docker run --rm nativebuildimage hack\make.ps1 -TestUnit 121 # >> docker run --rm -m 2GB nativebuildimage hack\make.ps1 -TestUnit (if using Hyper-V containers) 122 123 124 # ----------------------------------------------------------------------------------------- 125 126 127 # To run all tests and binary build, ensure you have created the nativebuildimage above. Then 128 # run one of the following from an (elevated) Windows PowerShell prompt: 129 # 130 # >> docker run nativebuildimage hack\make.ps1 -All 131 # >> docker run -m 2GB nativebuildimage hack\make.ps1 -All (if using Hyper-V containers) 132 133 # ----------------------------------------------------------------------------------------- 134 135 136 # Important notes: 137 # --------------- 138 # 139 # Don't attempt to use a bind-mount to pass a local directory as the bundles target 140 # directory. It does not work (golang attempts for follow a mapped folder incorrectly). 141 # Instead, use docker cp as per the example. 142 # 143 # go.zip is not removed from the image as it is used by the Windows CI servers 144 # to ensure the host and image are running consistent versions of go. 145 # 146 # Nanoserver support is a work in progress. Although the image will build if the 147 # FROM statement is updated, it will not work when running autogen through hack\make.ps1. 148 # It is suspected that the required GCC utilities (eg gcc, windres, windmc) silently 149 # quit due to the use of console hooks which are not available. 150 # 151 # The docker integration tests do not currently run in a container on Windows, predominantly 152 # due to Windows not supporting privileged mode, so anything using a volume would fail. 153 # They (along with the rest of the docker CI suite) can be run using 154 # https://github.com/jhowardmsft/docker-w2wCIScripts/blob/master/runCI/Invoke-DockerCI.ps1. 155 # 156 # ----------------------------------------------------------------------------------------- 157 158 159 # The number of build steps below are explicitly minimised to improve performance. 160 FROM microsoft/windowsservercore 161 162 # Use PowerShell as the default shell 163 SHELL ["powershell", "-command"] 164 165 # Environment variable notes: 166 # - GO_VERSION must be consistent with 'Dockerfile' used by Linux. 167 # - FROM_DOCKERFILE is used for detection of building within a container. 168 ENV GO_VERSION=1.7.4 ` 169 GIT_VERSION=2.11.0 ` 170 GOPATH=C:\go ` 171 FROM_DOCKERFILE=1 172 173 RUN ` 174 $ErrorActionPreference = 'Stop'; ` 175 $ProgressPreference = 'SilentlyContinue'; ` 176 ` 177 Function Test-Nano() { ` 178 $EditionId = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name 'EditionID').EditionId; ` 179 return (($EditionId -eq 'ServerStandardNano') -or ($EditionId -eq 'ServerDataCenterNano') -or ($EditionId -eq 'NanoServer')); ` 180 }` 181 ` 182 Function Download-File([string] $source, [string] $target) { ` 183 if (Test-Nano) { ` 184 $handler = New-Object System.Net.Http.HttpClientHandler; ` 185 $client = New-Object System.Net.Http.HttpClient($handler); ` 186 $client.Timeout = New-Object System.TimeSpan(0, 30, 0); ` 187 $cancelTokenSource = [System.Threading.CancellationTokenSource]::new(); ` 188 $responseMsg = $client.GetAsync([System.Uri]::new($source), $cancelTokenSource.Token); ` 189 $responseMsg.Wait(); ` 190 if (!$responseMsg.IsCanceled) { ` 191 $response = $responseMsg.Result; ` 192 if ($response.IsSuccessStatusCode) { ` 193 $downloadedFileStream = [System.IO.FileStream]::new($target, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write); ` 194 $copyStreamOp = $response.Content.CopyToAsync($downloadedFileStream); ` 195 $copyStreamOp.Wait(); ` 196 $downloadedFileStream.Close(); ` 197 if ($copyStreamOp.Exception -ne $null) { throw $copyStreamOp.Exception } ` 198 } ` 199 } else { ` 200 Throw ("Failed to download " + $source) ` 201 }` 202 } else { ` 203 $webClient = New-Object System.Net.WebClient; ` 204 $webClient.DownloadFile($source, $target); ` 205 } ` 206 } ` 207 ` 208 setx /M PATH $('C:\git\bin;C:\git\usr\bin;'+$Env:PATH+';C:\gcc\bin;C:\go\bin'); ` 209 ` 210 Write-Host INFO: Downloading git...; ` 211 $location='https://github.com/git-for-windows/git/releases/download/v'+$env:GIT_VERSION+'.windows.1/PortableGit-'+$env:GIT_VERSION+'-64-bit.7z.exe'; ` 212 Download-File $location C:\gitsetup.7z.exe; ` 213 ` 214 Write-Host INFO: Downloading go...; ` 215 Download-File $('https://golang.org/dl/go'+$Env:GO_VERSION+'.windows-amd64.zip') C:\go.zip; ` 216 ` 217 Write-Host INFO: Downloading compiler 1 of 3...; ` 218 Download-File https://raw.githubusercontent.com/jhowardmsft/docker-tdmgcc/master/gcc.zip C:\gcc.zip; ` 219 ` 220 Write-Host INFO: Downloading compiler 2 of 3...; ` 221 Download-File https://raw.githubusercontent.com/jhowardmsft/docker-tdmgcc/master/runtime.zip C:\runtime.zip; ` 222 ` 223 Write-Host INFO: Downloading compiler 3 of 3...; ` 224 Download-File https://raw.githubusercontent.com/jhowardmsft/docker-tdmgcc/master/binutils.zip C:\binutils.zip; ` 225 ` 226 Write-Host INFO: Installing PS7Zip package...; ` 227 Install-Package PS7Zip -Force | Out-Null; ` 228 Write-Host INFO: Importing PS7Zip...; ` 229 Import-Module PS7Zip -Force; ` 230 New-Item C:\git -ItemType Directory | Out-Null ; ` 231 cd C:\git; ` 232 Write-Host INFO: Extracting git...; ` 233 Expand-7Zip C:\gitsetup.7z.exe | Out-Null; ` 234 cd C:\; ` 235 ` 236 Write-Host INFO: Expanding go...; ` 237 Expand-Archive C:\go.zip -DestinationPath C:\; ` 238 ` 239 Write-Host INFO: Expanding compiler 1 of 3...; ` 240 Expand-Archive C:\gcc.zip -DestinationPath C:\gcc -Force; ` 241 Write-Host INFO: Expanding compiler 2 of 3...; ` 242 Expand-Archive C:\runtime.zip -DestinationPath C:\gcc -Force; ` 243 Write-Host INFO: Expanding compiler 3 of 3...; ` 244 Expand-Archive C:\binutils.zip -DestinationPath C:\gcc -Force; ` 245 ` 246 Write-Host INFO: Removing downloaded files...; ` 247 Remove-Item C:\gcc.zip; ` 248 Remove-Item C:\runtime.zip; ` 249 Remove-Item C:\binutils.zip; ` 250 Remove-Item C:\gitsetup.7z.exe; ` 251 ` 252 Write-Host INFO: Creating source directory...; ` 253 New-Item -ItemType Directory -Path C:\go\src\github.com\docker\docker | Out-Null; ` 254 ` 255 Write-Host INFO: Configuring git core.autocrlf...; ` 256 C:\git\bin\git config --global core.autocrlf true; ` 257 ` 258 Write-Host INFO: Completed 259 260 # Make PowerShell the default entrypoint 261 ENTRYPOINT ["powershell.exe"] 262 263 # Set the working directory to the location of the sources 264 WORKDIR C:\go\src\github.com\docker\docker 265 266 # Copy the sources into the container 267 COPY . .