running_ssh_service.rst 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. :title: Running an SSH service
  2. :description: Installing and running an sshd service
  3. :keywords: docker, example, package installation, networking
  4. .. _running_ssh_service:
  5. SSH Daemon Service
  6. ==================
  7. .. include:: example_header.inc
  8. The following Dockerfile sets up an sshd service in a container that you can use
  9. to connect to and inspect other container's volumes, or to get quick access to a
  10. test container.
  11. .. literalinclude:: running_ssh_service.Dockerfile
  12. Build the image using:
  13. .. code-block:: bash
  14. $ sudo docker build -t eg_sshd .
  15. Then run it. You can then use ``docker port`` to find out what host port the container's
  16. port 22 is mapped to:
  17. .. code-block:: bash
  18. $ sudo docker run -d -P --name test_sshd eg_sshd
  19. $ sudo docker port test_sshd 22
  20. 0.0.0.0:49154
  21. And now you can ssh to port ``49154`` on the Docker daemon's host IP address
  22. (``ip address`` or ``ifconfig`` can tell you that):
  23. .. code-block:: bash
  24. $ ssh root@192.168.1.2 -p 49154
  25. # The password is ``screencast``.
  26. $$
  27. Finally, clean up after your test by stopping and removing the container, and
  28. then removing the image.
  29. .. code-block:: bash
  30. $ sudo docker stop test_sshd
  31. $ sudo docker rm test_sshd
  32. $ sudo docker rmi eg_sshd