Here is a Dockerfile that will install Python 3.6.8 (latest) on a docker image based on the rocker/r-ver:3.5.1 docker image. I piped the output of some of the build commands to /dev/nullto reduce the output.
Took 3+ minutes for the entire operation on my Mac running Docker for MacOS.
After you build the image you can then use that image as your base for your application or just add the necessary items to the Dockerfile to build your application in the same build.
🐳 gforghetti:[~/Downloads] $ time docker image build -t my-image:latest .
Sending build context to Docker daemon 12.29kB
Step 1/5 : FROM rocker/r-ver:3.5.1
3.5.1: Pulling from rocker/r-ver
ab1fc7e4bf91: Pull complete
9eb003a6d293: Pull complete
Digest: sha256:0ed82c6efe24b84c4ec7d057ddd797776507669e239c100099916c73dd9b3e25
Status: Downloaded newer image for rocker/r-ver:3.5.1
---> 2f4fb476bd2e
Step 2/5 : ARG BUILDDIR="/tmp/build"
---> Running in 51f0817af41c
Removing intermediate container 51f0817af41c
---> 15571792882b
Step 3/5 : ARG PYTHON_VER="3.6.8"
---> Running in 4ef9c70e6ac8
Removing intermediate container 4ef9c70e6ac8
---> b0f5b5cff7cc
Step 4/5 : WORKDIR ${BUILDDIR}
---> Running in 2169201c4edb
Removing intermediate container 2169201c4edb
---> 13f79af467b9
Step 5/5 : RUN apt-get update -qq && apt-get upgrade -y > /dev/null 2>&1 && apt-get install wget gcc make zlib1g-dev -y -qq > /dev/null 2>&1 && wget --quiet https://www.python.org/ftp/python/${PYTHON_VER}/Python-${PYTHON_VER}.tgz > /dev/null 2>&1 && tar zxf Python-${PYTHON_VER}.tgz && cd Python-${PYTHON_VER} && ./configure > /dev/null 2>&1 && make > /dev/null 2>&1 && make install > /dev/null 2>&1 && rm -rf ${BUILDDIR}
---> Running in cc2e41b5e889
Removing intermediate container cc2e41b5e889
---> 315590f14d8b
Successfully built 315590f14d8b
Successfully tagged my-image:latest
real 3m16.401s
user 0m0.083s
sys 0m0.054s
🐳 gforghetti:[~/Downloads] $ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
my-image latest 315590f14d8b 6 minutes ago 807MB
rocker/r-ver 3.5.1 2f4fb476bd2e 9 days ago 604MB
🐳 gforghetti:[~/Downloads] $ docker container run -it my-image:latest python3 --version
Python 3.6.8
🐳 gforghetti:[~/Downloads] $
Good one! Really nice work getting this working. I can verify that this works. And if you do not run the test, it takes a lot less time. But… you alway run the tests, right?
Using the new Buildkit build enhancements available in Docker 18.09 I was able to reduce the build time down from 3m16.401s to 2m32.925s.
Buildkit is experimental and is only supported on Docker Linux engines. You must set “experimental” mode in the Docker daemon and your client. It has some performance improvements and some other “experimental” functions.
Python 3.6.8 was the eighth and last maintenance release of Python 3.6.
Note
There are now newer security-fix releases of Python 3.6 that supersede 3.6.8 and Python 3.8 is now the latest feature release of Python 3. Get the latest releases of 3.6.x and 3.8.x here. Python 3.6.8 is planned to be the last bugfix release for 3.6.x. Following the release of 3.6.8, we plan to provide security fixes for Python 3.6 as needed through 2021, five years following its initial release. Learn for more https://onlineitguru.com/python-training.html