Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undo Dockerfile VOLUME directive from a base image [duplicate]

I have an image derived from the Postgres official image, whose Dockerfile includes the following:

VOLUME /var/lib/postgresql/data

I'd like to create my own image based on this official image, but I don't want it to reference any volume. I'd like the Postgres data to be inside my image.

Any ideas please?

like image 719
david.perez Avatar asked Oct 23 '25 15:10

david.perez


1 Answers

You can't undo the VOLUME directive.

See this open issue on github: Reset properties inherited from parent image #3465

There are some solutions, based on answers of theses questions:

  • "Remove" a VOLUME in a Dockerfile
  • How to remove a volume in a Dockerfile
  • How to remove configure volumes in docker images

You can copy the base image and remove the VOLUME manually.


A workaround, see docker-copyedit. The script will docker save and image into an archive to modify its metadata and docker load it back into an image.


If you don't care about the volume and just want to put the data in the image, you'll have to use another location for the data and you can use use the environment variable PGDATA to define the new location.

like image 192
Mickael B. Avatar answered Oct 25 '25 11:10

Mickael B.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!