简体   繁体   中英

How to edit library package inside docker image

I want to manually change some source code in a .py file inside gensim library, which is installed inside a docker image after pip install -r requirements.txt which has gensim library version specified inside.

Since I'm using requirements.txt , changing source code locally (or on ec2) then building won't solve the problem.

Changing docker image after I pull it won't solve the problem since it won't be easily repeatable for other computers.

My current thought is to have that edited .py file inside the same directory as Dockerfile and make my application.py import from the modified .py file and build the image. Is (this a good way or) there a better way for docker to install a customized library?

If you 'own' the image and Dockerfile, then you can add the python file in it:

RUN pip install --requirement requirements.txt
ADD changed_source.py intended_location
...

If you don't own the image|Dockerfile, then a better practice is to derive a new image from it:

FROM the-other-file:tag
ADD changed_source.py intended_location
...

Make sense?

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