forked from labtraining/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockerexercise3.txt
More file actions
266 lines (242 loc) · 18 KB
/
Copy pathdockerexercise3.txt
File metadata and controls
266 lines (242 loc) · 18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
Exercise: Exposing Container Ports to the Host
1. Create a container from the 'centos:6' base image on your system. This container does not need to be name but should be run in daemon mode, interactive and connected to the current terminal. Finally, it should start the bash shell on start up
2. Using the appropriate Docker inspection command, find the IP address and name for the running container. Once you have the IP, ping the IP to be sure it is running. Finally, attach to the running container so you are logged into the shell.
3. From within the container, install the Open-SSH server and make sure the service is running. From another terminal, try to log into the container over SSH by IP and note the result.
4. Exit and stop the container. Remove the container from the list of previously run containers once you obtain the name from the appropriate Docker command.
5. Create another container, name this container 'test_ssh'. When creating the container, it should be run in interactive mode and attached to the current terminal running the bash shell. Finally, expose port 22 on the container to port 8022 on the host system. Once logged in, install the Open-SSH server and make sure the service is running. Find the IP address of the container and note it.
6. Install the 'sudo' utility. Add a user called 'test' and set a password for that user. Add the 'test' user to the 'sudoers' file. From another terminal window, attempt to log into the container via SSH on port 8022 as the 'test' user and confirm access.
1. Create a container from the 'centos:6' base image on your system. This container does not need to be name but should be run in daemon mode, interactive and connected to the current terminal. Finally, it should start the bash shell on start up.
[user@linuxacademy ~]$ docker run -itd docker.io/centos:6 /bin/bash
99f87625ff34a5a25af8edd7e95ad9b6a4bc70db63c2ac6e0850dd4cfae58cef
[user@linuxacademy ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
99f87625ff34 docker.io/centos:6 "/bin/bash" 3 seconds ago Up 2 seconds elegant_bohr
[user@linuxacademy ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
99f87625ff34 docker.io/centos:6 "/bin/bash" 5 seconds ago Up 5 seconds elegant_bohr
2. Using the appropriate Docker inspection command, find the IP address and name for the running container. Once you have the IP, ping the IP to be sure it is running. Finally, attach to the running container so you are logged into the shell.
[user@linuxacademy ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
99f87625ff34 docker.io/centos:6 "/bin/bash" 7 minutes ago Up 7 minutes elegant_bohr
[user@linuxacademy]$ docker inspect elegant_bohr | grep IP
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null
[user@linuxacademy ~]$ ping 172.17.0.2
PING 172.17.0.2 (172.17.0.2) 56(84) bytes of data.
64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.069 ms
64 bytes from 172.17.0.2: icmp_seq=2 ttl=64 time=0.096 ms
^C
--- 172.17.0.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.069/0.082/0.096/0.016 ms
[user@linuxacademy ~]$ docker attach elegant_bohr
[root@99f87625ff34 /]#
3. From within the container, install the Open-SSH server and make sure the service is running. From another terminal, try to log into the container over SSH by IP and note the result.
[root@99f87625ff34 /]# yum install openssh-server
... Lots of Output Here
Installed:
openssh-server.x86_64 0:5.3p1-112.el6_7
Dependency Installed:
fipscheck.x86_64 0:1.2.0-7.el6 fipscheck-lib.x86_64 0:1.2.0-7.el6 openssh.x86_64 0:5.3p1-112.el6_7
tcp_wrappers-libs.x86_64 0:7.6-57.el6
Complete!
[root@99f87625ff34 /]# service sshd start
Generating SSH2 RSA host key: [ OK ]
Generating SSH1 RSA host key: [ OK ]
Generating SSH2 DSA host key: [ OK ]
Starting sshd:
(Different Terminal)
[user@linuxacademy ~]$ ssh test@172.17.0.2
ssh: connect to host 172.17.0.2 port 22: Connection refused
4. Exit and stop the container. Remove the container from the list of previously run containers once you obtain the name from the appropriate Docker command.
[user@linuxacademy ~]$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
99f87625ff34 docker.io/centos:6 "/bin/bash" About an hour ago Exited (0) 4 seconds ago elegant_bohr
8ef073d5c7f4 docker.io/centos:6 "/bin/bash" About an hour ago Exited (0) About an hour ago silly_poincare
[user@linuxacademy ~]$ docker rm elegant_bohr
elegant_bohr
[user@linuxacademy ~]$ docker rm silly_poincare
silly_poincare
[user@linuxacademy ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
docker.io/ubuntu latest 91e54dfb1179 4 days ago 188.3 MB
docker.io/centos 6 a005304e4e74 9 weeks ago 203.1 MB
[user@linuxacademy ~]$
5. Create another container, name this container 'test_ssh'. When creating the container, it should be run in interactive mode and attached to the current terminal running the bash shell. Finally, expose port 22 on the container to port 8022 on the host system. Once logged in, install the Open-SSH server and make sure the service is running. Find the IP address of the container and note it.
[user@linuxacademy ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[user@linuxacademy ~]$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
99f87625ff34 docker.io/centos:6 "/bin/bash" About an hour ago Exited (0) 4 seconds ago elegant_bohr
8ef073d5c7f4 docker.io/centos:6 "/bin/bash" About an hour ago Exited (0) About an hour ago silly_poincare
[user@linuxacademy ~]$ docker rm elegant_bohr
elegant_bohr
[user@linuxacademy ~]$ docker rm silly_poincare
silly_poincare
[user@linuxacademy ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
docker.io/ubuntu latest 91e54dfb1179 4 days ago 188.3 MB
docker.io/centos 6 a005304e4e74 9 weeks ago 203.1 MB
[user@linuxacademy ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
docker.io/ubuntu latest 91e54dfb1179 4 days ago 188.3 MB
docker.io/centos 6 a005304e4e74 9 weeks ago 203.1 MB
[user@linuxacademy ~]$ docker run -it --name="test_ssh" -p 8022:22 docker.io/centos:6 /bin/bash
Usage of loopback devices is strongly discouraged for production use. Either use `--storage-opt dm.thinpooldev` or use `--storage-opt dm.no_warn_on_loop_devices=true` to suppress this warning.
[root@de1119934beb /]# yum install openssh-server
Loaded plugins: fastestmirror
Setting up Install Process
base | 3.7 kB 00:00
base/primary_db | 4.6 MB 00:07
extras | 3.4 kB 00:00
extras/primary_db | 27 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 1.3 MB 00:01
Resolving Dependencies
--> Running transaction check
---> Package openssh-server.x86_64 0:5.3p1-112.el6_7 will be installed
--> Processing Dependency: openssh = 5.3p1-112.el6_7 for package: openssh-server-5.3p1-112.el6_7.x86_64
--> Processing Dependency: libwrap.so.0()(64bit) for package: openssh-server-5.3p1-112.el6_7.x86_64
--> Processing Dependency: libfipscheck.so.1()(64bit) for package: openssh-server-5.3p1-112.el6_7.x86_64
--> Running transaction check
---> Package fipscheck-lib.x86_64 0:1.2.0-7.el6 will be installed
--> Processing Dependency: /usr/bin/fipscheck for package: fipscheck-lib-1.2.0-7.el6.x86_64
---> Package openssh.x86_64 0:5.3p1-112.el6_7 will be installed
---> Package tcp_wrappers-libs.x86_64 0:7.6-57.el6 will be installed
--> Running transaction check
---> Package fipscheck.x86_64 0:1.2.0-7.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================
Installing:
openssh-server x86_64 5.3p1-112.el6_7 updates 324 k
Installing for dependencies:
fipscheck x86_64 1.2.0-7.el6 base 14 k
fipscheck-lib x86_64 1.2.0-7.el6 base 8.3 k
openssh x86_64 5.3p1-112.el6_7 updates 274 k
tcp_wrappers-libs x86_64 7.6-57.el6 base 62 k
Transaction Summary
===============================================================================================================================
Install 5 Package(s)
Total download size: 682 k
Installed size: 1.6 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): fipscheck-1.2.0-7.el6.x86_64.rpm | 14 kB 00:00
(2/5): fipscheck-lib-1.2.0-7.el6.x86_64.rpm | 8.3 kB 00:00
(3/5): openssh-5.3p1-112.el6_7.x86_64.rpm | 274 kB 00:00
(4/5): openssh-server-5.3p1-112.el6_7.x86_64.rpm | 324 kB 00:00
(5/5): tcp_wrappers-libs-7.6-57.el6.x86_64.rpm | 62 kB 00:00
-------------------------------------------------------------------------------------------------------------------------------
Total 306 kB/s | 682 kB 00:02
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
Userid : CentOS-6 Key (CentOS 6 Official Signing Key) <centos-6-key@centos.org>
Package: centos-release-6-6.el6.centos.12.2.x86_64 (@CentOS/$releasever)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Installing : fipscheck-1.2.0-7.el6.x86_64 1/5
Installing : fipscheck-lib-1.2.0-7.el6.x86_64 2/5
Installing : openssh-5.3p1-112.el6_7.x86_64 3/5
Installing : tcp_wrappers-libs-7.6-57.el6.x86_64 4/5
Installing : openssh-server-5.3p1-112.el6_7.x86_64 5/5
Verifying : tcp_wrappers-libs-7.6-57.el6.x86_64 1/5
Verifying : fipscheck-lib-1.2.0-7.el6.x86_64 2/5
Verifying : fipscheck-1.2.0-7.el6.x86_64 3/5
Verifying : openssh-5.3p1-112.el6_7.x86_64 4/5
Verifying : openssh-server-5.3p1-112.el6_7.x86_64 5/5
Installed:
openssh-server.x86_64 0:5.3p1-112.el6_7
Dependency Installed:
fipscheck.x86_64 0:1.2.0-7.el6 fipscheck-lib.x86_64 0:1.2.0-7.el6 openssh.x86_64 0:5.3p1-112.el6_7
tcp_wrappers-libs.x86_64 0:7.6-57.el6
Complete!
[root@de1119934beb /]# service sshd start
Generating SSH2 RSA host key: [ OK ]
Generating SSH1 RSA host key: [ OK ]
Generating SSH2 DSA host key: [ OK ]
Starting sshd: [ OK ]
[root@de1119934beb /]# ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:03
inet addr:172.17.0.3 Bcast:0.0.0.0 Mask:255.255.0.0
inet6 addr: fe80::42:acff:fe11:3/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3944 errors:0 dropped:0 overruns:0 frame:0
TX packets:2104 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:7151212 (6.8 MiB) TX bytes:116622 (113.8 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
[root@de1119934beb /]#
6. Install the 'sudo' utility. Add a user called 'test' and set a password for that user. Add the 'test' user to the 'sudoers' file. From another terminal window, attempt to log into the container via SSH on port 8022 as the 'test' user and confirm access.
[root@de1119934beb /]# yum install sudo
Loaded plugins: fastestmirror
Setting up Install Process
Determining fastest mirrors
* base: repos.dfw.quadranet.com
* extras: centos.mirror.lstn.net
* updates: mirror.steadfast.net
Resolving Dependencies
--> Running transaction check
---> Package sudo.x86_64 0:1.8.6p3-20.el6_7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================
Installing:
sudo x86_64 1.8.6p3-20.el6_7 updates 707 k
Transaction Summary
===============================================================================================================================
Install 1 Package(s)
Total download size: 707 k
Installed size: 2.4 M
Is this ok [y/N]: y
Downloading Packages:
sudo-1.8.6p3-20.el6_7.x86_64.rpm | 707 kB 00:02
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : sudo-1.8.6p3-20.el6_7.x86_64 1/1
Verifying : sudo-1.8.6p3-20.el6_7.x86_64 1/1
Installed:
sudo.x86_64 0:1.8.6p3-20.el6_7
Complete!
[root@de1119934beb /]# adduser test
[root@de1119934beb /]# passwd test
Changing password for user test.
New password:
BAD PASSWORD: it is based on a dictionary word
Retype new password:
passwd: all authentication tokens updated successfully.
[root@de1119934beb /]#
(Other Terminal Window)
[user@linuxacademy ~]$ ssh test@172.17.0.3
The authenticity of host '172.17.0.3 (172.17.0.3)' can't be established.
RSA key fingerprint is e8:5e:28:d8:64:1f:81:3a:d9:4c:2c:0c:8e:a1:27:b7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.17.0.3' (RSA) to the list of known hosts.
test@172.17.0.3's password:
[test@de1119934beb ~]$