running_ssh_service.rst 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. :title: Running an SSH service
  2. :description: A screencast of 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. **Video:**
  9. I've create a little screencast to show how to create a sshd service
  10. and connect to it. It is something like 11 minutes and not entirely
  11. smooth, but gives you a good idea.
  12. .. note::
  13. This screencast was created before ``docker`` version 0.5.2, so the
  14. daemon is unprotected and available via a TCP port. When you run
  15. through the same steps in a newer version of ``docker``, you will
  16. need to add ``sudo`` in front of each ``docker`` command in order
  17. to reach the daemon over its protected Unix socket.
  18. .. raw:: html
  19. <div style="margin-top:10px;">
  20. <iframe width="800" height="400" src="http://ascii.io/a/2637/raw" frameborder="0"></iframe>
  21. </div>
  22. You can also get this sshd container by using
  23. ::
  24. sudo docker pull dhrp/sshd
  25. The password is 'screencast'
  26. **Video's Transcription:**
  27. .. code-block:: bash
  28. # Hello! We are going to try and install openssh on a container and run it as a service
  29. # let's pull ubuntu to get a base ubuntu image.
  30. $ docker pull ubuntu
  31. # I had it so it was quick
  32. # now let's connect using -i for interactive and with -t for terminal
  33. # we execute /bin/bash to get a prompt.
  34. $ docker run -i -t ubuntu /bin/bash
  35. # yes! we are in!
  36. # now lets install openssh
  37. $ apt-get update
  38. $ apt-get install openssh-server
  39. # ok. lets see if we can run it.
  40. $ which sshd
  41. # we need to create privilege separation directory
  42. $ mkdir /var/run/sshd
  43. $ /usr/sbin/sshd
  44. $ exit
  45. # now let's commit it
  46. # which container was it?
  47. $ docker ps -a |more
  48. $ docker commit a30a3a2f2b130749995f5902f079dc6ad31ea0621fac595128ec59c6da07feea dhrp/sshd
  49. # I gave the name dhrp/sshd for the container
  50. # now we can run it again
  51. $ docker run -d dhrp/sshd /usr/sbin/sshd -D # D for daemon mode
  52. # is it running?
  53. $ docker ps
  54. # yes!
  55. # let's stop it
  56. $ docker stop 0ebf7cec294755399d063f4b1627980d4cbff7d999f0bc82b59c300f8536a562
  57. $ docker ps
  58. # and reconnect, but now open a port to it
  59. $ docker run -d -p 22 dhrp/sshd /usr/sbin/sshd -D
  60. $ docker port b2b407cf22cf8e7fa3736fa8852713571074536b1d31def3fdfcd9fa4fd8c8c5 22
  61. # it has now given us a port to connect to
  62. # we have to connect using a public ip of our host
  63. $ hostname
  64. # *ifconfig* is deprecated, better use *ip addr show* now
  65. $ ifconfig
  66. $ ssh root@192.168.33.10 -p 49153
  67. # Ah! forgot to set root passwd
  68. $ docker commit b2b407cf22cf8e7fa3736fa8852713571074536b1d31def3fdfcd9fa4fd8c8c5 dhrp/sshd
  69. $ docker ps -a
  70. $ docker run -i -t dhrp/sshd /bin/bash
  71. $ passwd
  72. $ exit
  73. $ docker commit 9e863f0ca0af31c8b951048ba87641d67c382d08d655c2e4879c51410e0fedc1 dhrp/sshd
  74. $ docker run -d -p 22 dhrp/sshd /usr/sbin/sshd -D
  75. $ docker port a0aaa9558c90cf5c7782648df904a82365ebacce523e4acc085ac1213bfe2206 22
  76. # *ifconfig* is deprecated, better use *ip addr show* now
  77. $ ifconfig
  78. $ ssh root@192.168.33.10 -p 49154
  79. # Thanks for watching, Thatcher thatcher@dotcloud.com