2014-05-21 17:05:19 -04:00
|
|
|
page_title: Dockerizing an SSH service
|
|
|
|
page_description: Installing and running an SSHd service on Docker
|
2014-04-15 20:53:12 -04:00
|
|
|
page_keywords: docker, example, package installation, networking
|
|
|
|
|
2014-05-21 17:05:19 -04:00
|
|
|
# Dockerizing an SSH Daemon Service
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2014-05-21 17:05:19 -04:00
|
|
|
The following `Dockerfile` sets up an SSHd service in a container that you
|
2014-04-23 16:48:28 -04:00
|
|
|
can use to connect to and inspect other container's volumes, or to get
|
2014-04-15 20:53:12 -04:00
|
|
|
quick access to a test container.
|
|
|
|
|
|
|
|
# sshd
|
|
|
|
#
|
|
|
|
# VERSION 0.0.1
|
|
|
|
|
2014-06-05 14:10:52 -04:00
|
|
|
FROM debian
|
2014-04-15 20:53:12 -04:00
|
|
|
MAINTAINER Thatcher R. Peskens "thatcher@dotcloud.com"
|
|
|
|
|
|
|
|
# make sure the package repository is up to date
|
|
|
|
RUN apt-get update
|
|
|
|
|
|
|
|
RUN apt-get install -y openssh-server
|
2014-05-21 17:05:19 -04:00
|
|
|
RUN mkdir /var/run/sshd
|
2014-04-15 20:53:12 -04:00
|
|
|
RUN echo 'root:screencast' |chpasswd
|
|
|
|
|
|
|
|
EXPOSE 22
|
2014-06-05 14:10:52 -04:00
|
|
|
CMD ["/usr/sbin/sshd", "-D"]
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
Build the image using:
|
|
|
|
|
2014-05-14 16:22:38 -04:00
|
|
|
$ sudo docker build --rm -t eg_sshd .
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2014-05-21 17:05:19 -04: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-15 20:53:12 -04:00
|
|
|
|
2014-05-14 16:24:08 -04:00
|
|
|
$ sudo docker run -d -P --name test_sshd eg_sshd
|
2014-04-15 20:53:12 -04:00
|
|
|
$ sudo docker port test_sshd 22
|
|
|
|
0.0.0.0:49154
|
|
|
|
|
2014-05-21 17:05:19 -04:00
|
|
|
And now you can ssh to port `49154` on the Docker daemon's host IP
|
|
|
|
address (`ip address` or `ifconfig` can tell you that):
|
2014-04-15 20:53:12 -04: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 17:05:19 -04:00
|
|
|
|