running_ssh_service.rst 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. Create an 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. # now let's commit it
  29. # which container was it?
  30. $ docker ps -a |more
  31. $ docker commit a30a3a2f2b130749995f5902f079dc6ad31ea0621fac595128ec59c6da07feea dhrp/sshd
  32. # I gave the name dhrp/sshd for the container
  33. # now we can run it again
  34. $ docker run -d dhrp/sshd /usr/sbin/sshd -D # D for daemon mode
  35. # is it running?
  36. $ docker ps
  37. # yes!
  38. # let's stop it
  39. $ docker stop 0ebf7cec294755399d063f4b1627980d4cbff7d999f0bc82b59c300f8536a562
  40. $ docker ps
  41. # and reconnect, but now open a port to it
  42. $ docker run -d -p 22 dhrp/sshd /usr/sbin/sshd -D
  43. $ docker port b2b407cf22cf8e7fa3736fa8852713571074536b1d31def3fdfcd9fa4fd8c8c5 22
  44. # it has now given us a port to connect to
  45. # we have to connect using a public ip of our host
  46. $ hostname
  47. $ ifconfig
  48. $ ssh root@192.168.33.10 -p 49153
  49. # Ah! forgot to set root passwd
  50. $ docker commit b2b407cf22cf8e7fa3736fa8852713571074536b1d31def3fdfcd9fa4fd8c8c5 dhrp/sshd
  51. $ docker ps -a
  52. $ docker run -i -t dhrp/sshd /bin/bash
  53. $ passwd
  54. $ exit
  55. $ docker commit 9e863f0ca0af31c8b951048ba87641d67c382d08d655c2e4879c51410e0fedc1 dhrp/sshd
  56. $ docker run -d -p 22 dhrp/sshd /usr/sbin/sshd -D
  57. $ docker port a0aaa9558c90cf5c7782648df904a82365ebacce523e4acc085ac1213bfe2206 22
  58. $ ifconfig
  59. $ ssh root@192.168.33.10 -p 49154
  60. # Thanks for watching, Thatcher thatcher@dotcloud.com