running_ssh_service.rst 2.8 KB

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