Skip to content

Commit af903f0

Browse files
committed
Use multi-stage build for Python
1 parent b1c21a6 commit af903f0

3 files changed

Lines changed: 16 additions & 40 deletions

File tree

python/Dockerfile

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1+
# escape=`
2+
FROM python:3.6-windowsservercore AS python
3+
14
FROM microsoft/nanoserver
25

6+
COPY --from=python /Python /Python
7+
38
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
49

510
ENV PYTHON_VERSION 3.6.1
611
ENV PYTHON_PIP_VERSION 9.0.1
712

8-
RUN Invoke-WebRequest $('https://www.python.org/ftp/python/{0}/python-{0}-embed-amd64.zip' -f $env:PYTHON_VERSION) -OutFile 'python.zip' -UseBasicParsing ; \
9-
Expand-Archive python.zip -DestinationPath C:\python ; \
10-
$env:PATH = 'C:\python;C:\python\Scripts;{0}' -f $env:PATH ; \
11-
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\' -Name Path -Value $env:PATH ; \
12-
Remove-Item -Path python.zip ; \
13-
mkdir $env:APPDATA\Python\Python36\site-packages ; \
14-
Invoke-WebRequest 'https://bootstrap.pypa.io/get-pip.py' -OutFile 'get-pip.py' -UseBasicParsing ; \
15-
$replace = ('import tempfile{0}import site{0}site.getusersitepackages()' -f [char][int]10) ; \
16-
Get-Content get-pip.py | Foreach-Object { $_ -replace 'import tempfile', $replace } | Out-File -Encoding Ascii getpip.py ; \
17-
$pipInstall = ('pip=={0}' -f $env:PYTHON_PIP_VERSION) ; \
18-
python getpip.py $pipInstall ; \
19-
Remove-Item get-pip.py ; \
13+
RUN $env:PATH = 'C:\Python;C:\Python\Scripts;{0}' -f $env:PATH ; `
14+
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\' -Name Path -Value $env:PATH ; `
15+
mkdir $env:APPDATA\Python\Python36\site-packages ; `
16+
Invoke-WebRequest 'https://bootstrap.pypa.io/get-pip.py' -OutFile 'get-pip.py' -UseBasicParsing ; `
17+
$replace = ('import tempfile{0}import site{0}site.getusersitepackages()' -f [char][int]10) ; `
18+
Get-Content get-pip.py | Foreach-Object { $_ -replace 'import tempfile', $replace } | Out-File -Encoding Ascii getpip.py ; `
19+
$pipInstall = ('pip=={0}' -f $env:PYTHON_PIP_VERSION) ; `
20+
python getpip.py $pipInstall ; `
21+
Remove-Item get-pip.py ; `
2022
Remove-Item getpip.py
2123
2224
RUN pip install --no-cache-dir virtualenv

python/Dockerfile.build

Lines changed: 0 additions & 22 deletions
This file was deleted.

python/build.ps1

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# docker build -t python .
1+
. $PSScriptRoot\..\update-docker-ce.ps1
22

3-
# docker rm -f pythonbuild36 2>&1
4-
docker pull python:3.6-windowsservercore
5-
docker create --name=pythonbuild36 python:3.6-windowsservercore
6-
docker cp pythonbuild36:Python tmp
7-
docker build -t python -f Dockerfile.build .
3+
docker build -t python .

0 commit comments

Comments
 (0)