-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an UNVOLUME or UNSET VOLUME statement to cancaled mount the default parent volume #4802
Comments
I can suggest a design option |
Maybe smth like
|
I think it looks great! Maybe it can also support an extended syntax like to allow filtering which specific FROM --reset=volume=/var/lib/docker,env=MYVAR,env=MYOTHERVAR img On a note, |
I'm more thinking it from the perspective of "I don't want let changes in the base image control this part of my build". If I already know a specific volume or other parameter by name that I want to keep then I can reset all and re-add missing manually. Otoh. the extended syntax does not look too awful, but I think individually it makes more sense to for example define env that I want to keep, rather than the ones I want to unset. |
I think this will require a lot of refactoring. If you reset Environment Variables then you can influence the parent entry point through a script file. (updated) or ENV ENV_VAR= ENTRYPOINT or CMD you always can to override
We are now discussing VOLUME here because parent volumes create difficulties. |
Really? I don't think so. |
No, that is not how it works. That only resets the variable for your current running process inside a container.
That isn't exactly equivalent. The environment variable would still be in the list of defined variables but the value would be empty.
The problem with the older attempts with this seems to be more that there wasn't a solution that fixed the general problem (or that the general problem was not well-defined) and nobody wanted to add extra hacky one-off command, that patched one case but left many open questions to be figured out later. Adding this kind of reset functionality to one command or to all applicable commands doesn't necessarily mean a big difference in development complexity. Two things have changed since that old discussion in earlier issues:
So from my side, I would be open to adding In that case I think the syntax that best aligns with existing commands would be.
These are the commands that allow defining named keys. Other commands should not need My take is that both of these could be added to the labs channel https://docs.docker.com/build/dockerfile/frontend/#labs-channel |
This syntax would be a good idea
A global reset will have consequences and will therefore be used extremely rarely. At build time, the parent image needs the environment variables that it declares, since the entrypoint startup script depends on this. unset all env
I explained this earlier, but deleted some of my comments so as not to clutter up the topic. How I do it
If people care about the need to reset variables after the entry point, then I think you can implement this:
or
In this case, when resetting the environment variables But unfortunately in this case you will have to redefine the parent ENTRYPOINT. |
By the way . Sometimes there is a lack of a directive that would be executed after the entrypoint is runed. But these are my wishes. Example : As an addition, you can implement this Today I am forced to write my entry point and override the parent entry point Why is the command Rewriting the entrypoint that is declared by the parent is a crutch that interferes with life. Previously I expressed my thoughts about privileges moby/moby#47632 Such ideas would allow developers to remove restrictions and inconveniences. But I don’t want to once again flood with new topics, so I expressed my ideas here. |
As a future strategy, I would recommend idea defining the principles of Covariance and contravariance in inheritance. For example, I understand that there are many factors against this. But this is my idea that you can take as perspective. |
I have a workaround for this, as an example, the official postgres image. Originally posted by me here: https://stackoverflow.com/a/78645904/2545063 And also here: You can use FROM postgres:15-bookworm as postgres-docker
FROM debian:bookworm-slim as postgres-build
# We do this because the postgres-docker container has a VOLUME on /var/lib/postgresql/data
# This copies the filesystem without bringing the VOLUME with it.
COPY --from=postgres-docker / /
# DO THE REST OF YOUR STUFF
# https://hub.docker.com/_/postgres - see 15-bookworm for the stuff we are setting here
# Note: We need to set these because we are using COPY --from=postgres-docker - see above
ENTRYPOINT ["docker-entrypoint.sh"]
ENV LANG en_US.utf8
ENV PG_MAJOR 15
ENV PATH $PATH:/usr/lib/postgresql/${PG_MAJOR}/bin
ENV PGDATA /var/lib/postgresql/data
ENV SLEEP_ON_EXIT=0
STOPSIGNAL SIGINT
CMD ["postgres"]
EXPOSE 5432 That said, I would MUCH prefer to be able to do:
instead of having to do Someone wrote a script to do this sort of thing via image |
I really appreciate the suggestion from @tonistiigi (also the syntax to use KEYWORD --unset). To provide another real-world example: Regarding the workaround provided by @thorfi, be aware that this approach increases the size of your resulting image. |
This topic has been before discussed since 2014:
Created a new topic based on recommendations moby/moby#8177 (comment)
Target: Add
UNVOLUME /target/directory
(or UNSET VOLUME) statement in Dockerfile.Behavior: Removes volume metadata that is added by the parent image. If there is no metadata to delete, a warning is issued. Mounting and unmounting volumes must be applied sequentially according to the image inheritance order.
The problem exists and people suffer from it and ask for something to be done.
Reasons for change:
As a result, parent volumes hang like extra garbage and take up disk space (often data from the container is copied to volumes by default).
But the default volume always overlaps this folder in the container and the user does not have access to it.
Please study the topic moby/moby#3465 and you will understand that there are problems. It’s just that not everyone can or wants to describe the situation that the developers encountered.
I think there are enough legal grounds to consider this problem seriously and include any option for canceling the parent default volume.
Some links:
moby/moby#33842 (comment) - VOLUME behavior in buildkit - VOLUME is now metadata
moby/moby#3465 (comment) - unmount volume via ENTRYPOINT
moby/moby#3465 (comment) - Rebuilding the image with new settings
moby/moby#3465 (comment) - Changing metadata in a built image
(UPDATED)
I have a request to the participants - reproduce your problems in detail.
If possible with examples.
It is better not to discuss unless necessary, so as not to clutter the topic.
The text was updated successfully, but these errors were encountered: