简体   繁体   中英

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. I have read that you have to add the package in the docker file. However, I don't know where it is stored. I work on 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.

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 . For instance, if you want to install requests , a minimalist Dockerfile could be as follows:

FROM puckel/docker-airflow
RUN pip install requests

Create such a file in myproject/ , then cd in myproject/ and simply run 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.

You can read on docker tags to replace 66b9d91c4c95 by a meaningful name.

Did you used docker pull and docker run commands?

If so, there is container running, you can check it by docker ps

And if you want to install python libraries in the container, you may go into the container via

docker exec -it container_id bash

and there you go with pip install

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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