2013-04-03 22:21:57 -07:00
|
|
|
:title: Running an SSH service
|
2014-02-13 16:12:21 +10:00
|
|
|
:description: Installing and running an sshd service
|
2013-04-03 22:21:57 -07:00
|
|
|
:keywords: docker, example, package installation, networking
|
|
|
|
|
|
|
|
.. _running_ssh_service:
|
2013-03-29 17:30:10 -07:00
|
|
|
|
2013-06-01 22:03:28 -07:00
|
|
|
SSH Daemon Service
|
|
|
|
==================
|
2013-03-29 17:30:10 -07:00
|
|
|
|
2013-04-07 10:23:00 -04:00
|
|
|
.. include:: example_header.inc
|
2013-03-29 17:30:10 -07:00
|
|
|
|
2014-02-13 16:12:21 +10:00
|
|
|
The following Dockerfile sets up an sshd service in a container that you can use
|
|
|
|
to connect to and inspect other container's volumes, or to get quick access to a
|
|
|
|
test container.
|
2013-03-29 17:30:10 -07:00
|
|
|
|
2014-02-13 16:12:21 +10:00
|
|
|
.. literalinclude:: running_ssh_service.Dockerfile
|
2013-03-29 17:30:10 -07:00
|
|
|
|
2014-02-13 16:12:21 +10:00
|
|
|
Build the image using:
|
2013-08-13 18:05:35 -07:00
|
|
|
|
2014-02-13 16:12:21 +10:00
|
|
|
.. code-block:: bash
|
2013-03-29 17:30:10 -07:00
|
|
|
|
2014-03-13 11:46:02 -06:00
|
|
|
$ sudo docker build -t eg_sshd .
|
2013-03-29 17:30:10 -07:00
|
|
|
|
2014-02-13 16:12:21 +10:00
|
|
|
Then run it. You can then use ``docker port`` to find out what host port the container's
|
|
|
|
port 22 is mapped to:
|
2013-11-02 18:26:52 -07:00
|
|
|
|
|
|
|
.. code-block:: bash
|
2013-03-29 17:30:10 -07:00
|
|
|
|
2014-03-13 11:46:02 -06:00
|
|
|
$ sudo docker run -d -P --name test_sshd eg_sshd
|
2014-02-13 16:12:21 +10:00
|
|
|
$ sudo docker port test_sshd 22
|
|
|
|
0.0.0.0:49154
|
2013-03-29 17:30:10 -07:00
|
|
|
|
2014-02-13 16:12:21 +10: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):
|
2013-05-29 11:29:30 -07:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2014-02-13 16:12:21 +10:00
|
|
|
$ ssh root@192.168.1.2 -p 49154
|
|
|
|
# The password is ``screencast``.
|
|
|
|
$$
|
2013-05-29 11:29:30 -07:00
|
|
|
|
2014-02-13 16:12:21 +10:00
|
|
|
Finally, clean up after your test by stopping and removing the container, and
|
|
|
|
then removing the image.
|
|
|
|
|
|
|
|
.. code-block:: bash
|
2013-05-29 11:29:30 -07:00
|
|
|
|
2014-02-13 16:12:21 +10:00
|
|
|
$ sudo docker stop test_sshd
|
|
|
|
$ sudo docker rm test_sshd
|
|
|
|
$ sudo docker rmi eg_sshd
|