docker install python3 development environment

Python is an interpreted, object-oriented, and dynamic data type high-level programming language. Getting started is simple and easy to learn. Python There are two ways to install Docker. 

Let's take the current latest version  3.6.5 installation as an example to install:

Find the python image on Docker Hub:

 See the latest version 3.6

Pull the official image, the label is 3.6.5:

 It can be seen that the image has a size of more than 900M.

 Enter the created  python directory, create Dockerfile

FROM buildpack-deps:jessie

# Delete the old python
RUN apt-get purge -y python.*

# Use UTF-8 encoding
ENV LANG C.UTF-8

ENV PYTHON_VERSION 3.6.5

# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
ENV PYTHON_PIP_VERSION 10.0.1

RUN set -ex \
        && curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" -o python.tar.xz \
        && mkdir -p /usr/src/python \
        && tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \
        && rm python.tar.xz \
        \
        && cd /usr/src/python \
        && ./configure --enable-shared --enable-unicode=ucs4 \
        && make -j$(nproc) \
        && make install \
        && ldconfig \
        && pip3 install --no-cache-dir --upgrade --ignore-installed pip==$PYTHON_PIP_VERSION \
        && find /usr/local -depth \
                \( \
                    \( -type d -a -name test -o -name tests \) \
                    -The \
                    \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
                \) -exec rm -rf '{}' + \
        && rm -rf /usr/src/python ~/.cache

# make some useful symlinks that are expected to exist
RUN cd /usr/local/bin \
        && ln -s easy_install-3.5 easy_install \
        && ln -s idle3 idle \
        && ln -s pydoc3 pydoc \
        && ln -s python3 python \
        && ln -s python3-config python-config

CMD ["python3"]

By  Dockerfile creating a mirror my-python:3.6.5:

 After the build is complete, you can find the newly created mirror in the local mirror list

/python/myapp Create a new file in the  directory  hello.py and enter the following:

 
 

 Then execute the file:

Command description:

  1. -v $PWD/myapp:/htdocs/python

    myapp Mount the current directory in the host  to /htdocs/python of the container

  2. -w htdocs/python

    Specify the htdocs/python/myapp directory of the container  as the working directory

  3. python3 hello.py

    Use container  python3 commands to execute hello.py files in the working directory 

Guess you like

Origin blog.csdn.net/lchmyhua88/article/details/107634266