Re:Docker containers should not run an SSH server
by vidarh on Thursday June 26, 2014 @02:07PM
(#7950843)
I run sshd in one of my Docker images. BUT most of my Docker images are single-app, with no sshd. This includes the various applications I'm working on. The one I ssh into is a (most of the time) replacement for ssh-ing into my actual server. It defines /home as a volume that I pull in from a directory on the server.
Then when I start playing with a new application, I set up a new docker image for it, and has that docker image bind to a suitable subdirectory that is then shared with the "dev" image I ssh into.
This means I always have 100% up to date documentation of the requirements for running the app, in the form of the docker file.
I don't see a problem with running sshd in a Docker container. I do have a bit of an issue with "throwing a bunch of stuff" in the containers. If your purpose for having ssh there is to be able to investigate things, then I'd argue you don't really need it in most cases:
- You can copy files out of the containers with "docker cp"
- All the processes are visible and traceable from the host
- You can choose to export the important bits of the filesystem of the container, so that you can start a second container to inspect those bits more thoroughly (this can also be used to great effect to allow apps that needs to work on the same file sets to be isolated in separate containers).
- During dev/testing you can easily override the entrypoint and start a shell.
In practice I've found that while introspection of various forms is important during testing and development, there's also a certain benefit in not giving yourself direct access to easily modify stuff: It makes it easier to maintain discipline and update the Dockerfile etc. and rebuild containers.
If you also use e.g. systemd to run the containers, and log to the console, you get your logs concentrated via journald and optionally shipped on to rsyslog etc., and combined with the docker tools and careful use of exported volumes, there's very little state left where there's much need to ssh in to a specific container. There's also a tool (forget the name; EDIT: D'oh, it's "nsenter" that's presented in the article I'm thinking about) that let you run a process in the same cgroup namespaces as your container as well.
If anything, I'm leaning towards trimming the containers further, down to the bare essentials for each specific app.
Then when I start playing with a new application, I set up a new docker image for it, and has that docker image bind to a suitable subdirectory that is then shared with the "dev" image I ssh into.
This means I always have 100% up to date documentation of the requirements for running the app, in the form of the docker file.
I don't see a problem with running sshd in a Docker container. I do have a bit of an issue with "throwing a bunch of stuff" in the containers. If your purpose for having ssh there is to be able to investigate things, then I'd argue you don't really need it in most cases:
- You can copy files out of the containers with "docker cp"
- All the processes are visible and traceable from the host
- You can choose to export the important bits of the filesystem of the container, so that you can start a second container to inspect those bits more thoroughly (this can also be used to great effect to allow apps that needs to work on the same file sets to be isolated in separate containers).
- During dev/testing you can easily override the entrypoint and start a shell.
In practice I've found that while introspection of various forms is important during testing and development, there's also a certain benefit in not giving yourself direct access to easily modify stuff: It makes it easier to maintain discipline and update the Dockerfile etc. and rebuild containers.
If you also use e.g. systemd to run the containers, and log to the console, you get your logs concentrated via journald and optionally shipped on to rsyslog etc., and combined with the docker tools and careful use of exported volumes, there's very little state left where there's much need to ssh in to a specific container. There's also a tool (forget the name; EDIT: D'oh, it's "nsenter" that's presented in the article I'm thinking about) that let you run a process in the same cgroup namespaces as your container as well.
If anything, I'm leaning towards trimming the containers further, down to the bare essentials for each specific app.