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

docker exec into a stopped container #18078

Closed
vikstrous opened this issue Nov 18, 2015 · 7 comments

Comments

@vikstrous
Copy link
Contributor

commented Nov 18, 2015

It looks like docker run is an order of magnitude slower than docker exec. However, if the container is not running, you can't exec in its context and there is no way to re-run it with a different starting command.

We are using docker run many times in a Makefile and if we were able to replace it with docker exec we would reduce the docker related overhead significantly. The only workaround I can think of is to run a container with sleep 100000, use docker exec throughout the build, then try to docker kill at the end. This is likely to occasionally leave a container running if the build fails to clean up properly, so I would much rather have a way to exec into a stopped container or re-start it with a different entrypoint/arguments.

@vikstrous

This comment has been minimized.

Copy link
Contributor Author

commented Nov 18, 2015

After further investigation, it looks like starting is the slow part and this wouldn't solve my original problem.

@duglin

This comment has been minimized.

Copy link
Contributor

commented Nov 19, 2015

Can we close this then?

@vikstrous

This comment has been minimized.

Copy link
Contributor Author

commented Nov 19, 2015

I still want to know why you can't simply start a container with a different entry point. Can we add an option to start that lets you do that? Is there any reason not to?

@MHBauer

This comment has been minimized.

Copy link
Contributor

commented Nov 19, 2015

You could take the container back to an image and then re-run or re-create it with a different entrypoint. Once a container is created there isn't much you can do to it besides start it as it is.

@crosbymichael

This comment has been minimized.

Copy link
Member

commented Nov 20, 2015

The main reason why is because containers are supposed to be immutable. You cannot exec into a stopped container because it has be be running first. Most container starts are in the area of 200ms, no overlay filesystems ( non- devicemapper ) so it would be interesting to see your Makefile and what you are doing to suggest a different way if it is too slow.

@bmangold

This comment has been minimized.

Copy link

commented Nov 20, 2015

Exactly what @MHBauer said:
Commit the stopped container:
docker commit $STOPPED_CONTAINER user/test_image

Start/run with a different entry point:
docker run -ti --entrypoint=sh user/test_image

@rof20004

This comment has been minimized.

Copy link

commented Sep 29, 2018

For me the best solution was this:
jpetazzo/nsenter#27 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.