Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install Python into Windows Docker container

Tags:

python

docker

I want to create a docker container using base image mcr.microsoft.com/dotnet/framework/runtime:4.8.1 but I also need Python on here. Unfortunately the official Python images only use windowsservercore. What do I put in my Dockerfile to make this happen? All the documentation I see are either for linux/unix or require manually downloading an exe beforehand.

like image 527
wheeeee Avatar asked Oct 19 '25 19:10

wheeeee


1 Answers

You can add installer file and trigger it from powershell with proper commands. There is documentation on how to do it: https://docs.python.org/3.10/using/windows.html#installing-without-ui

Here is the code I have used

ADD https://www.python.org/ftp/python/3.10.11/python-3.10.11-amd64.exe C:/python3.exe
RUN powershell -Command \
  $ErrorActionPreference = 'Stop'; \
  Start-Process c:\python3.exe -ArgumentList '/quiet InstallAllUsers=1 PrependPath=1' -Wait ; \
  Remove-Item c:\python3.exe -Force
like image 73
TheBigvi Avatar answered Oct 22 '25 08:10

TheBigvi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!