-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
511 lines (434 loc) · 14.4 KB
/
index.html
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Docker and Ansible</title>
<meta name="description" content="Presentation slides about Docker and Ansible">
<meta name="author" content="Daniel Kraic">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/white.css" id="theme">
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="lib/css/github.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h2>Docker and Ansible</h2>
<h3>Daniel Kraic</h3>
<h4>2015-10-23</h4>
<p>
<small><a href="http://github.com/danielkraic" target="_blank">github.com/danielkraic</a></small>
<br>
<small><a href="http://blog.dkraic.com" target="_blank">blog.dkraic.com</a></small>
</p>
</section>
<section>
<section>
<img src="http://www.ansible.com/hs-fs/hub/330046/file-769078185-png/Official_Logos/ansible_wordlogo_black_medium.png?t=1445360239370" alt="">
<p>Simple. Agentless. Powerful.</p>
</section>
<section>
<h2>Ansible</h2>
<ul>
<li>configuring and managing computers</li>
<li>multi-node software deployment</li>
<li>ad hoc task execution</li>
<li>configuration management</li>
</ul>
</section>
<section>
<h2>In fact, it’s parallel ssh<br>...but done in smart way</h2>
</section>
<section>
<ul>
<li>agentless</li>
<li>connect to nodes over SSH</li>
<li>written in Python</li>
<li><code>pip install ansible</code></li>
<li>requires Python (2.4 or later) to be installed on node</li>
</ul>
</section>
<section>
<h3 style='text-transform: lowercase;'>ansible host1 -m shell -a 'uname -a'</h3>
<small style='text-transform: lowercase;'>ansible -i inventory_file host_selection -m module -a params</small>
</section>
<section>
<h2>Inventory file</h2>
<pre><code class="ini" data-trim>
[webservers]
www[01:50].example.com
[databases]
db-[a:f].example.com
[targets]
localhost ansible_connection=local
host1.com ansible_connection=ssh ansible_ssh_user=<user1></user1>
host2.com ansible_connection=ssh ansible_ssh_user=user2
</code></pre>
</section>
<section>
<h2>Modules</h2>
<ul>
<li>command, shell, script</li>
<li>copy, fetch, replace, stat, ini_file, template</li>
<li>apt, apt_key, apt_repository, composer, bower, npm, pip, cpanm, maven</li>
<li>service, authorized_keys, sysctl, cron, user, group, hostname, lvg, lvol, modprobe, mount</li>
<li>haproxy, get_url, ...</li>
</ul>
</section>
<section>
<h2>Examples</h2>
</section>
<section>
<pre><code class="bash" data-trim>
# run custom command
ansible h1 -a "echo hello"
# run as sudo, other user, ask for sudo pass
ansible h1 -a "uname" -u username --sudo [--ask-sudo-pass]
# manage httpd service
ansible h1 -m service -a "name=httpd state=started"
# manage apt packages
ansible h1 -m apt -a "name=foo update_cache=yes state=latest"
# manage apt repository
ansible h1 -m apt_repository -a "repo='ppa:nginx/stable'"
</code></pre>
</section>
<section>
<pre><code class="bash" data-trim>
# create files
ansible h1 -m file -a "dest=/tmp/f1 mode=600 owner=usr1"
# copy file
ansible h1 -m copy -a "src=/etc/hosts dest=/etc/hosts"
# fetch file
ansible h1 -m fetch -a "src=/tmp/somefile dest=/tmp/fetched"
# manage ini file
ansible h1 -m ini_file -a "dest=f.ini section=S option=V value=1"
</code></pre>
</section>
<section>
<h1>Playbook</h1>
<ul>
<li>group of task in yaml file</li>
<li>variables, handlers, includes, "host type conditions", roles</li>
<li>failed_when, ignore_errors, notify, delegate_to</li>
<li>reusable roles at <a href="https://galaxy.ansible.com/" target="_blank">galaxy.ansible.com</a></li>
</ul>
</section>
<section>
<h3>Usage</h3>
<pre><code class="bash" data-trim>
# run playbook
ansible-playbook playbook.yml
# run playbook using a parallelism level of 10
ansible-playbook playbook.yml -f 10
# list hosts that will be afected
ansible-playbook playbook.yml --list-hosts
</code></pre>
</section>
<section>
<pre><code class="yaml" data-trim>
---
- hosts: webservers
vars:
http_port: 80
tasks:
- name: ensure apache is at the latest version
yum: pkg=httpd state=latest
- name: write the apache config file
template: src=/srv/httpd.j2 dest=/etc/httpd.conf
notify:
- restart apache
- name: ensure apache is running (and enable it at boot)
service: name=httpd state=started enabled=yes
handlers:
- name: restart apache
service: name=httpd state=restarted
</code></pre>
</section>
<section>
<a href="http://www.ansible.com/" target="_blank">ansible.com</a>
<br>
<a href="https://github.com/ansible/ansible" target="_blank">github.com/ansible/ansible</a>
<br>
<a href="http://blog.dkraic.com/post/ansible/">blog.dkraic.com/post/ansible</a>
</section>
</section>
<section>
<section>
<!--<img style="background: white" src="https://muffinresearch.co.uk/content/images/2014/Aug/large_h-trans.png" alt="Docker" />-->
<img style="background: white" src="https://upload.wikimedia.org/wikipedia/commons/7/79/Docker_%28container_engine%29_logo.png" alt="Docker" />
<p>Build → Ship → Run</p>
</section>
<section>
<h2>Docker</h2>
<ul>
<li>package app with all dependencies into a container</li>
<li>build once - run everywhere (developers)</li>
<li>configure once - run anything (sys admins)</li>
<li>run on any computer, any infrastructure and any cloud</li>
</ul>
</section>
<section>
<h2>Docker container</h2>
<ul>
<li>application</li>
<li>runtime</li>
<li>libraries</li>
<li>system tools</li>
<li>complete filesystem</li>
</ul>
</section>
<section>
<h2>Container vs VM</h2>
<img style="background: white" src="http://pointful.github.io/docker-intro/docker-img/containers-vs-vms.png" alt="" />
</section>
<section>
<h2>Docker container</h2>
<ul>
<li>share linux kernel with other containers</li>
<li>run as an isolated process in userspace on the host operating system</li>
<li>uses resource isolation features of the Linux kernel - cgroups and kernel namespaces</li>
</ul>
</section>
<section>
<h2>Build → Ship → Run</h2>
<ul>
<li><strong>Build</strong> – build docker container application and all of its dependencies</li>
<li><strong>Ship</strong> – push container to public/private docker repository</li>
<li><strong>Run</strong> – pull container from repository a run it</li>
</ul>
</section>
<section>
<h2>Examples</h2>
</section>
<section>
<h2>Create + Start</h2>
<pre><code class="bash" data-trim>
docker create -i -t --name my_debian debian:jessie bash
</code></pre>
<ul>
<li><strong>-i</strong> interactive mode (keeps the STDIN open)</li>
<li><strong>-t</strong> allocates a pseudo-TTY</li>
<li><strong>–name</strong> name of the container (or generate hash string)</li>
<li><strong>debian:jessie</strong> image to be instantiated.</li>
<li><strong>bash</strong> command to run inside container</li>
</ul>
<pre><code class="bash" data-trim>
docker start -a -i my_debian
</code></pre>
<ul>
<li><strong>-a</strong> attach to the pseudo-TTY</li>
</ul>
</section>
<section>
<h2>Create + Start = Run</h2>
<pre><code class="bash" data-trim>
docker run hello-world
docker run docker/whalesay cowsay 'hello form docker'
</code></pre>
</section>
<section>
<h3>Run interactive</h3>
<pre><code class="bash" data-trim>
docker run -i -t --name my_debian debian:jessie /bin/bash
</code></pre>
<h3>Run as deamon</h3>
<pre><code class="bash" data-trim>
docker run -d --name MySQL mysql:5.7 /opt/mysql/mysqld
</code></pre>
</section>
<section>
<h3>Expose ports</h3>
<pre><code class="bash" data-trim>
docker run -d -p 8080:80 --name web nginx
</code></pre>
<p>Expose all container ports to host</p>
<pre><code class="bash" data-trim>
docker run -d -P --name web nginx
</code></pre>
</section>
<section>
<h3>Attach data</h3>
<pre><code class="bash" data-trim>
docker run --name web -p 80:80 -d \
-v /var/www:/usr/share/nginx/html:ro nginx
</code></pre>
<h3>Set ENV</h3>
<pre><code class="bash" data-trim>
docker run -i -t -e VAR1=val1 -e VAR2=val2 debian:jessie bash
</code></pre>
<h3>Exec</h3>
<pre><code class="bash" data-trim>
docker exec -i -t my_debian bash
</code></pre>
</section>
<section>
<h2>Demo: web server</h2>
<pre><code class="bash" data-trim>
echo 'hello from docker' > index.html
docker run -p 8080:80 \
-v `pwd`:/usr/share/nginx/html:ro -d nginx
# go to http://localhost:8080
</code></pre>
</section>
<section>
<h2>Control container</h2>
<pre><code class="bash" data-trim>
docker ps
docker ps -a
docker ps -a --filter 'exited=0'
docker stop my_debian
docker kill my_debian
docker rm my_debian
</code></pre>
</section>
<section>
<h2>Control images</h2>
<pre><code class="bash" data-trim>
docker search nginx
docker pull nginx
docker pull debian:squeeze
docker pull 172.16.0.1/username/image_name[:tag]
docker images
docker rmi -f nginx
</code></pre>
</section>
<section>
<h2>Link containers</h2>
<pre><code class="bash" data-trim>
docker run --name DB \
-e MYSQL_ROOT_PASSWORD=admin \
-e MYSQL_DATABASE=admin \
-d mysql:5.7
docker run -p 8080:80 \
-e WORDPRESS_DB_PASSWORD=admin \
--name WP --link DB:mysql \
-d wordpress
# go to http://localhost:8080
</code></pre>
</section>
<section>
<h2>Docker Compose</h2>
<p>tool for defining and running multi-container applications
<ul>
<li>define Dockerfile</li>
<li>define services in <code>docker-compose.yml</code></li>
<li>run <code>docker-compose up</code></li>
</ul>
</section>
<section>
<h2>Docker Hub</h2>
<p><a href="https://hub.docker.com/" target="_blank">hub.docker.com</a></p>
</section>
<section>
<h2>Dockerfile</h2>
<p>instructions to build docker images</p>
<pre><code class="bash" data-trim>
docker build -t dkraic/myapp .
</code></pre>
</section>
<section>
<pre><code class="dockerfile" data-trim>
FROM ubuntu:14.04
# install ansible
RUN apt-get update && apt-get install -y ansible
# add localhost to ansible hosts
RUN echo 'localhost ansible_connection=local' > /etc/ansible/hosts
# get ansible playbooks
COPY my-playbooks/ /etc/ansible/playbooks/
# run ansible playbook
RUN ansible-playbook /etc/ansible/playbooks/server-install.yaml
</code></pre>
</section>
<section>
<h2>Container lifecycle</h2>
<ul>
<li>docker create</li>
<li>docker run</li>
<li>docker stop</li>
<li>docker start</li>
<li>docker restart</li>
<li>docker rm</li>
<li>docker kill</li>
<li>docker attach</li>
<li>docker wait</li>
</ul>
</section>
<section>
<h2>Container info</h2>
<ul>
<li>docker ps</li>
<li>docker logs</li>
<li>docker inspect</li>
<li>docker port</li>
<li>docker top</li>
</ul>
</section>
<section>
<h2>Images</h2>
<ul>
<li>docker images</li>
<li>docker build</li>
<li>docker commit</li>
<li>docker rmi</li>
<li>docker login</li>
<li>docker search</li>
<li>docker pull</li>
<li>docker push</li>
</ul>
</section>
<section>
<a href="https://docs.docker.com/" target="_blank">docs.docker.com</a>
<br>
<a href="https://hub.docker.com/" target="_blank">hub.docker.com</a>
<br>
<a href="http://blog.dkraic.com/post/docker/">blog.dkraic.com/post/docker</a>
</section>
</section>
<section>
<p>slides:<br>
<a href="https://github.com/danielkraic/slides-docker-ansible">github.com/danielkraic/slides-docker-ansible</a>
</p>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
//transition: 'slide', // none/fade/slide/convex/concave/zoom
transition: 'convex', // none/fade/slide/convex/concave/zoom
// Optional reveal.js plugins
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, condition: function() { return !!document.querySelector( 'pre code' ); }, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true },
{ src: 'plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>