2013-04-04 01:21:57 -04:00
|
|
|
:title: Running an SSH service
|
2014-02-13 01:12:21 -05:00
|
|
|
:description: Installing and running an sshd service
|
2013-04-04 01:21:57 -04:00
|
|
|
:keywords: docker, example, package installation, networking
|
|
|
|
|
|
|
|
.. _running_ssh_service:
|
2013-03-29 20:30:10 -04:00
|
|
|
|
2013-06-02 01:03:28 -04:00
|
|
|
SSH Daemon Service
|
|
|
|
==================
|
2013-03-29 20:30:10 -04:00
|
|
|
|
2013-04-07 10:23:00 -04:00
|
|
|
.. include:: example_header.inc
|
2013-03-29 20:30:10 -04:00
|
|
|
|
2014-02-13 01:12:21 -05: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 20:30:10 -04:00
|
|
|
|
2014-02-13 01:12:21 -05:00
|
|
|
.. literalinclude:: running_ssh_service.Dockerfile
|
2013-03-29 20:30:10 -04:00
|
|
|
|
2014-02-13 01:12:21 -05:00
|
|
|
Build the image using:
|
2013-08-13 21:05:35 -04:00
|
|
|
|
2014-02-13 01:12:21 -05:00
|
|
|
.. code-block:: bash
|
2013-03-29 20:30:10 -04:00
|
|
|
|
2014-02-13 01:12:21 -05:00
|
|
|
$ sudo docker build -rm -t eg_sshd .
|
2013-03-29 20:30:10 -04:00
|
|
|
|
2014-02-13 01:12:21 -05: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 21:26:52 -04:00
|
|
|
|
|
|
|
.. code-block:: bash
|
2013-03-29 20:30:10 -04:00
|
|
|
|
2014-02-13 01:12:21 -05:00
|
|
|
$ sudo docker run -d -P -name test_sshd eg_sshd
|
|
|
|
$ sudo docker port test_sshd 22
|
|
|
|
0.0.0.0:49154
|
2013-03-29 20:30:10 -04:00
|
|
|
|
2014-02-13 01:12:21 -05: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 14:29:30 -04:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2014-02-13 01:12:21 -05:00
|
|
|
$ ssh root@192.168.1.2 -p 49154
|
|
|
|
# The password is ``screencast``.
|
|
|
|
$$
|
2013-05-29 14:29:30 -04:00
|
|
|
|
2014-02-13 01:12:21 -05:00
|
|
|
Finally, clean up after your test by stopping and removing the container, and
|
|
|
|
then removing the image.
|
|
|
|
|
|
|
|
.. code-block:: bash
|
2013-05-29 14:29:30 -04:00
|
|
|
|
2014-02-13 01:12:21 -05:00
|
|
|
$ sudo docker stop test_sshd
|
|
|
|
$ sudo docker rm test_sshd
|
|
|
|
$ sudo docker rmi eg_sshd
|