1、 install python3
Here's one bug, because centos System comes with python2, and python The soft connection of is the default point to python2 Of ,
therefore , When installed python3 after , You need to modify the soft connection , take python Point to python3.
however centos Package manager yum It's dependence again python2 Of , So I modified python After soft connection of ,yum Package manager
It can't be used . This is not bug Do you ?
There are solutions .
Install first python3, After loading , Switch to usr /bin, First delete the original soft connection python, Again
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
Establish a new soft connection , Replace the old . If there had been pip Of , Also delete , Set up new .
And then there's the solution yum The package manager cannot be used .
yum Installation error File "/usr/bin/yum", line 30 except KeyboardInterrupt, e:
because yum Package usage python2* Etc , It's time to modify the environment python3 Then there's a problem ,
solve :
Modify file /usr/bin/yum、/usr/libexec/urlgrabber-ext-down Corresponding in the head python by #!/usr/bin/python2.7
In other words, most applications directly use python3, Those who can't adapt , Just use the original python2.
Then it is for practice docker pack python The program is mirrored .
Actually , There are also bug. After installation python3 after , I updated it once pip.pip Become the latest , Then when I pack docker Mirror image ,
It always reminds me pip It's not the latest , So I wonder . Can't , stay Dockerfile There is also a layer inside pip to update . also , I didn't put
python Soft connect to python3 Of , So it's using python3 and pip3 When , Always use python3 and pip3. then , Report errors , I have to ,
python Soft connect directly to python3,pip The same thing , Then I met the one above yum When the package manager is not available . therefore linux The environment is sometimes very bug Of .
Use the following command , You can directly connect the python Environment query , Put it in a text file , But what? ?
If you are in the Dockerfile Improper use of this text file in the file , Could lead to docker Failed to download dependency .
docker The process of packaging images is actually a process of docker The warehouse downloads the dependent process , We're writing python When it comes to programming , The main dependence is python3,
And then we're writing Dockerfile When you file , Will specify python3, Then other dependencies will be downloaded , Added to python3 On .
If it is nodejs The program , Is in the Dockerfile Use... In the document npm Package manager to download dependencies , If it is python Program , Is the use of pip Package manager to download dependencies .
If using java Written springboot Program , Then it could be maven Package manager .
Next, let's look at pip Manager Management python.
pip freeze > requirements.txt
The following picture is the file structure , stay dir Medium is python Program , stay Dockerfile Is the packaged configuration content ,
# Based on the basic image
FROM python:3.6.5
# Set up code A folder is a working directory
#COPY dir .
#COPY dir TCPserver.py
WORKDIR ./dir
ADD . .
# Installation support
# It has to be updated pip, Something's wrong , Yes bug
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
#RUN pip install numpy
#CMD ["python", "./dir/TCPserver.py"]
CMD ["python", "./dir/hello.py"]
docker build -t dir .
docker run dir
Insert picture description here