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 shell/provisioning without SSH #4179

Closed
rasschaert opened this issue Jul 12, 2014 · 15 comments · Fixed by #7377
Closed

Docker shell/provisioning without SSH #4179

rasschaert opened this issue Jul 12, 2014 · 15 comments · Fixed by #7377

Comments

@rasschaert
Copy link
Contributor

Currently, Vagrant can only provision or shell into a Docker container when it has an SSH daemon running.

Last month Docker's Jérôme Petazzoni wrote a post on the Docker blog titled "Why you don't need to run SSHD in your Docker containers". In it, he introduces a small tool called nsenter, which allows you to enter the namespace of a Docker container and run a program, such as a bash shell.

In the comments, Phusion's Hongi Lai, the creator of baseimage-docker, responds to the post:

Now, you are advocating nsenter. I am seriously considering this option. There is currently an ongoing discussion on the baseimage-docker bug tracker about replacing SSH with nsenter: phusion/baseimage-docker#102

Baseimage-docker is one of the more popular images to use with Vagrant, and Phusion were some of the most vocal advocates in favor of running SSHd inside docker containers.

Meanwhile, upstream, Docker is committed to creating a native mechanism to execute new processes in existing containers. It was slated for the 1.0 release but has since been delayed.

It'd be nice if Vagrant would allow for other mechanisms such as nsenter to provision or shell into containers.

@FooBarWidget
Copy link

Hongli Lai here. I think it's better to wait a while before implementing anything, because the landscape is still moving quickly. From the research I've done so far, it does not look like it's viable to completely replace SSH with nsenter. The nsenter approach requires the binary to be installed on the host, which is not always the case. There are also certain use cases where SSH is more appropriate than nsenter. Most likely, in Baseimage-docker we will support both.

The sanest approach would be to wait for Docker's native mechanism, which hasn't been implemented.

@FooBarWidget
Copy link

And another issue with nsenter is: processes started by nsenter cannot be killed from within the container, even by root inside the container. Thus, their behavior is slightly different from when they're executed from within the container, or by SSH. It's not entirely clear whether it's ok to run arbitrary commands inside the container like this. Also, nsenter requires root on the Docker host.

@peefour
Copy link

peefour commented Jul 16, 2014

hi,
Because most of my docker containers are mostly mini servers (I like to use the docker images from turnkeylinux) I find SSH invaluable.

However it is not clear to me what the functional difference is between:

  1. ssh
  2. docker attach
  3. nsenter

please advise why/when prefer the one above the other?

thanks!

@FooBarWidget
Copy link

docker attach is totally unrelated to the other two. docker attach reattaches a Docker container to a terminal, kind of like re-attaching a screen session. It is not a way to login to a container.

As for ssh vs nsenter, read these writeups in the baseimage-docker documentation:

@peefour
Copy link

peefour commented Jul 16, 2014

Thanks for the links, I had already read them but still have these questions:

if I need access to the docker containers on a machine, I can use both docker attach (if on the same host) as SSH, as nsenter, to change or inspect stuff on that machine.

I understand that SSH is a different beast because you use it mainly over the network.
it is still not clear to me why nsenter is different (or preferred) for this task than docker-attach?

thanks!

@mitchellh
Copy link
Contributor

I think we can use docker exec now!

@frankscholten
Copy link

+1

This was referenced Dec 5, 2014
@schmunk42
Copy link

+1 for vagrant docker-exec

@semekh
Copy link

semekh commented Jul 29, 2015

docker exec is now a part of docker itself. Do you think it's a good idea to transparently use docker exec instead of ssh-ing into the container? It provides the same interface as SSH, and it shouldn't result in any incompatibility.

@thomaszbz
Copy link

SSH is just overhead here if you can just use docker exec which is provided by docker. Vagrant should be capable to use both scenarios.

sethvargo added a commit that referenced this issue May 31, 2016
This adds a new core command, `docker-exec`, which allows the user to
exec into an already-running container.

- Fixes #6566
- Fixes #5193
- Fixes #4904
- Fixes #4057
- Fixes #4179
- Fixes #4903
sethvargo added a commit that referenced this issue May 31, 2016
This adds a new core command, `docker-exec`, which allows the user to
exec into an already-running container.

- Fixes #6566
- Fixes #5193
- Fixes #4904
- Fixes #4057
- Fixes #4179
- Fixes #4903
sethvargo added a commit that referenced this issue May 31, 2016
This adds a new core command, `docker-exec`, which allows the user to
exec into an already-running container.

- Fixes #6566
- Fixes #5193
- Fixes #4904
- Fixes #4057
- Fixes #4179
- Fixes #4903
sethvargo added a commit that referenced this issue Jun 1, 2016
This adds a new core command, `docker-exec`, which allows the user to
exec into an already-running container.

- Fixes #6566
- Fixes #5193
- Fixes #4904
- Fixes #4057
- Fixes #4179
- Fixes #4903
@thatguystone
Copy link

thatguystone commented Aug 18, 2016

Was this actually addressed in #7377?

@bogdando
Copy link

No, it seems not possible to use the docker-exec as a replacemant to the vm.provision :shell

@jgillich
Copy link

This should be reopened @sethvargo

@chrisroberts
Copy link
Member

@jgillich Hi! Closed issues are not tracked. If you are still having a problem, please open a new issue. Thanks!

@ghost
Copy link

ghost commented Apr 3, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.