roughly speaking, take Node.js, which I am a little familiar with, for example, you may not want to create a dependent package folder called node_modules in the container, but mount a directory of the host, right? But in the process of building, you need to download and rely on it more than once? Or are there multiple dependent package folders?
I haven't tried it, but I guess even if you have more than one installation package folder, the container can be mounted one by one, so it should be possible to do so:
docker run -d -v /dir1:/dir1 -v /dir2:/dir2 image:version
but in theory, this is not very good. After all, the dependency package of the image has too much to do with the running environment. This is how I do Dockerfile:
COPY ./package.json /app
CMD npm install
COPY ./ /app
RUN npm start
I first copy the dependency configuration file into the image, then install the dependency package, and then copy the project.
after this, as long as the dependency package configuration file remains unchanged, the mirror layer in the step of installing the dependency package can be used repeatedly, and the construction speed will be greatly improved.
I hope I can help you.