【发布时间】:2021-08-15 01:38:53
【问题描述】:
我对 docker 完全陌生(在 Windows 10 机器上)。我打算将 python 开发环境设置为 docker 容器。我所做的大部分阅读都涉及到 Dockerfile 的使用。我想从头开始,而不是纯粹使用命令。
我打算做的是非常基本的要求:拥有 python docker 映像,并且我应该能够在该映像中安装更多库并将这些更新提交到该映像。但我想完全使用命令(而不是通过 Dockerfile)来完成。
我在 Windows 10 机器上使用 Docker Desktop。我做了docker pull python:latest,它像这样拉出图像:
C:\Users\MyHomeDirectory>docker pull python:latest
latest: Pulling from library/python
d960726af2be: Pull complete
e8d62473a22d: Pull complete
8962bc0fad55: Pull complete
65d943ee54c1: Pull complete
532f6f723709: Pull complete
1334e0fe2851: Pull complete
062ada600c9e: Pull complete
aec2e3a89371: Pull complete
1ec7c3bcb4b2: Pull complete
Digest: sha256:65367d1d3eb47f62127f007ea1f74d1ce11be988044042ab45d74adc6cfceb21
Status: Downloaded newer image for python:latest
docker.io/library/python:latest
然后我做了docker images,它显示python最新图像的大小为886 MB。
C:\Users\Tejas.Khajanchee>docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
python latest 5b3b4504ff1f 47 hours ago 886MB
我也可以通过 docker run -it python 进入交互式 python 并生成交互式 shell:
Python 3.9.5 (default, May 12 2021, 15:26:36)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import gc
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
>>>
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas'
>>>
>>> import openpyxl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'openpyxl'
>>>
但很明显,有些库没有安装。但这就是我卡住的地方。如何将库安装到 python 映像中并更新映像。另外,如果这个 shell 是到目前为止我唯一可以做的事情,886 MB 内容代表什么?我也希望能够使用这个 docker 图像运行脚本。当我尝试在一个非常基本的 hello world 脚本上执行此操作时,会出现以下错误:
C:\Users\MyHomeDirectory\Downloads>docker run -it python a.py
docker: Error response from daemon: OCI runtime create failed: container_linux.go:367: starting container process caused: exec: "a.py": executable file not found in $PATH: unknown.
我希望能够完全使用命令而不是 Dockerfile 来执行此操作。请帮忙。
【问题讨论】:
-
你能进入你的容器并运行
python -m pip install numpy吗?如果是我,我会使用 docker 文件来处理这个问题。 -
不,它不允许我进入容器。我做了
docker exec -it python /bin/bash。它给出了一个错误:Error: No such container: python.
标签: python-3.x docker pip