Im trying to run a python3 application in a docker container using CentOS 7 as the base image. So if I'm just playing with it interactively, I type scl enable rh-python36 bash
That obviously switches my standard python2 environment to the python3.6 environment I install earlier(in the Dockerfile) Now, earlier in the dockerfile I run the following:
SHELL ["scl", "enable", "rh-python36"]
(and many variations of this)
This enables me to do all of my pip installations in this python3 environment. However, when I actually want to run my app.py with CMD, it defaults to the python2. I've tried playing with ENTRYPOINT and variations of CMD, but I cant seem to make the python3 environment active when the container finally runs. How can I get this running correctly with python3?
Here's the dockerfile:
FROM centos:7
RUN mkdir -p /usr/src/app && \
yum install -y centos-release-scl && \
yum install -y rh-python36 && \
yum install -y rh-python36-python-tkinter
SHELL ["scl", "enable", "rh-python36"]
WORKDIR /usr/src/app
COPY . .
WORKDIR /usr/src/app/codeBase
RUN pip install --no-cache-dir -r /usr/src/app/codeBase/requirements.txt
EXPOSE 9000
CMD ["python", "run.py"]
I've also tried the alias solution, but I'm afraid it doesnt change the python exe for the CMD: Here's the totally runnable version with that that still prints out python 2.7.5:
FROM centos:7
RUN mkdir -p /usr/src/app && \
yum install -y centos-release-scl && \
yum install -y rh-python36 && \
yum install -y rh-python36-python-tkinter
WORKDIR /usr/src/app
RUN alias python=$(find / -type f -name "python*" | grep "python3.6$")
CMD ["python", "-V"]
It just seems as though none of this persists in the new shell created with CMD