I have a Dockerfile extending FROM
an image that declares a VOLUME
. Is there a way to overwrite the VOLUME
directive in such a way, that it "removes" the VOLUME
?
Removing Docker Volumes To remove one or more Docker volumes, run the docker volume ls command to find the ID of the volumes you want to remove. If you get an error similar to the one shown below, it means that an existing container uses the volume. To remove the volume, you will have to remove the container first.
This command removes the container and any volumes associated with it. Note that if a volume was specified with a name, it will not be removed.
You cannot specify a volume source in the Dockerfile: A common source of confusion when specifying volumes in a Dockerfile is trying to match the runtime syntax of a source and destination at image build time, this will not work. The Dockerfile can only specify the destination of the volume.
If you still want to use ENV to set your variable, then you'll have to start each RUN in which you want the variable to be unset with unset VAR_NAME , which will unset it for that specific RUN only.
No.
The only way to do so, is if you clone Dockerfile
of the image you use as base one (the one in FROM
) and remove the VOLUME
directive manually. Then build it and use in your FROM
as base one.
There are cases when you can not modify the original Dockerfile - in my case an image from production. The only chance is to modify the metadata (with docker save/load actions). As I need to that regulary, I have created a little script for that, have a look at docker-copyedit if that can help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With