running_ssh_service.rst 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 created a little screencast to show how to create an SSHd service
  10. and connect to it. It is something like 11 minutes and not entirely
  11. smooth, but it 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. <iframe width="815" height="450" frameborder="0"
  20. sandbox="allow-same-origin allow-scripts"
  21. srcdoc="<body><script type=&quot;text/javascript&quot;
  22. src=&quot;https://asciinema.org/a/2637.js&quot;
  23. id=&quot;asciicast-2637&quot; async></script></body>">
  24. </iframe>
  25. You can also get this sshd container by using:
  26. .. code-block:: bash
  27. sudo docker pull dhrp/sshd
  28. The password is ``screencast``.
  29. **Video's Transcription:**
  30. .. code-block:: bash
  31. # Hello! We are going to try and install openssh on a container and run it as a service
  32. # let's pull ubuntu to get a base ubuntu image.
  33. $ docker pull ubuntu
  34. # I had it so it was quick
  35. # now let's connect using -i for interactive and with -t for terminal
  36. # we execute /bin/bash to get a prompt.
  37. $ docker run -i -t ubuntu /bin/bash
  38. # yes! we are in!
  39. # now lets install openssh
  40. $ apt-get update
  41. $ apt-get install openssh-server
  42. # ok. lets see if we can run it.
  43. $ which sshd
  44. # we need to create privilege separation directory
  45. $ mkdir /var/run/sshd
  46. $ /usr/sbin/sshd
  47. $ exit
  48. # now let's commit it
  49. # which container was it?
  50. $ docker ps -a |more
  51. $ docker commit a30a3a2f2b130749995f5902f079dc6ad31ea0621fac595128ec59c6da07feea dhrp/sshd
  52. # I gave the name dhrp/sshd for the container
  53. # now we can run it again
  54. $ docker run -d dhrp/sshd /usr/sbin/sshd -D # D for daemon mode
  55. # is it running?
  56. $ docker ps
  57. # yes!
  58. # let's stop it
  59. $ docker stop 0ebf7cec294755399d063f4b1627980d4cbff7d999f0bc82b59c300f8536a562
  60. $ docker ps
  61. # and reconnect, but now open a port to it
  62. $ docker run -d -p 22 dhrp/sshd /usr/sbin/sshd -D
  63. $ docker port b2b407cf22cf8e7fa3736fa8852713571074536b1d31def3fdfcd9fa4fd8c8c5 22
  64. # it has now given us a port to connect to
  65. # we have to connect using a public ip of our host
  66. $ hostname
  67. # *ifconfig* is deprecated, better use *ip addr show* now
  68. $ ifconfig
  69. $ ssh root@192.168.33.10 -p 49153
  70. # Ah! forgot to set root passwd
  71. $ docker commit b2b407cf22cf8e7fa3736fa8852713571074536b1d31def3fdfcd9fa4fd8c8c5 dhrp/sshd
  72. $ docker ps -a
  73. $ docker run -i -t dhrp/sshd /bin/bash
  74. $ passwd
  75. $ exit
  76. $ docker commit 9e863f0ca0af31c8b951048ba87641d67c382d08d655c2e4879c51410e0fedc1 dhrp/sshd
  77. $ docker run -d -p 22 dhrp/sshd /usr/sbin/sshd -D
  78. $ docker port a0aaa9558c90cf5c7782648df904a82365ebacce523e4acc085ac1213bfe2206 22
  79. # *ifconfig* is deprecated, better use *ip addr show* now
  80. $ ifconfig
  81. $ ssh root@192.168.33.10 -p 49154
  82. # Thanks for watching, Thatcher thatcher@dotcloud.com
  83. Update:
  84. -------
  85. For Ubuntu 13.10 using stackbrew/ubuntu, you may need do these additional steps:
  86. 1. change /etc/pam.d/sshd, pam_loginuid line 'required' to 'optional'
  87. 2. echo LANG=\"en_US.UTF-8\" > /etc/default/locale