-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 '--replace' option into container creation command #5036
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing!
I'm still struggling to find the use-case for this though, and not sure if we should do this.
While there could be some use-cases that (e.g.) are used to update or replace a container, there may already be better ways to achieve that;
docker compose
allows updating your stack by updating the compose file, and runningdocker compose up
(which performs steps needed to reconcile state with the state in the compose-file)- with swarm enabled (which could be a single node),
docker service update
allows updating definition of services, which will create new tasks to replace the old one (but keeping a configurable number of previous instances) - for some use-cases (not all options can be updated)
docker container update
can be used to update an existing container's configuration - for other scenarios, and for sure it's not as "polished", chaining commands together (
docker rm -fv <container> && docker run ...
) or creating a shell alias for this could be used
The current approach in this PR means that any container with the given name would be forcefully killed and removed, which can be a very destructive operation.
I think this would warrant a more in-depth look into use-cases and a design based on that; without having given it a lot of thought, I'm considering (again, depending on use-cases);
- extending
docker container update
and/or introducing adocker container edit
option; this is something that has come up in discussions, but combined with implementing reconciliation logic; some changes will require a new container to be created, which is something that could be added to that logic (which could be either an explicit option to be set, or use a similar logic as swarm where previous iterations are kept) - a
docker container replace
command that explicitly replaces an existing container; possibly combined with the above
In either case, I think this requires some thinking before we implement this, and I'd rather not take this pull request (also because there's existing options that could allow this).
8ada74d
to
39c54e5
Compare
Hello @thaJeztah, Thank you for your feedback. |
closes #5023
- What I did
Implemented a
--replace
option within thecontainer create
command, allowing for the removal (if existing) of the container with the specified name without the need to separately execute theremove <container_name>
command.- How I did it
In the source file
cli/command/container/create.go
Line 73
: Added the new option as boolean with default valuefalse
Line 255
: If the option istrue
and the user has supplied a name we call the ContainerRemove(..)- How to verify it
- Description for the changelog