roadmap icon indicating copy to clipboard operation
roadmap copied to clipboard

Change the -v flag on docker compose down

Open GarretSidzaka opened this issue 1 year ago • 6 comments

Change the -v flag on docker compose down. Some customers have accidentally cleared their volumes and lost data using this flag. Suggest to change -v flag to --volumes. This is also more consistent with other tools.

Docker compose plugin

The problem is "docker compose down -v" might be misunderstood to be a "verbosity" flag and cause customers to lose persistent volume data.

Education can help others know not to use this flag. But the similarity with verbosity flags is troubling.

GarretSidzaka avatar May 07 '24 22:05 GarretSidzaka

The -v option is a shorthand for --volumes, so --volumes already exists;

docker compose down --help

Usage:  docker compose down [OPTIONS] [SERVICES]

Stop and remove containers, networks

Options:
      --dry-run          Execute command in dry run mode
      --remove-orphans   Remove containers for services not defined in the Compose file
      --rmi string       Remove images used by services. "local" remove only images that don't have a custom tag ("local"|"all")
  -t, --timeout int      Specify a shutdown timeout in seconds
  -v, --volumes          Remove named volumes declared in the "volumes" section of the Compose file and anonymous volumes attached to containers

The problem is "docker compose down -v" might be misunderstood to be a "verbosity" flag and cause customers to lose persistent volume data.

I know we generally try to avoid shorthand flags if there's possible ambiguity. This one already has existed for multiple years, which for sure makes it more complicated to change, as removing it would be a breaking change.

That said; some similar changes were made for docker system prune, where previously named volumes could be removed if they were not in use at the time the prune command was executed; https://github.com/moby/moby/pull/44216, so maybe a similar approach could be taken

thaJeztah avatar May 13 '24 12:05 thaJeztah

I was just talking about this ticket in a developer meeting, and the consensus is the -v is so dangerous we try to keep it secret from customers, and when we do use it, we do it with considerable warning not to perform on their own.

We are very afraid that a new user would want to examine some bug or behavior in the "docker compose down" command by simply typing "docker compose down -v". That is because cURL and many other common commands have "-v" as a verbosity flag, its actually quite common in the POSIX world. And if this engineer did this common thing, this person could potentially wipe an entire prod environment, without warning, in an instant. There is no confirmation on this "-v" volume destruction.

This is very apparently a design flaw upon contemplation and should be addressed. Also, this would break all my automation that uses "-v", I agree. I didn't even know about --volumes until later. Adding a confirmation dialog would also break automation. This is a pickle.

GarretSidzaka avatar Sep 06 '24 16:09 GarretSidzaka

Ignore closure that was a mis click 🤦

GarretSidzaka avatar Sep 06 '24 16:09 GarretSidzaka

Rather than change the -v flag name, perhaps add a confirmation y/n prompt that can be overridden with another -y flag

But this still changes existing behavior if people are relying on -v silently cleaning up everything

rep-movsd avatar Jul 17 '25 07:07 rep-movsd

Rather than change the -v flag name, perhaps add a confirmation y/n prompt that can be overridden with another -y flag

But this still changes existing behavior if people are relying on -v silently cleaning up everything

Thank you Rep-movsd, I have been thinking about this ticket alot since I posted it. I really think that a confirmation dialog would be a non breaking way to implement this. We could also add perhaps "-f" to remove the confirmation which would be much less breaking for folks who do use docker compose down -v programmatically. I can't imagine why but I'm sure someone does.

GarretSidzaka avatar Jul 17 '25 15:07 GarretSidzaka

Rather than change the -v flag name, perhaps add a confirmation y/n prompt that can be overridden with another -y flag But this still changes existing behavior if people are relying on -v silently cleaning up everything

Thank you Rep-movsd, I have been thinking about this ticket alot since I posted it. I really think that a confirmation dialog would be a non breaking way to implement this. We could also add perhaps "-f" to remove the confirmation which would be much less breaking for folks who do use docker compose down -v programmatically. I can't imagine why but I'm sure someone does.

Another suggestion, allow the -f to be set via an environment variable - this means people can just add that in the environment without having to edit anything

In general having an env var that can pass some default options is very useful

rep-movsd avatar Jul 18 '25 07:07 rep-movsd