2014-05-21 21:05:19 +00:00
|
|
|
page_title: Dockerizing an SSH service
|
|
|
|
page_description: Installing and running an SSHd service on Docker
|
2014-04-16 00:53:12 +00:00
|
|
|
page_keywords: docker, example, package installation, networking
|
|
|
|
|
2014-05-21 21:05:19 +00:00
|
|
|
# Dockerizing an SSH Daemon Service
|
2014-04-16 00:53:12 +00:00
|
|
|
|
2014-05-21 21:05:19 +00:00
|
|
|
The following `Dockerfile` sets up an SSHd service in a container that you
|
2014-04-23 20:48:28 +00:00
|
|
|
can use to connect to and inspect other container's volumes, or to get
|
2014-04-16 00:53:12 +00:00
|
|
|
quick access to a test container.
|
|
|
|
|
|
|
|
# sshd
|
|
|
|
#
|
|
|
|
# VERSION 0.0.1
|
|
|
|
|
2014-09-03 21:44:57 +00:00
|
|
|
FROM ubuntu:14.04
|
2014-04-16 00:53:12 +00:00
|
|
|
MAINTAINER Thatcher R. Peskens "thatcher@dotcloud.com"
|
|
|
|
|
2014-07-07 18:06:34 +00:00
|
|
|
RUN apt-get update && apt-get install -y openssh-server
|
2014-05-21 21:05:19 +00:00
|
|
|
RUN mkdir /var/run/sshd
|
2014-09-03 21:44:57 +00:00
|
|
|
RUN echo 'root:screencast' | chpasswd
|
|
|
|
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
|
2014-04-16 00:53:12 +00:00
|
|
|
|
|
|
|
EXPOSE 22
|
2014-09-03 21:44:57 +00:00
|
|
|
CMD ["/usr/sbin/sshd", "-D"]
|
2014-04-16 00:53:12 +00:00
|
|
|
|
|
|
|
Build the image using:
|
|
|
|
|
2014-07-16 09:12:14 +00:00
|
|
|
$ sudo docker build -t eg_sshd .
|
2014-04-16 00:53:12 +00:00
|
|
|
|
2014-05-21 21:05:19 +00:00
|
|
|
Then run it. You can then use `docker port` to find out what host port
|
|
|
|
the container's port 22 is mapped to:
|
2014-04-16 00:53:12 +00:00
|
|
|
|
2014-05-14 20:24:08 +00:00
|
|
|
$ sudo docker run -d -P --name test_sshd eg_sshd
|
2014-04-16 00:53:12 +00:00
|
|
|
$ sudo docker port test_sshd 22
|
|
|
|
0.0.0.0:49154
|
|
|
|
|
2014-09-03 21:44:57 +00:00
|
|
|
And now you can ssh as `root` on the container's IP address (you can find it
|
|
|
|
with `docker inspect`) or on port `49154` of the Docker daemon's host IP address
|
|
|
|
(`ip address` or `ifconfig` can tell you that):
|
2014-04-16 00:53:12 +00:00
|
|
|
|
|
|
|
$ ssh root@192.168.1.2 -p 49154
|
|
|
|
# The password is ``screencast``.
|
|
|
|
$$
|
|
|
|
|
|
|
|
Finally, clean up after your test by stopping and removing the
|
|
|
|
container, and then removing the image.
|
|
|
|
|
|
|
|
$ sudo docker stop test_sshd
|
|
|
|
$ sudo docker rm test_sshd
|
|
|
|
$ sudo docker rmi eg_sshd
|
2014-05-21 21:05:19 +00:00
|
|
|
|