Browse code

update the sshd example to use just a Dockerfile

Docker-DCO-1.1-Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au> (github: SvenDowideit)

Sven Dowideit authored on 2014/02/13 15:12:21
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,17 @@
0
+# sshd
1
+#
2
+# VERSION               0.0.1
3
+
4
+FROM     ubuntu
5
+MAINTAINER Thatcher R. Peskens "thatcher@dotcloud.com"
6
+
7
+# make sure the package repository is up to date
8
+RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
9
+RUN apt-get update
10
+
11
+RUN apt-get install -y openssh-server
12
+RUN mkdir /var/run/sshd 
13
+RUN echo 'root:screencast' |chpasswd
14
+
15
+EXPOSE 22
16
+CMD    /usr/sbin/sshd -D
... ...
@@ -1,5 +1,5 @@
1 1
 :title: Running an SSH service
2
-:description: A screencast of installing and running an sshd service
2
+:description: Installing and running an sshd service
3 3
 :keywords: docker, example, package installation, networking
4 4
 
5 5
 .. _running_ssh_service:
... ...
@@ -9,101 +9,41 @@ SSH Daemon Service
9 9
 
10 10
 .. include:: example_header.inc
11 11
 
12
+The following Dockerfile sets up an sshd service in a container that you can use
13
+to connect to and inspect other container's volumes, or to get quick access to a
14
+test container.
12 15
 
13
-**Video:**
16
+.. literalinclude:: running_ssh_service.Dockerfile
14 17
 
15
-I've created a little screencast to show how to create an SSHd service
16
-and connect to it. It is something like 11 minutes and not entirely
17
-smooth, but it gives you a good idea.
18
+Build the image using:
18 19
 
19
-.. note::
20
-   This screencast was created before Docker version 0.5.2, so the
21
-   daemon is unprotected and available via a TCP port. When you run
22
-   through the same steps in a newer version of Docker, you will
23
-   need to add ``sudo`` in front of each ``docker`` command in order
24
-   to reach the daemon over its protected Unix socket.
20
+.. code-block:: bash
25 21
 
26
-.. raw:: html
22
+    $ sudo docker build -rm -t eg_sshd .
27 23
 
28
-   <iframe width="815" height="450" frameborder="0"
29
-           sandbox="allow-same-origin allow-scripts" 
30
-   srcdoc="<body><script type=&quot;text/javascript&quot; 
31
-           src=&quot;https://asciinema.org/a/2637.js&quot; 
32
-           id=&quot;asciicast-2637&quot; async></script></body>">
33
-   </iframe>
34
-        
35
-You can also get this sshd container by using:
24
+Then run it. You can then use ``docker port`` to find out what host port the container's
25
+port 22 is mapped to:
36 26
 
37 27
 .. code-block:: bash
38 28
 
39
-    sudo docker pull dhrp/sshd
40
-
41
-
42
-The password is ``screencast``.
29
+    $ sudo docker run -d -P -name test_sshd eg_sshd
30
+    $ sudo docker port test_sshd 22
31
+    0.0.0.0:49154
43 32
 
44
-**Video's Transcription:**
33
+And now you can ssh to port ``49154`` on the Docker daemon's host IP address 
34
+(``ip address`` or ``ifconfig`` can tell you that):
45 35
 
46 36
 .. code-block:: bash
47 37
 
48
-         # Hello! We are going to try and install openssh on a container and run it as a service
49
-         # let's pull ubuntu to get a base ubuntu image. 
50
-         $ docker pull ubuntu
51
-         # I had it so it was quick
52
-         # now let's connect using -i for interactive and with -t for terminal 
53
-         # we execute /bin/bash to get a prompt.
54
-         $ docker run -i -t ubuntu /bin/bash
55
-         # yes! we are in!
56
-         # now lets install openssh
57
-         $ apt-get update
58
-         $ apt-get install openssh-server
59
-         # ok. lets see if we can run it.
60
-         $ which sshd
61
-         # we need to create privilege separation directory
62
-         $ mkdir /var/run/sshd
63
-         $ /usr/sbin/sshd
64
-         $ exit
65
-         # now let's commit it 
66
-         # which container was it?
67
-         $ docker ps -a |more
68
-         $ docker commit a30a3a2f2b130749995f5902f079dc6ad31ea0621fac595128ec59c6da07feea dhrp/sshd 
69
-         # I gave the name dhrp/sshd for the container
70
-         # now we can run it again 
71
-         $ docker run -d dhrp/sshd /usr/sbin/sshd -D # D for daemon mode 
72
-         # is it running?
73
-         $ docker ps
74
-         # yes!
75
-         # let's stop it 
76
-         $ docker stop 0ebf7cec294755399d063f4b1627980d4cbff7d999f0bc82b59c300f8536a562
77
-         $ docker ps
78
-         # and reconnect, but now open a port to it
79
-         $ docker run -d -p 22 dhrp/sshd /usr/sbin/sshd -D 
80
-         $ docker port b2b407cf22cf8e7fa3736fa8852713571074536b1d31def3fdfcd9fa4fd8c8c5 22
81
-         # it has now given us a port to connect to
82
-         # we have to connect using a public ip of our host
83
-         $ hostname
84
-         # *ifconfig* is deprecated, better use *ip addr show* now
85
-         $ ifconfig
86
-         $ ssh root@192.168.33.10 -p 49153
87
-         # Ah! forgot to set root passwd
88
-         $ docker commit b2b407cf22cf8e7fa3736fa8852713571074536b1d31def3fdfcd9fa4fd8c8c5 dhrp/sshd 
89
-         $ docker ps -a
90
-         $ docker run -i -t dhrp/sshd /bin/bash
91
-         $ passwd
92
-         $ exit
93
-         $ docker commit 9e863f0ca0af31c8b951048ba87641d67c382d08d655c2e4879c51410e0fedc1 dhrp/sshd
94
-         $ docker run -d -p 22 dhrp/sshd /usr/sbin/sshd -D
95
-         $ docker port a0aaa9558c90cf5c7782648df904a82365ebacce523e4acc085ac1213bfe2206 22
96
-         # *ifconfig* is deprecated, better use *ip addr show* now
97
-         $ ifconfig
98
-         $ ssh root@192.168.33.10 -p 49154
99
-         # Thanks for watching, Thatcher thatcher@dotcloud.com
100
-         
101
-Update:
102
-
103
-For Ubuntu 13.10 using stackbrew/ubuntu, you may need do these additional steps:
104
-
105
-1. change /etc/pam.d/sshd, pam_loginuid line 'required' to 'optional'
106
-2. echo LANG=\"en_US.UTF-8\" > /etc/default/locale
38
+    $ ssh root@192.168.1.2 -p 49154
39
+    # The password is ``screencast``.
40
+    $$
107 41
 
42
+Finally, clean up after your test by stopping and removing the container, and
43
+then removing the image.
44
+
45
+.. code-block:: bash
108 46
 
47
+    $ sudo docker stop test_sshd
48
+    $ sudo docker rm test_sshd
49
+    $ sudo docker rmi eg_sshd