Docker Community Forums

Share and learn in the Docker community.

How can I install python 3.6 version on top of R

I’m trying to to build a docker image for machine learning package based on python version 3.6 and R for deep learning and other machine learning.

I’m struggling install python version 3.6 on top of ‘rocker/r-ver:3.5.1’ image, which can be used in R through reticulate package.

rocker/r-ver:3.5.1 image is based on debian:stretch. Does anyone have an idea for this?

There is no python3.6 in the debian stretch repository but you can find it in the testing repository.


Or you can build it from source but that takes ages.

@ovelindstrom Thank you for the helpful answer!!


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.


FROM rocker/r-ver:3.5.1
ARG BUILDDIR="/tmp/build"

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${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} 


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
 ---> 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${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? :wink:

Hi Ove.

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.

Some links on Buildkit:


🐳  gforghetti:[~/Downloads] $ export DOCKER_BUILDKIT=1
🐳  gforghetti:[~/Downloads] $ time docker image build -t my-image:latest .
[+] Building 152.9s (6/6) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                   0.0s
 => => transferring dockerfile: 560B                                                                                                                                                                   0.0s
 => [internal] load .dockerignore                                                                                                                                                                      0.0s
 => => transferring context: 2B                                                                                                                                                                        0.0s
 => [internal] load metadata for                                                                                                                                            0.9s
 => [1/2] FROM                                                                                      3.5s
 => => resolve                                                                                      0.0s
 => => sha256:741437d97401b83849ccbfe4ed8964049b752081647d7f1ea8aea29d989f8968 45.34MB / 45.34MB                                                                                                       1.7s
 => => sha256:066051f6674f6a3293bbd5a190081b1ae7fcae655a3884db59ebb3a2831da623 2.36kB / 2.36kB                                                                                                         0.0s
 => => sha256:92cfa9da19ed9dd7683efbf25a5e2e3a15256dd88f224d0a1f907bfa1fb12ad1 529B / 529B                                                                                                             0.0s
 => => sha256:d508d16c64cd269a838aca07b4823d6271963e7f60c2ecaebe62b7f33d1f0842 1.50kB / 1.50kB                                                                                                         0.0s
 => => extracting sha256:741437d97401b83849ccbfe4ed8964049b752081647d7f1ea8aea29d989f8968                                                                                                              1.5s
 => [2/2] 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  146.3s
 => exporting to image                                                                                                                                                                                 2.0s
 => => exporting layers                                                                                                                                                                                2.0s
 => => writing image sha256:656a1d548a9795af6ddf9939debdb9c71f0eb0ea8ef71144e4e7740cfed7099e                                                                                                           0.0s
 => => naming to                                                                                                                                                     0.0s

real	2m32.925s
user	0m0.488s
sys	0m0.278s```
1 Like

If you want to install python latest version then you can get it from google still you facing an issue then you can come and get from experts.

Python 3.6.8 was the eighth and last maintenance release of Python 3.6.


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

For python version 2.x you can simply use

pip install pillow
But for python version 3.X you need to specify

(sudo) pip3 install pillow
when you enter pip in bash hit tab and you will see what options you have