Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Remove" a VOLUME in a Dockerfile

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?

like image 742
tyrondis Avatar asked May 17 '17 09:05

tyrondis


People also ask

How do you remove the volume of a container?

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.

Does docker container RM remove volumes?

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.

Can we specify volume in Dockerfile?

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.

How do I unset an environment variable in Dockerfile?

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.


2 Answers

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.

like image 145
Alex Karshin Avatar answered Sep 23 '22 19:09

Alex Karshin


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.

like image 31
Guido U. Draheim Avatar answered Sep 22 '22 19:09

Guido U. Draheim