0

I have made a programming model in python 2.7 version and want to run it on Centos 6.8 version by using it in a Docker File.

At present there is two version of python in my Docker File:

  1. 2.6.6 (Default cannot remove )
  2. 2.7.8

But when I start to install the libraries by using pip it gets installed in the python 2.6 version

I want to make a Docker file such that a person doesn't need to manually go into the container and create a system link to use it.

It should be all included in the Docker file itself. Is there anyone who can give me a clear idea how this is possible in Centos 6 only.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Rituraj kumar
  • 349
  • 1
  • 4
  • 15
  • 1
    Why does it need to be Centos 6? And why can't you use the existing Python images? – OneCricketeer Feb 21 '18 at 09:18
  • In any case, the default Python is on the PATH first. This has nothing to do with CentOS 6. https://stackoverflow.com/questions/27093612/in-a-dockerfile-how-to-update-path-environment-variable/27096550 – OneCricketeer Feb 21 '18 at 09:21
  • @ cricket_007 Because we already have a pre-existing system in that environment. – Rituraj kumar Feb 21 '18 at 10:17

1 Answers1

2

You want to install python 2.7 inside the Dockerfile ?

FROM centos:6.8

RUN yum -y update
RUN yum install -y epel-release && yum groupinstall -y 'development tools'
RUN yum install -y zlib-dev openssl-devel sqlite-devel bzip2-devel xz-libs wget
RUN wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz
RUN tar xvfJ Python-2.7.8.tar.xz
WORKDIR Python-2.7.8
RUN ./configure --prefix=/usr/local && make && make altinstall
RUN curl https://bootstrap.pypa.io/get-pip.py | python2.7

Inside this container the version 2.6.6 still as default, to use python 2.7.8 you have to specify explicitly python2.7:

[root@79f3f51d0000 ~]# which python
/usr/bin/python
[root@79f3f51d0000 ~]# which python2.7
/usr/local/bin/python2.7
[root@79f3f51d0000 ~]# which pip2.7
/usr/local/bin/pip2.7
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
ibt23sec5
  • 369
  • 3
  • 13
  • Should `make altinstall` already run the default make target? – OneCricketeer Feb 21 '18 at 10:28
  • But when I am installing libraries through pip it goes in the python2.6 version package file. Is there a way to install all the libraries in the python2.7 version package? – Rituraj kumar Feb 21 '18 at 10:32
  • 1
    @Riturajkumar Only Python 2.7.9+ come with `pip` pre-installed. You need to install pip separately with 2.7.8 – OneCricketeer Feb 21 '18 at 10:43
  • @cricket_007 Can you please specify how do you installed pip separately with 2.7.8. As I was unable to install pip to specific python 2.7 version? – Rituraj kumar Feb 21 '18 at 10:50
  • 1
    @Riturajkumar There is a page specifically for that. Replace `python` with `python2.7` https://pip.pypa.io/en/stable/installing/ – OneCricketeer Feb 21 '18 at 10:54
  • @Riturajkumar: Install pip from pip.pypa.io as @cricket_007 says and install it with python2.7: `python2.7 get-pip.py`. You'll have another pip version to choose in `/usr/local/bin/pip2.7` – ibt23sec5 Feb 21 '18 at 10:58
  • @ibt23sec5 I am getting an error when running this command python2.7 get-pip.py. Error: python2.7: can't open file 'get-pip.py': [Errno 2] No such file or directory – Rituraj kumar Feb 21 '18 at 11:08
  • @Riturajkumar: Did you download the get-pip.py file before? cricket_007 has updated the Dockerfile content, it should work with. – ibt23sec5 Feb 21 '18 at 11:12
  • Thanks for the guidance it really helped a lot to me. – Rituraj kumar Feb 21 '18 at 11:28