running_ssh_service.rst 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 or you can add
  18. your user to docker's group: ``sudo usermod -a -G docker <user>``.
  19. .. raw:: html
  20. <div style="margin-top:10px;">
  21. <iframe width="800" height="400" src="http://ascii.io/a/2637/raw" frameborder="0"></iframe>
  22. </div>
  23. You can also get this sshd container by using:
  24. .. code-block:: bash
  25. sudo docker pull dhrp/sshd
  26. The password is ``screencast``.
  27. **Video's Transcription:**
  28. .. code-block:: bash
  29. # Hello! We are going to try and install openssh on a container and run it as a service
  30. # let's pull ubuntu to get a base ubuntu image.
  31. $ docker pull ubuntu
  32. # I had it so it was quick
  33. # now let's connect using -i for interactive and with -t for terminal
  34. # we execute /bin/bash to get a prompt.
  35. $ docker run -i -t ubuntu /bin/bash
  36. # yes! we are in!
  37. # now lets install openssh
  38. $ apt-get update
  39. $ apt-get install openssh-server
  40. # ok. lets see if we can run it.
  41. $ which sshd
  42. # we need to create privilege separation directory
  43. $ mkdir /var/run/sshd
  44. $ /usr/sbin/sshd
  45. $ exit
  46. # now let's commit it
  47. # which container was it?
  48. $ docker ps -a |more
  49. $ docker commit a30a3a2f2b130749995f5902f079dc6ad31ea0621fac595128ec59c6da07feea dhrp/sshd
  50. # I gave the name dhrp/sshd for the container
  51. # now we can run it again
  52. $ docker run -d dhrp/sshd /usr/sbin/sshd -D # D for daemon mode
  53. # is it running?
  54. $ docker ps
  55. # yes!
  56. # let's stop it
  57. $ docker stop 0ebf7cec294755399d063f4b1627980d4cbff7d999f0bc82b59c300f8536a562
  58. $ docker ps
  59. # and reconnect, but now open a port to it
  60. $ docker run -d -p 22 dhrp/sshd /usr/sbin/sshd -D
  61. $ docker port b2b407cf22cf8e7fa3736fa8852713571074536b1d31def3fdfcd9fa4fd8c8c5 22
  62. # it has now given us a port to connect to
  63. # we have to connect using a public ip of our host
  64. $ hostname
  65. # *ifconfig* is deprecated, better use *ip addr show* now
  66. $ ifconfig
  67. $ ssh root@192.168.33.10 -p 49153
  68. # Ah! forgot to set root passwd
  69. $ docker commit b2b407cf22cf8e7fa3736fa8852713571074536b1d31def3fdfcd9fa4fd8c8c5 dhrp/sshd
  70. $ docker ps -a
  71. $ docker run -i -t dhrp/sshd /bin/bash
  72. $ passwd
  73. $ exit
  74. $ docker commit 9e863f0ca0af31c8b951048ba87641d67c382d08d655c2e4879c51410e0fedc1 dhrp/sshd
  75. $ docker run -d -p 22 dhrp/sshd /usr/sbin/sshd -D
  76. $ docker port a0aaa9558c90cf5c7782648df904a82365ebacce523e4acc085ac1213bfe2206 22
  77. # *ifconfig* is deprecated, better use *ip addr show* now
  78. $ ifconfig
  79. $ ssh root@192.168.33.10 -p 49154
  80. # Thanks for watching, Thatcher thatcher@dotcloud.com