简体   繁体   English

如何在拉出的docker映像上安装python库?

[英]How to install a python library to a pulled docker image?

I have pulled a docker image to run airflow (pucker/airflow) and it is running well. 我拉了一个泊坞窗图像以运行气流(褶皱/气流),并且运行良好。 However, I can't manage to install a new python library on this image. 但是,我无法在此图像上安装新的python库。 I have read that you have to add the package in the docker file. 我读过你必须在docker文件中添加包。 However, I don't know where it is stored. 但是,我不知道它存储在哪里。 I work on MacOSX. 我在MacOSX上工作。

Thanks for your help 谢谢你的帮助

As I understand it, you only pulled a puckel/docker-airflow image from dockerhub, and you're simply running that image. 据我了解,您仅从puckel/docker-airflow提取了一个puckel/docker-airflow airflow映像,而您只是在运行该映像。

If you need to add extra libraries, and if you want to include the install of these libraries in a build process, you probably need a Dockerfile . 如果您需要添加额外的库,并且要在构建过程中包括这些库的安装,则可能需要Dockerfile For instance, if you want to install requests , a minimalist Dockerfile could be as follows: 例如,如果要安装requests ,则极简的Dockerfile可以如下所示:

FROM puckel/docker-airflow
RUN pip install requests

Create such a file in myproject/ , then cd in myproject/ and simply run docker build . 创建这样一个文件myproject/ ,然后cdmyproject/和简单的运行docker build . This will output a simple log such as: 这将输出一个简单的日志,例如:

Step 1/2 : FROM puckel/docker-airflow
 ---> 12753a529f9f
Step 2/2 : RUN python3 -m pip install requests
 ---> Running in 66860c8ca099
Requirement already satisfied: requests in /usr/local/lib/python3.6/site-packages (2.22.0)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/site-packages (from requests) (2019.3.9)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.6/site-packages (from requests) (3.0.4)
Requirement already satisfied: idna<2.9,>=2.5 in /usr/local/lib/python3.6/site-packages (from requests) (2.8)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.6/site-packages (from requests) (1.25.3)
Removing intermediate container 66860c8ca099
 ---> 66b9d91c4c95
Successfully built 66b9d91c4c95

Then run docker run 66b9d91c4c95 to instantiate the image you just created, or docker run -it 66b9d91c4c95 bash to open bash in it. 然后运行docker run 66b9d91c4c95实例化刚刚创建的映像,或者docker run -it 66b9d91c4c95 bash在其中打开bash

You can read on docker tags to replace 66b9d91c4c95 by a meaningful name. 您可以阅读66b9d91c4c95 标签 ,以有意义的名称替换66b9d91c4c95

Did you used docker pull and docker run commands? 您是否使用了docker pulldocker run命令?

If so, there is container running, you can check it by docker ps 如果是这样,则有容器在运行,您可以通过docker ps检查它

And if you want to install python libraries in the container, you may go into the container via 如果您想在容器中安装python库,则可以通过以下方式进入容器

docker exec -it container_id bash

and there you go with pip install 然后就可以进行pip install

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM