简体   繁体   中英

Best way to enhance a Docker image for small changes that need to be persisted

I have a docker image that takes about 45min to build. As I'm working with it, I'm finding that I sometimes need to add python packages to it for the code I'm working on. I want to be able to install these packages such that it persists.

What's the best way to achieve this?

G

docker builds the container image from cache if nothing is changed. When it founds a change in a line, it executes again all the lines from the change. So, if you need to add libraries, just add more lines at the end of the dockerfile.

While working on docker I have followed two approaches .

First if you have file like

1 from nginx 
2 env name:"add"
3 CMD ["nginx"]

So if you change on 2 line the first line will we cached automatically .

Second Or you can use other approach if your docker file is big you can separate it in two docker file
On first file you can add all the essential things you want . and create images of it

In this way you will not have to wait for 45 min every time for the software download. and on send file use that image like

from imagename

and to all change staff here

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