English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Recherche Docker Hub 镜像上的 Python :
Vous pouvez voir d'autres versions de python via Sort by, par défaut, c'est la version la plus récente python:lastest。
De plus, nous pouvons utiliser la commande docker search python pour afficher les versions disponibles :
w3codebox@w3codebox:~/python$ docker search python NAME DESCRIPTION STARS OFFICIAL AUTOMATED python Python est un interprète,... 982 [OK] kaggle/python Image Docker pour Python... 33 [OK] azukiapp/python Image Docker pour exécuter Python... 3 [OK] vimagick/python mini python 2 [OK] tsuru/python Image pour le Python... 2 [OK] pandada8/alpine-python Image Python basée sur Alpine 1 [OK] 1science/python Images Docker Python basées sur... 1 [OK] lucidfrontier45/python-uwsgi Python avec uWSGI 1 [OK] orbweb/python Image Python 1 [OK] pathwar/python Modèle Python pour les niveaux Pathwar 1 [OK] rounds/10m-python Python, setuptools et pip. 0 [OK] ruimashita/python ubuntu 14.04 python 0 [OK] tnanba/python Python sur CentOS-7 image. 0 [OK]
Ici, nous récupérons l'image officielle, avec l'étiquette3.5
w3codebox@w3codebox:~/python$ docker pull python:3.5
Après que le téléchargement soit terminé, nous pouvons trouver REPOSITORY pour python, avec l'étiquette 3.5 de l'image.}
w3codebox@w3codebox:~/python$ docker images python:3.5 REPOSITORY TAG IMAGE ID CREATED SIZE python 3.5 045767ddf24a 9 days ago 684.1 MB
Créez Dockerfile</p>
Tout d'abord, créez le répertoire python pour stocker les éléments pertinents ultérieurs.
w3codebox@w3codebox:~$ mkdir -p ~/python ~/python/myapp
Le répertoire myapp sera mappé sur le répertoire d'application configuré dans le conteneur python.
Entrez dans le répertoire python créé, créez un Dockerfile.
FROM buildpack-deps:jessie # supprimer plusieurs traces de python debian RUN apt-get purge -y python.* # http://bugs.python.org/problème19846 # > À l'heure actuelle, la définition de "LANG=C" sur un système Linux *casse fondamentalement Python 3*, et ce n'est pas bon. ENV LANG C.UTF-8 # gpg: clé F73C700D: clé publique "Larry Hastings <[email protected]>" importée ENV GPG_KEY 97FC712E4C024BBEA48A61ED3A5CA953F73C700D ENV PYTHON_VERSION 3.5.1 # if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'" ENV PYTHON_PIP_VERSION 8.1.2 RUN set -ex \\ && curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" -o python.tar.xz \\ && curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" -o python.tar.xz.asc \\ && export GNUPGHOME="$(mktemp -d) " \\ && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \ && gpg --batch --verify python.tar.xz.asc python.tar.xz \ && rm -r "$GNUPGHOME" python.tar.xz.asc \ && 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 \) \ -o \ \( -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"]
Créer une image via Dockerfile, remplacez par votre propre nom :
w3codebox@w3codebox:~/python$ docker build -t python:3.5 .
Création terminée, nous pouvons trouver l'image créée récemment dans la liste des images locales :
w3codebox@w3codebox:~/python$ docker images python:3.5 REPOSITORY TAG IMAGE ID CREATED SIZE python 3.5 045767ddf24a 9 days ago 684.1 MB
在 ~/python/在 myapp 目录下创建一个 helloworld.py 文件,代码如下:
#!/usr/bin/python print("Hello, World!");
w3codebox@w3codebox:~/python$ docker run -v $PWD/myapp:/usr/src/myapp -w /usr/src/myapp python:3.5 python helloworld.py
命令说明:
-v $PWD/myapp:/usr/src/myapp: 将主机中当前目录下的 myapp 挂载到容器的 /usr/src/myapp。
-w /usr/src/myapp: 指定容器的 /usr/src/myapp 目录为工作目录。
python helloworld.py: 使用容器的 python 命令来执行工作目录中的 helloworld.py 文件。
输出结果:
Hello, World!