Skip to content
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

Override named container with -oc or --override-container parameter #22811

Closed
lexandro opened this issue May 18, 2016 · 4 comments
Closed

Override named container with -oc or --override-container parameter #22811

lexandro opened this issue May 18, 2016 · 4 comments

Comments

@lexandro
Copy link
Contributor

Named containers are cool, but you should provide --rm to make your run command repeatable, but deleting containers after stopping is not always the desired behavior because we want inspect them or tail their log, etc. During the development would be nice to use named containers and make possible their overriding with a parameter.

Suggested parameteres:
-oc or --override-container - Overriding the same named container if exists

-f or --force - Force the override of the named container

Current situation:
Step 1: docker run --name ubuntu ubuntu echo hello
Step 2: repeating step 1 is not possible without --rm.

Suggested way:
Step 1: docker run --name ubuntu ubuntu echo hello
Step 2: docker run -oc --name ubuntu ubuntu echo hello

In step 2 the docker client calls an rm first on the image.

Optional parameter: -f or --force for forced replacement
Step 2: docker run -f -oc --name ubuntu ubuntu echo hello

@thaJeztah
Copy link
Member

You can already do so using docker rename, so I don't think we should implement something like this;

docker run -dit --name container ubuntu sh -c "echo hello"
docker rename container old-container \
&& docker run -dit --name container ubuntu sh -c "echo hello" \
&& docker stop old-container

@thaJeztah
Copy link
Member

I think this is a duplicate of #2733, so I'll close this issue, but feel free to comment here after I closed 👍

@lexandro
Copy link
Contributor Author

That's interesting, because --rm is also a hack that exists only in the client. Your solution is quite sophisticated especially, when you are just trying things :(

@jrichardsz
Copy link

maybe this could help you :

create image

docker build -t my_image .

run image as container (remove before run)

docker rm "my_awesome_containter" -f && docker run --name "my_awesome_containter" my_image

more elegant

container_name="my_awesome_containter"
docker rm $container_name -f && docker run --name $container_name my_image

first call fails because container does not exist (coming soon)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants