├── .gitignore ├── LICENSE.md ├── README.md ├── Rakefile ├── containers ├── Containers.pptx ├── container_resources.txt ├── containers.pdf └── docker-container-solutions.md ├── diagrams ├── 12factor-container.png ├── Docker-Intro.graffle │ ├── data.plist │ └── image1.png ├── ciao-explicit-port.png ├── ciao-random-port.png ├── containers-vs-vms.png ├── cow-vs-data-volume.png ├── images-and-containers.png ├── nginx-ciao.png ├── port-mapping-to-host.png ├── shared-network.png ├── shared-volume.png ├── two-distros-one-kernel.png └── unix-kernel.png ├── exercises ├── ciao-proxy │ ├── .dockerignore │ ├── Dockerfile │ ├── Makefile │ ├── README.md │ ├── docker-compose.yml │ ├── nginx.conf │ ├── proxy.conf.sh │ └── run ├── ciao │ ├── Dockerfile │ ├── Makefile │ ├── docker-compose.yml │ ├── index.js │ └── package.json ├── composed │ ├── autobuilt │ │ └── docker-compose.yml │ ├── basic-exercise │ │ └── docker-compose.yml │ ├── basic │ │ └── docker-compose.yml │ ├── sharing-exercise │ │ ├── dates │ │ └── docker-compose.yml │ ├── sharing │ │ └── docker-compose.yml │ ├── with-curl-exercise │ │ └── docker-compose.yml │ └── with-curl │ │ └── docker-compose.yml ├── containers.html ├── example-voting-app │ ├── .gitignore │ ├── LICENSE │ ├── MAINTAINERS │ ├── README.md │ ├── architecture.png │ ├── docker-compose-javaworker.yml │ ├── docker-compose-simple.yml │ ├── docker-compose.yml │ ├── docker-stack.yml │ ├── dockercloud.yml │ ├── result │ │ ├── .vscode │ │ │ └── launch.json │ │ ├── Dockerfile │ │ ├── docker-compose.test.yml │ │ ├── package.json │ │ ├── server.js │ │ ├── tests │ │ │ ├── Dockerfile │ │ │ ├── render.js │ │ │ └── tests.sh │ │ └── views │ │ │ ├── app.js │ │ │ ├── index.html │ │ │ ├── socket.io.js │ │ │ └── stylesheets │ │ │ └── style.css │ ├── vote │ │ ├── Dockerfile │ │ ├── app.py │ │ ├── requirements.txt │ │ ├── static │ │ │ └── stylesheets │ │ │ │ └── style.css │ │ └── templates │ │ │ └── index.html │ └── worker │ │ ├── Dockerfile │ │ ├── Dockerfile.j │ │ ├── pom.xml │ │ └── src │ │ ├── Worker │ │ ├── Program.cs │ │ └── Worker.csproj │ │ └── main │ │ └── java │ │ └── worker │ │ └── Worker.java ├── hello │ ├── Dockerfile │ └── hello.sh ├── index.md ├── mysite │ ├── Dockerfile │ └── docs │ │ └── index.html ├── refdata │ ├── Dockerfile │ └── words └── ubuntu-with-curl │ └── Dockerfile ├── index.html ├── js └── remark-latest.min.js ├── media ├── REA.png ├── compose.png ├── docker-hub.png ├── docker │ ├── small_h-dark-trans.png │ ├── small_h-dark.png │ ├── small_h-trans.png │ ├── small_h.png │ ├── small_v-dark-trans.png │ ├── small_v-dark.png │ ├── small_v-trans.png │ └── small_v.png ├── favicon.png ├── linux_docker_host.svg └── mac_docker_host.svg ├── setup.sh └── styles.css /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *~ 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Attribution 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More_considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution 4.0 International Public License 58 | 59 | By exercising the Licensed Rights (defined below), You accept and agree 60 | to be bound by the terms and conditions of this Creative Commons 61 | Attribution 4.0 International Public License ("Public License"). To the 62 | extent this Public License may be interpreted as a contract, You are 63 | granted the Licensed Rights in consideration of Your acceptance of 64 | these terms and conditions, and the Licensor grants You such rights in 65 | consideration of benefits the Licensor receives from making the 66 | Licensed Material available under these terms and conditions. 67 | 68 | 69 | Section 1 -- Definitions. 70 | 71 | a. Adapted Material means material subject to Copyright and Similar 72 | Rights that is derived from or based upon the Licensed Material 73 | and in which the Licensed Material is translated, altered, 74 | arranged, transformed, or otherwise modified in a manner requiring 75 | permission under the Copyright and Similar Rights held by the 76 | Licensor. For purposes of this Public License, where the Licensed 77 | Material is a musical work, performance, or sound recording, 78 | Adapted Material is always produced where the Licensed Material is 79 | synched in timed relation with a moving image. 80 | 81 | b. Adapter's License means the license You apply to Your Copyright 82 | and Similar Rights in Your contributions to Adapted Material in 83 | accordance with the terms and conditions of this Public License. 84 | 85 | c. Copyright and Similar Rights means copyright and/or similar rights 86 | closely related to copyright including, without limitation, 87 | performance, broadcast, sound recording, and Sui Generis Database 88 | Rights, without regard to how the rights are labeled or 89 | categorized. For purposes of this Public License, the rights 90 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 91 | Rights. 92 | 93 | d. Effective Technological Measures means those measures that, in the 94 | absence of proper authority, may not be circumvented under laws 95 | fulfilling obligations under Article 11 of the WIPO Copyright 96 | Treaty adopted on December 20, 1996, and/or similar international 97 | agreements. 98 | 99 | e. Exceptions and Limitations means fair use, fair dealing, and/or 100 | any other exception or limitation to Copyright and Similar Rights 101 | that applies to Your use of the Licensed Material. 102 | 103 | f. Licensed Material means the artistic or literary work, database, 104 | or other material to which the Licensor applied this Public 105 | License. 106 | 107 | g. Licensed Rights means the rights granted to You subject to the 108 | terms and conditions of this Public License, which are limited to 109 | all Copyright and Similar Rights that apply to Your use of the 110 | Licensed Material and that the Licensor has authority to license. 111 | 112 | h. Licensor means the individual(s) or entity(ies) granting rights 113 | under this Public License. 114 | 115 | i. Share means to provide material to the public by any means or 116 | process that requires permission under the Licensed Rights, such 117 | as reproduction, public display, public performance, distribution, 118 | dissemination, communication, or importation, and to make material 119 | available to the public including in ways that members of the 120 | public may access the material from a place and at a time 121 | individually chosen by them. 122 | 123 | j. Sui Generis Database Rights means rights other than copyright 124 | resulting from Directive 96/9/EC of the European Parliament and of 125 | the Council of 11 March 1996 on the legal protection of databases, 126 | as amended and/or succeeded, as well as other essentially 127 | equivalent rights anywhere in the world. 128 | 129 | k. You means the individual or entity exercising the Licensed Rights 130 | under this Public License. Your has a corresponding meaning. 131 | 132 | 133 | Section 2 -- Scope. 134 | 135 | a. License grant. 136 | 137 | 1. Subject to the terms and conditions of this Public License, 138 | the Licensor hereby grants You a worldwide, royalty-free, 139 | non-sublicensable, non-exclusive, irrevocable license to 140 | exercise the Licensed Rights in the Licensed Material to: 141 | 142 | a. reproduce and Share the Licensed Material, in whole or 143 | in part; and 144 | 145 | b. produce, reproduce, and Share Adapted Material. 146 | 147 | 2. Exceptions and Limitations. For the avoidance of doubt, where 148 | Exceptions and Limitations apply to Your use, this Public 149 | License does not apply, and You do not need to comply with 150 | its terms and conditions. 151 | 152 | 3. Term. The term of this Public License is specified in Section 153 | 6(a). 154 | 155 | 4. Media and formats; technical modifications allowed. The 156 | Licensor authorizes You to exercise the Licensed Rights in 157 | all media and formats whether now known or hereafter created, 158 | and to make technical modifications necessary to do so. The 159 | Licensor waives and/or agrees not to assert any right or 160 | authority to forbid You from making technical modifications 161 | necessary to exercise the Licensed Rights, including 162 | technical modifications necessary to circumvent Effective 163 | Technological Measures. For purposes of this Public License, 164 | simply making modifications authorized by this Section 2(a) 165 | (4) never produces Adapted Material. 166 | 167 | 5. Downstream recipients. 168 | 169 | a. Offer from the Licensor -- Licensed Material. Every 170 | recipient of the Licensed Material automatically 171 | receives an offer from the Licensor to exercise the 172 | Licensed Rights under the terms and conditions of this 173 | Public License. 174 | 175 | b. No downstream restrictions. You may not offer or impose 176 | any additional or different terms or conditions on, or 177 | apply any Effective Technological Measures to, the 178 | Licensed Material if doing so restricts exercise of the 179 | Licensed Rights by any recipient of the Licensed 180 | Material. 181 | 182 | 6. No endorsement. Nothing in this Public License constitutes or 183 | may be construed as permission to assert or imply that You 184 | are, or that Your use of the Licensed Material is, connected 185 | with, or sponsored, endorsed, or granted official status by, 186 | the Licensor or others designated to receive attribution as 187 | provided in Section 3(a)(1)(A)(i). 188 | 189 | b. Other rights. 190 | 191 | 1. Moral rights, such as the right of integrity, are not 192 | licensed under this Public License, nor are publicity, 193 | privacy, and/or other similar personality rights; however, to 194 | the extent possible, the Licensor waives and/or agrees not to 195 | assert any such rights held by the Licensor to the limited 196 | extent necessary to allow You to exercise the Licensed 197 | Rights, but not otherwise. 198 | 199 | 2. Patent and trademark rights are not licensed under this 200 | Public License. 201 | 202 | 3. To the extent possible, the Licensor waives any right to 203 | collect royalties from You for the exercise of the Licensed 204 | Rights, whether directly or through a collecting society 205 | under any voluntary or waivable statutory or compulsory 206 | licensing scheme. In all other cases the Licensor expressly 207 | reserves any right to collect such royalties. 208 | 209 | 210 | Section 3 -- License Conditions. 211 | 212 | Your exercise of the Licensed Rights is expressly made subject to the 213 | following conditions. 214 | 215 | a. Attribution. 216 | 217 | 1. If You Share the Licensed Material (including in modified 218 | form), You must: 219 | 220 | a. retain the following if it is supplied by the Licensor 221 | with the Licensed Material: 222 | 223 | i. identification of the creator(s) of the Licensed 224 | Material and any others designated to receive 225 | attribution, in any reasonable manner requested by 226 | the Licensor (including by pseudonym if 227 | designated); 228 | 229 | ii. a copyright notice; 230 | 231 | iii. a notice that refers to this Public License; 232 | 233 | iv. a notice that refers to the disclaimer of 234 | warranties; 235 | 236 | v. a URI or hyperlink to the Licensed Material to the 237 | extent reasonably practicable; 238 | 239 | b. indicate if You modified the Licensed Material and 240 | retain an indication of any previous modifications; and 241 | 242 | c. indicate the Licensed Material is licensed under this 243 | Public License, and include the text of, or the URI or 244 | hyperlink to, this Public License. 245 | 246 | 2. You may satisfy the conditions in Section 3(a)(1) in any 247 | reasonable manner based on the medium, means, and context in 248 | which You Share the Licensed Material. For example, it may be 249 | reasonable to satisfy the conditions by providing a URI or 250 | hyperlink to a resource that includes the required 251 | information. 252 | 253 | 3. If requested by the Licensor, You must remove any of the 254 | information required by Section 3(a)(1)(A) to the extent 255 | reasonably practicable. 256 | 257 | 4. If You Share Adapted Material You produce, the Adapter's 258 | License You apply must not prevent recipients of the Adapted 259 | Material from complying with this Public License. 260 | 261 | 262 | Section 4 -- Sui Generis Database Rights. 263 | 264 | Where the Licensed Rights include Sui Generis Database Rights that 265 | apply to Your use of the Licensed Material: 266 | 267 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 268 | to extract, reuse, reproduce, and Share all or a substantial 269 | portion of the contents of the database; 270 | 271 | b. if You include all or a substantial portion of the database 272 | contents in a database in which You have Sui Generis Database 273 | Rights, then the database in which You have Sui Generis Database 274 | Rights (but not its individual contents) is Adapted Material; and 275 | 276 | c. You must comply with the conditions in Section 3(a) if You Share 277 | all or a substantial portion of the contents of the database. 278 | 279 | For the avoidance of doubt, this Section 4 supplements and does not 280 | replace Your obligations under this Public License where the Licensed 281 | Rights include other Copyright and Similar Rights. 282 | 283 | 284 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 285 | 286 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 287 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 288 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 289 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 290 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 291 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 292 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 293 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 294 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 295 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 296 | 297 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 298 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 299 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 300 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 301 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 302 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 303 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 304 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 305 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 306 | 307 | c. The disclaimer of warranties and limitation of liability provided 308 | above shall be interpreted in a manner that, to the extent 309 | possible, most closely approximates an absolute disclaimer and 310 | waiver of all liability. 311 | 312 | 313 | Section 6 -- Term and Termination. 314 | 315 | a. This Public License applies for the term of the Copyright and 316 | Similar Rights licensed here. However, if You fail to comply with 317 | this Public License, then Your rights under this Public License 318 | terminate automatically. 319 | 320 | b. Where Your right to use the Licensed Material has terminated under 321 | Section 6(a), it reinstates: 322 | 323 | 1. automatically as of the date the violation is cured, provided 324 | it is cured within 30 days of Your discovery of the 325 | violation; or 326 | 327 | 2. upon express reinstatement by the Licensor. 328 | 329 | For the avoidance of doubt, this Section 6(b) does not affect any 330 | right the Licensor may have to seek remedies for Your violations 331 | of this Public License. 332 | 333 | c. For the avoidance of doubt, the Licensor may also offer the 334 | Licensed Material under separate terms or conditions or stop 335 | distributing the Licensed Material at any time; however, doing so 336 | will not terminate this Public License. 337 | 338 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 339 | License. 340 | 341 | 342 | Section 7 -- Other Terms and Conditions. 343 | 344 | a. The Licensor shall not be bound by any additional or different 345 | terms or conditions communicated by You unless expressly agreed. 346 | 347 | b. Any arrangements, understandings, or agreements regarding the 348 | Licensed Material not stated herein are separate from and 349 | independent of the terms and conditions of this Public License. 350 | 351 | 352 | Section 8 -- Interpretation. 353 | 354 | a. For the avoidance of doubt, this Public License does not, and 355 | shall not be interpreted to, reduce, limit, restrict, or impose 356 | conditions on any use of the Licensed Material that could lawfully 357 | be made without permission under this Public License. 358 | 359 | b. To the extent possible, if any provision of this Public License is 360 | deemed unenforceable, it shall be automatically reformed to the 361 | minimum extent necessary to make it enforceable. If the provision 362 | cannot be reformed, it shall be severed from this Public License 363 | without affecting the enforceability of the remaining terms and 364 | conditions. 365 | 366 | c. No term or condition of this Public License will be waived and no 367 | failure to comply consented to unless expressly agreed to by the 368 | Licensor. 369 | 370 | d. Nothing in this Public License constitutes or may be interpreted 371 | as a limitation upon, or waiver of, any privileges and immunities 372 | that apply to the Licensor or You, including from the legal 373 | processes of any jurisdiction or authority. 374 | 375 | 376 | ======================================================================= 377 | 378 | Creative Commons is not a party to its public 379 | licenses. Notwithstanding, Creative Commons may elect to apply one of 380 | its public licenses to material it publishes and in those instances 381 | will be considered the “Licensor.” The text of the Creative Commons 382 | public licenses is dedicated to the public domain under the CC0 Public 383 | Domain Dedication. Except for the limited purpose of indicating that 384 | material is shared under a Creative Commons public license or as 385 | otherwise permitted by the Creative Commons policies published at 386 | creativecommons.org/policies, Creative Commons does not authorize the 387 | use of the trademark "Creative Commons" or any other trademark or logo 388 | of Creative Commons without its prior written consent including, 389 | without limitation, in connection with any unauthorized modifications 390 | to any of its public licenses or any other arrangements, 391 | understandings, or agreements concerning use of licensed material. For 392 | the avoidance of doubt, this paragraph does not form part of the 393 | public licenses. 394 | 395 | Creative Commons may be contacted at creativecommons.org. 396 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # An introduction to Docker 2 | 3 | This is material for REA's internal introductory Docker training. 4 | 5 | The slide-deck is implemented in HTML and Javascript, so is 6 | easy to run in any browser. Open `index.html` to start. 7 | 8 | If you are digesting this material as part of organised training, 9 | we recommend running through the setup process *before* you turn 10 | up on the day: 11 | 12 | 1. Install Docker and Docker Compose 13 | 14 | - [Docker for Mac](https://docs.docker.com/docker-for-mac/) is a good option. 15 | 16 | or 17 | 18 | ``` 19 | brew tap caskroom/cask 20 | brew cask install docker 21 | ``` 22 | 23 | 2. Clone this repository 24 | 25 | ``` 26 | git clone https://github.com/realestate-com-au/intro-to-docker.git 27 | ``` 28 | 29 | 3. Run `./setup.sh` (estimated download size is 1.5GB) 30 | 31 | ``` 32 | $ ./setup.sh 33 | YAY: /var/run/docker.sock exists 34 | YAY: I can talk to docker 35 | 36 | Docker is at localhost 37 | 38 | YAY: docker version 1.12.0 39 | YAY: docker-compose version 1.8.0 40 | 41 | Pulling some images to get you started ... 42 | ``` 43 | 44 | 4. You can then open the slides from your local copy: 45 | 46 | ``` 47 | open index.html 48 | ``` 49 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | task "default" => "exercises/index.md" 2 | 3 | file "exercises/index.md" => "index.html" do |t| 4 | puts "re-generating #{t.name}" 5 | slides_body = File.read("index.html") 6 | .sub(%r{.*.*}m) { $1 } 7 | slides = slides_body.split("---\n") 8 | slides.each do |slide| 9 | slide.sub!(/.*^# /m, '# ') 10 | end 11 | File.open(t.name, "w") do |exercises| 12 | slides.each do |slide| 13 | next unless slide =~ /^# Try it:/ 14 | exercises.puts slide 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /containers/Containers.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/containers/Containers.pptx -------------------------------------------------------------------------------- /containers/container_resources.txt: -------------------------------------------------------------------------------- 1 | Container vs VM (good visualisation) 2 | https://www.google.com/url?sa=i&source=images&cd=&cad=rja&uact=8&ved=2ahUKEwjupvewqcXhAhWHdH0KHWtPCs0QjRx6BAgBEAU&url=https://medium.com/devopslinks/docker-containers-vms-and-orchestration-technology-for-the-beginners-68ae979bce5a&psig=AOvVaw2HsTmmxMvS2PTe72z8qyFe&ust=1554978735176428 3 | 4 | Best resource for the exercises we will be doing 5 | https://docs.docker.com/engine/reference/commandline 6 | 7 | Docker run (most used) 8 | https://docs.docker.com/engine/reference/commandline/run/ 9 | 10 | Exposing ports 11 | https://docs.docker.com/engine/reference/run/#expose-incoming-ports 12 | 13 | Docker network 14 | https://docs.docker.com/engine/reference/commandline/network/ 15 | 16 | Docker volume 17 | https://docs.docker.com/storage/volumes/ 18 | 19 | Docker bind mount 20 | https://docs.docker.com/storage/bind-mounts/ 21 | 22 | Understanding volumes 23 | https://www.ionos.com/community/server-cloud-infrastructure/docker/understanding-and-managing-docker-container-volumes/ 24 | 25 | Docker logs 26 | https://docs.docker.com/engine/reference/commandline/logs/ 27 | 28 | Customer docker images used in the exercises 29 | realestata/ciao --> https://git.realestate.com.au/cowbell/intro-to-docker/tree/gh-pages/exercises/ciao 30 | realestate/ciao-proxy --> https://git.realestate.com.au/cowbell/intro-to-docker/tree/gh-pages/exercises/ciao-proxy 31 | 32 | 33 | ------------------------------------------------------------------------------------------- 34 | 35 | SOLUTIONS 36 | https://git.realestate.com.au/bharg-sharma/docker-training/blob/master/docker-container-solutions.txt 37 | -------------------------------------------------------------------------------- /containers/containers.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/containers/containers.pdf -------------------------------------------------------------------------------- /containers/docker-container-solutions.md: -------------------------------------------------------------------------------- 1 | #### CONTAINER BASICS 2 | 3 | Current running containers 4 | ``` 5 | docker ps 6 | ``` 7 | 8 | Current containers 9 | ``` 10 | docker ps -a 11 | ``` 12 | 13 | List container ids only 14 | ``` 15 | docker ps -aq 16 | ``` 17 | 18 | Stopping a container 19 | ``` 20 | docker stop 21 | ``` 22 | 23 | Stop running containers using their ids 24 | ``` 25 | docker stop $(docker ps -aq) 26 | ``` 27 | 28 | Re-starting a container 29 | ``` 30 | docker start 31 | ``` 32 | 33 | Remove the containers once stopped 34 | ``` 35 | docker rm 36 | ``` 37 | Force remove a container (stops and removes the container, it can be dangerous if there are unsaved changes) 38 | 39 | ``` 40 | docker rm -f 41 | ``` 42 | 43 | Remove unused containers (that have been stopped) 44 | ``` 45 | docker container prune 46 | ``` 47 | 48 | Create a container using an image 49 | ``` 50 | docker run --rm -it --name bharg realestate/ciao bash 51 | ``` 52 | 53 | Run in daemon mode 54 | ``` 55 | docker run -d --name bharg realestate/ciao 56 | ``` 57 | 58 | Changing something in the container 59 | ``` 60 | docker exec -it bharg bash 61 | cd ~ 62 | echo persistence! > my_file.txt 63 | ``` 64 | 65 | #### PORTS 66 | 67 | Current ports occupied 68 | ``` 69 | docker ps --> PORTS 70 | docker port 71 | ``` 72 | 73 | Publishing a specific port 74 | ``` 75 | docker run -d --name expose -p 1234:80 realestate/ciao 76 | curl localhost:1234 --> Ciao Mondo! 77 | ``` 78 | 79 | Publishing a random port 80 | ``` 81 | docker run -d --name random -p 80 realestate/ciao 82 | curl $(docker port random 80) 83 | ``` 84 | 85 | #### NETWORKS 86 | 87 | Our containers 88 | ``` 89 | docker run -d --name proxy realestate/ciao-proxy --> reverse proxy 90 | docker run -d --name bharg_app realestate/ciao --> the app 91 | ``` 92 | 93 | Check our current networks 94 | ``` 95 | docker network ls 96 | ``` 97 | 98 | Create a network 99 | ``` 100 | docker network create shared 101 | ``` 102 | 103 | Run containers in the network, expose a port 104 | ``` 105 | docker run -d --name app --network=shared realestate/ciao 106 | docker run -d --name proxy --network=shared -p 5678:80 realestate/ciao 107 | ``` 108 | 109 | Check we can access the app 110 | ``` 111 | curl localhost:5678 112 | ``` 113 | 114 | Check containers are running 115 | ``` 116 | docker container ls 117 | ``` 118 | 119 | Check the containers are in the correct network 120 | ``` 121 | docker network inspect shared 122 | ``` 123 | 124 | Remove the network 125 | ``` 126 | docker network rm -f shared 127 | docker network prune 128 | ``` 129 | 130 | #### VOLUMES 131 | 132 | Mounting a volume 133 | ``` 134 | set MY_PATH=~/Documents 135 | docker run -it --name bind_mount -v $MY_PATH:/notes ubuntu bash 136 | mount | grep notes --> mount looks for any filesystems that have been recently mounted 137 | ``` 138 | 139 | Persistence in a volume 140 | ``` 141 | cd /notes; ls 142 | echo I mounted a dir! > mount-in-docker 143 | docker stop 144 | docker start 145 | ``` 146 | 147 | Creating a named volume 148 | ``` 149 | docker run -it --rm -v my-cache:/cache ubuntu bash 150 | echo TESTING > /cache/test 151 | ``` 152 | 153 | Checking volume exists 154 | ``` 155 | docker volume ls 156 | ``` 157 | 158 | Checking the /cache exists 159 | ``` 160 | docker run -it --rm -v my-cache:/cache ubuntu bash 161 | ls /cache 162 | ``` 163 | 164 | Removing the volume 165 | ``` 166 | docker volume rm my-cache 167 | ``` 168 | 169 | Creating an anonymous volume with read-only rights (more secure) 170 | ``` 171 | docker run -it --rm --read-only -v /more_space ubuntu bash 172 | ``` 173 | 174 | Sharing a volume 175 | Setting up the provider 176 | ``` 177 | docker run -it --rm --name provider -v data:/publish ubuntu 178 | echo not here > /publish/wheres-the-money 179 | ``` 180 | 181 | Setting up the consumer (consume the volume) 182 | ``` 183 | docker run -it --rm --name consumer -v data:/extract ubuntu 184 | ``` 185 | Find the volume 186 | ``` 187 | cat /extract/wheres-the-money 188 | ``` 189 | 190 | #### LOGS 191 | 192 | Getting logs for a container 193 | ``` 194 | docker logs 195 | ``` 196 | 197 | Displaying timestamp and detailed log 198 | ``` 199 | docker logs --detail -t 200 | ``` 201 | 202 | Real time output 203 | ``` 204 | docker logs --follow --timestamps 205 | ``` 206 | 207 | #### ENV VARS 208 | 209 | Processing an env variable 210 | ``` 211 | docker run -d —name Bharg -p 1234:80 -e MESSAGE='Works for me' 212 | ``` 213 | 214 | Check you get the new greeting 215 | ``` 216 | curl localhost:1234 217 | ``` 218 | -------------------------------------------------------------------------------- /diagrams/12factor-container.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/diagrams/12factor-container.png -------------------------------------------------------------------------------- /diagrams/Docker-Intro.graffle/image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/diagrams/Docker-Intro.graffle/image1.png -------------------------------------------------------------------------------- /diagrams/ciao-explicit-port.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/diagrams/ciao-explicit-port.png -------------------------------------------------------------------------------- /diagrams/ciao-random-port.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/diagrams/ciao-random-port.png -------------------------------------------------------------------------------- /diagrams/containers-vs-vms.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/diagrams/containers-vs-vms.png -------------------------------------------------------------------------------- /diagrams/cow-vs-data-volume.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/diagrams/cow-vs-data-volume.png -------------------------------------------------------------------------------- /diagrams/images-and-containers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/diagrams/images-and-containers.png -------------------------------------------------------------------------------- /diagrams/nginx-ciao.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/diagrams/nginx-ciao.png -------------------------------------------------------------------------------- /diagrams/port-mapping-to-host.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/diagrams/port-mapping-to-host.png -------------------------------------------------------------------------------- /diagrams/shared-network.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/diagrams/shared-network.png -------------------------------------------------------------------------------- /diagrams/shared-volume.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/diagrams/shared-volume.png -------------------------------------------------------------------------------- /diagrams/two-distros-one-kernel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/diagrams/two-distros-one-kernel.png -------------------------------------------------------------------------------- /diagrams/unix-kernel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/diagrams/unix-kernel.png -------------------------------------------------------------------------------- /exercises/ciao-proxy/.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | -------------------------------------------------------------------------------- /exercises/ciao-proxy/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx@sha256:0fe6413f3e30fcc5920bc8fa769280975b10b1c26721de956e1428b9e2f29d04 2 | 3 | RUN rm /etc/nginx/conf.d/default.conf 4 | 5 | COPY nginx.conf /etc/nginx/nginx.conf 6 | COPY proxy.conf.sh /nginx/proxy.conf.sh 7 | COPY run /nginx/run 8 | 9 | CMD ["/nginx/run"] 10 | 11 | EXPOSE 80 12 | -------------------------------------------------------------------------------- /exercises/ciao-proxy/Makefile: -------------------------------------------------------------------------------- 1 | REPOSITORY = realestate/ciao-proxy 2 | VERSION := $(shell TZ=Australia/Melbourne date +'%Y%m%d%H%M') 3 | 4 | default: image 5 | 6 | image: 7 | docker build -t $(REPOSITORY) . 8 | 9 | release: image 10 | docker tag $(REPOSITORY):latest $(REPOSITORY):$(VERSION) 11 | docker push $(REPOSITORY):latest 12 | docker push $(REPOSITORY):$(VERSION) 13 | -------------------------------------------------------------------------------- /exercises/ciao-proxy/README.md: -------------------------------------------------------------------------------- 1 | # nginx-reverse-proxy 2 | 3 | This is a simple Docker-ization of Nginx, designed for use as a reverse-proxy in front of app-servers (like Unicorn) that don't like slow clients. 4 | 5 | ## Usage 6 | 7 | This image expects a linked "app" container to be provided. The app container should have an HTTP app-server listening on port `${NGINX_APP_PORT-5000}`. 8 | 9 | e.g. 10 | 11 | # start app-server 12 | docker run --name theapp -d tutum/hello-world 13 | 14 | # wrap it with an Nginx proxy 15 | docker run --name nginx -p 80:80 --link theapp:app \ 16 | nginx-reverse-proxy 17 | -------------------------------------------------------------------------------- /exercises/ciao-proxy/docker-compose.yml: -------------------------------------------------------------------------------- 1 | hello: 2 | image: tutum/hello-world 3 | 4 | nginx: 5 | build: . 6 | environment: 7 | BACKEND: app 8 | PORT: 5000 9 | links: 10 | - hello:app 11 | ports: 12 | - 8080:5000 13 | -------------------------------------------------------------------------------- /exercises/ciao-proxy/nginx.conf: -------------------------------------------------------------------------------- 1 | user www-data; 2 | worker_processes auto; 3 | pid /run/nginx.pid; 4 | 5 | events { 6 | worker_connections 768; 7 | # multi_accept on; 8 | } 9 | 10 | http { 11 | 12 | ## 13 | # Basic Settings 14 | ## 15 | 16 | sendfile on; 17 | tcp_nopush on; 18 | tcp_nodelay on; 19 | types_hash_max_size 2048; 20 | # server_tokens off; 21 | 22 | # server_names_hash_bucket_size 64; 23 | # server_name_in_redirect off; 24 | 25 | include /etc/nginx/mime.types; 26 | default_type application/octet-stream; 27 | 28 | ## 29 | # Logging Settings 30 | ## 31 | 32 | log_format keyvalue 'ip=$remote_addr user=$remote_user ' 33 | 'req="$request" status=$status bytes_sent=$body_bytes_sent ' 34 | 'req_time=$request_time ref="$http_referer" ' 35 | 'ua="$http_user_agent" forwarded="$http_x_forwarded_for" ' 36 | 'cache_status=$upstream_cache_status ' 37 | 'upstream_response_time=$upstream_response_time'; 38 | 39 | access_log /dev/stdout keyvalue; 40 | error_log /dev/stderr; 41 | 42 | ## 43 | # Gzip Settings 44 | ## 45 | 46 | gzip on; 47 | gzip_disable "MSIE [1-6]\.(?!.*SV1)"; 48 | 49 | gzip_vary on; 50 | gzip_proxied any; 51 | gzip_comp_level 6; 52 | gzip_buffers 16 8k; 53 | gzip_http_version 1.1; 54 | gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; 55 | 56 | ## 57 | # Virtual Host Configs 58 | ## 59 | 60 | include /etc/nginx/conf.d/*.conf; 61 | } 62 | 63 | daemon off; 64 | -------------------------------------------------------------------------------- /exercises/ciao-proxy/proxy.conf.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | cat < /etc/nginx/conf.d/proxy.conf 4 | 5 | exec nginx 6 | -------------------------------------------------------------------------------- /exercises/ciao/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:6.2.2 2 | 3 | COPY package.json /app/ 4 | WORKDIR /app 5 | RUN npm install 6 | COPY index.js /app/ 7 | 8 | ENV PORT 80 9 | EXPOSE 80 10 | CMD ["node", "/app/index.js"] 11 | -------------------------------------------------------------------------------- /exercises/ciao/Makefile: -------------------------------------------------------------------------------- 1 | REPOSITORY = realestate/ciao 2 | VERSION := $(shell TZ=Australia/Melbourne date +'%Y%m%d%H%M') 3 | 4 | image: 5 | docker build -t $(REPOSITORY):latest . 6 | 7 | release: image 8 | docker tag $(REPOSITORY):latest $(REPOSITORY):$(VERSION) 9 | docker push $(REPOSITORY):latest 10 | docker push $(REPOSITORY):$(VERSION) 11 | -------------------------------------------------------------------------------- /exercises/ciao/docker-compose.yml: -------------------------------------------------------------------------------- 1 | dev: 2 | image: node:6.2.2 3 | volumes: 4 | - .:/app 5 | working_dir: /app 6 | command: bash 7 | -------------------------------------------------------------------------------- /exercises/ciao/index.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | 3 | // Constants 4 | var PORT = (process.env.PORT || "80"); 5 | var MESSAGE = (process.env.MESSAGE || "Ciao mondo."); 6 | 7 | // SIGINT handler 8 | process.on('SIGINT', function() { 9 | console.log("Caught interrupt signal"); 10 | process.exit(); 11 | }); 12 | 13 | // App 14 | var app = express(); 15 | app.get('/', function (req, res) { 16 | console.log("Saying: " + MESSAGE); 17 | res.send(MESSAGE + '\n'); 18 | }); 19 | 20 | app.listen(PORT); 21 | console.log('Running on http://localhost:' + PORT); 22 | -------------------------------------------------------------------------------- /exercises/ciao/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ciao", 3 | "private": true, 4 | "version": "0.0.1", 5 | "description": "Node.js Hello world app", 6 | "dependencies": { 7 | "express": ">=3.11.0" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /exercises/composed/autobuilt/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | 5 | app: 6 | build: ../../ciao 7 | 8 | proxy: 9 | build: ../../ciao-proxy 10 | depends_on: 11 | - app 12 | environment: 13 | BACKEND: app 14 | ports: 15 | - 5678:80 16 | -------------------------------------------------------------------------------- /exercises/composed/basic-exercise/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | 5 | app: {} 6 | 7 | proxy: 8 | image: realestate/ciao-proxy 9 | -------------------------------------------------------------------------------- /exercises/composed/basic/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | 5 | app: 6 | image: realestate/ciao 7 | 8 | proxy: 9 | image: realestate/ciao-proxy 10 | depends_on: 11 | - app 12 | environment: 13 | BACKEND: app 14 | ports: 15 | - 5678:80 16 | -------------------------------------------------------------------------------- /exercises/composed/sharing-exercise/dates: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/exercises/composed/sharing-exercise/dates -------------------------------------------------------------------------------- /exercises/composed/sharing-exercise/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | 5 | consumer: 6 | image: ubuntu:16.04 7 | volumes: 8 | - .:/data 9 | command: tail -f /data/dates 10 | -------------------------------------------------------------------------------- /exercises/composed/sharing/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | volumes: 4 | shared: {} 5 | 6 | services: 7 | 8 | producer: 9 | image: busybox 10 | volumes: 11 | - shared:/out 12 | command: sh -c "while true; do date; sleep 1; done > /out/dates" 13 | 14 | consumer: 15 | image: ubuntu:16.04 16 | depends_on: 17 | - producer 18 | volumes: 19 | - shared:/data 20 | command: tail -f /data/dates 21 | -------------------------------------------------------------------------------- /exercises/composed/with-curl-exercise/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | 5 | app: 6 | image: realestate/ciao 7 | 8 | proxy: 9 | image: realestate/ciao-proxy 10 | depends_on: 11 | - app 12 | environment: 13 | BACKEND: app 14 | ports: 15 | - 5678:80 16 | -------------------------------------------------------------------------------- /exercises/composed/with-curl/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | 5 | app: 6 | image: realestate/ciao 7 | 8 | proxy: 9 | image: realestate/ciao-proxy 10 | depends_on: 11 | - app 12 | environment: 13 | BACKEND: app 14 | ports: 15 | - 5678:80 16 | 17 | client: 18 | build: ../../ubuntu-with-curl 19 | depends_on: 20 | - proxy 21 | command: sh -c "while true; do curl http://proxy; sleep 1; done" 22 | -------------------------------------------------------------------------------- /exercises/containers.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | An introduction to Docker: Container Exercises 5 | 6 | 7 | 8 | 9 | 10 | 167 | 169 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /exercises/example-voting-app/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | project.lock.json 3 | bin/ 4 | obj/ -------------------------------------------------------------------------------- /exercises/example-voting-app/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | Copyright 2016 Docker, Inc. 180 | 181 | Licensed under the Apache License, Version 2.0 (the "License"); 182 | you may not use this file except in compliance with the License. 183 | You may obtain a copy of the License at 184 | 185 | http://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable law or agreed to in writing, software 188 | distributed under the License is distributed on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 190 | See the License for the specific language governing permissions and 191 | limitations under the License. 192 | -------------------------------------------------------------------------------- /exercises/example-voting-app/MAINTAINERS: -------------------------------------------------------------------------------- 1 | Aanand Prasad 2 | Ben Firshman 3 | Fernando Mayo 4 | Mano Marks 5 | Maxime Heckel 6 | -------------------------------------------------------------------------------- /exercises/example-voting-app/README.md: -------------------------------------------------------------------------------- 1 | Example Voting App 2 | ========= 3 | 4 | Getting started 5 | --------------- 6 | 7 | Download [Docker](https://www.docker.com/products/overview). If you are on Mac or Windows, [Docker Compose](https://docs.docker.com/compose) will be automatically installed. On Linux, make sure you have the latest version of [Compose](https://docs.docker.com/compose/install/). 8 | 9 | Run in this directory: 10 | ``` 11 | docker-compose up 12 | ``` 13 | The app will be running at [http://localhost:5000](http://localhost:5000), and the results will be at [http://localhost:5001](http://localhost:5001). 14 | 15 | Alternately, if you want to run it on a [Docker Swarm](https://docs.docker.com/engine/swarm/), first make sure you have a swarm. If you don't, run: 16 | ``` 17 | docker swarm init 18 | ``` 19 | Once you have your swarm, in this directory run: 20 | ``` 21 | docker stack deploy --compose-file docker-stack.yml vote 22 | ``` 23 | 24 | Architecture 25 | ----- 26 | 27 | ![Architecture diagram](architecture.png) 28 | 29 | * A Python webapp which lets you vote between two options 30 | * A Redis queue which collects new votes 31 | * A .NET worker which consumes votes and stores them in… 32 | * A Postgres database backed by a Docker volume 33 | * A Node.js webapp which shows the results of the voting in real time 34 | 35 | 36 | Note 37 | ---- 38 | 39 | The voting application only accepts one vote per client. It does not register votes if a vote has already been submitted from a client. -------------------------------------------------------------------------------- /exercises/example-voting-app/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/exercises/example-voting-app/architecture.png -------------------------------------------------------------------------------- /exercises/example-voting-app/docker-compose-javaworker.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | vote: 5 | build: ./vote 6 | command: python app.py 7 | volumes: 8 | - ./vote:/app 9 | ports: 10 | - "5000:80" 11 | networks: 12 | - front-tier 13 | - back-tier 14 | 15 | result: 16 | build: ./result 17 | command: nodemon --debug server.js 18 | volumes: 19 | - ./result:/app 20 | ports: 21 | - "5001:80" 22 | - "5858:5858" 23 | networks: 24 | - front-tier 25 | - back-tier 26 | 27 | worker: 28 | build: 29 | context: ./worker 30 | dockerfile: Dockerfile.j 31 | networks: 32 | - back-tier 33 | 34 | redis: 35 | image: redis:alpine 36 | container_name: redis 37 | ports: ["6379"] 38 | networks: 39 | - back-tier 40 | 41 | db: 42 | image: postgres:9.4 43 | container_name: db 44 | volumes: 45 | - "db-data:/var/lib/postgresql/data" 46 | networks: 47 | - back-tier 48 | 49 | volumes: 50 | db-data: 51 | 52 | networks: 53 | front-tier: 54 | back-tier: 55 | -------------------------------------------------------------------------------- /exercises/example-voting-app/docker-compose-simple.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | vote: 5 | build: ./vote 6 | command: python app.py 7 | volumes: 8 | - ./vote:/app 9 | ports: 10 | - "5000:80" 11 | 12 | redis: 13 | image: redis:alpine 14 | ports: ["6379"] 15 | 16 | worker: 17 | build: ./worker 18 | 19 | db: 20 | image: postgres:9.4 21 | 22 | result: 23 | build: ./result 24 | command: nodemon --debug server.js 25 | volumes: 26 | - ./result:/app 27 | ports: 28 | - "5001:80" 29 | - "5858:5858" 30 | -------------------------------------------------------------------------------- /exercises/example-voting-app/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | vote: 5 | build: ./vote 6 | command: python app.py 7 | volumes: 8 | - ./vote:/app 9 | ports: 10 | - "5000:80" 11 | networks: 12 | - front-tier 13 | - back-tier 14 | 15 | result: 16 | build: ./result 17 | command: nodemon --debug server.js 18 | volumes: 19 | - ./result:/app 20 | ports: 21 | - "5001:80" 22 | - "5858:5858" 23 | networks: 24 | - front-tier 25 | - back-tier 26 | 27 | worker: 28 | build: ./worker 29 | networks: 30 | - back-tier 31 | 32 | redis: 33 | image: redis:alpine 34 | container_name: redis 35 | ports: ["6379"] 36 | networks: 37 | - back-tier 38 | 39 | db: 40 | image: postgres:9.6 41 | container_name: db 42 | volumes: 43 | - "db-data:/var/lib/postgresql/data" 44 | networks: 45 | - back-tier 46 | 47 | volumes: 48 | db-data: 49 | 50 | networks: 51 | front-tier: 52 | back-tier: 53 | -------------------------------------------------------------------------------- /exercises/example-voting-app/docker-stack.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | 4 | redis: 5 | image: redis:alpine 6 | ports: 7 | - "6379" 8 | networks: 9 | - frontend 10 | deploy: 11 | replicas: 2 12 | update_config: 13 | parallelism: 2 14 | delay: 10s 15 | restart_policy: 16 | condition: on-failure 17 | db: 18 | image: postgres:9.4 19 | volumes: 20 | - db-data:/var/lib/postgresql/data 21 | networks: 22 | - backend 23 | deploy: 24 | placement: 25 | constraints: [node.role == manager] 26 | vote: 27 | image: dockersamples/examplevotingapp_vote:before 28 | ports: 29 | - 5000:80 30 | networks: 31 | - frontend 32 | depends_on: 33 | - redis 34 | deploy: 35 | replicas: 2 36 | update_config: 37 | parallelism: 2 38 | restart_policy: 39 | condition: on-failure 40 | result: 41 | image: dockersamples/examplevotingapp_result:before 42 | ports: 43 | - 5001:80 44 | networks: 45 | - backend 46 | depends_on: 47 | - db 48 | deploy: 49 | replicas: 1 50 | update_config: 51 | parallelism: 2 52 | delay: 10s 53 | restart_policy: 54 | condition: on-failure 55 | 56 | worker: 57 | image: dockersamples/examplevotingapp_worker 58 | networks: 59 | - frontend 60 | - backend 61 | deploy: 62 | mode: replicated 63 | replicas: 1 64 | labels: [APP=VOTING] 65 | restart_policy: 66 | condition: on-failure 67 | delay: 10s 68 | max_attempts: 3 69 | window: 120s 70 | placement: 71 | constraints: [node.role == manager] 72 | 73 | visualizer: 74 | image: dockersamples/visualizer:stable 75 | ports: 76 | - "8080:8080" 77 | stop_grace_period: 1m30s 78 | volumes: 79 | - "/var/run/docker.sock:/var/run/docker.sock" 80 | deploy: 81 | placement: 82 | constraints: [node.role == manager] 83 | 84 | networks: 85 | frontend: 86 | backend: 87 | 88 | volumes: 89 | db-data: 90 | -------------------------------------------------------------------------------- /exercises/example-voting-app/dockercloud.yml: -------------------------------------------------------------------------------- 1 | db: 2 | image: 'postgres:9.4' 3 | restart: always 4 | redis: 5 | image: 'redis:latest' 6 | restart: always 7 | result: 8 | autoredeploy: true 9 | image: 'docker/example-voting-app-result:latest' 10 | ports: 11 | - '80:80' 12 | restart: always 13 | lb: 14 | autoredeploy: true 15 | image: 'dockercloud/haproxy:latest' 16 | links: 17 | - vote 18 | ports: 19 | - "80:80" 20 | roles: 21 | - global 22 | restart: always 23 | vote: 24 | autoredeploy: true 25 | image: 'docker/example-voting-app-vote:latest' 26 | restart: always 27 | target_num_containers: 5 28 | 29 | worker: 30 | autoredeploy: true 31 | image: 'docker/example-voting-app-worker:latest' 32 | restart: always 33 | target_num_containers: 3 34 | -------------------------------------------------------------------------------- /exercises/example-voting-app/result/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Attach", 6 | "type": "node", 7 | "request": "attach", 8 | "port": 5858, 9 | "address": "localhost", 10 | "restart": true, 11 | "sourceMaps": false, 12 | "outDir": null, 13 | "localRoot": "${workspaceRoot}", 14 | "remoteRoot": "/app", 15 | "timeout": 10000 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /exercises/example-voting-app/result/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:5.11.0-slim 2 | 3 | WORKDIR /app 4 | 5 | RUN npm install -g nodemon 6 | ADD package.json /app/package.json 7 | RUN npm config set registry http://registry.npmjs.org 8 | RUN npm install && npm ls 9 | RUN mv /app/node_modules /node_modules 10 | 11 | ADD . /app 12 | 13 | ENV PORT 80 14 | EXPOSE 80 15 | 16 | CMD ["node", "server.js"] 17 | -------------------------------------------------------------------------------- /exercises/example-voting-app/result/docker-compose.test.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | 5 | sut: 6 | build: ./tests/ 7 | depends_on: 8 | - vote 9 | - result 10 | - worker 11 | networks: 12 | - front-tier 13 | 14 | vote: 15 | build: ../vote/ 16 | ports: ["80"] 17 | depends_on: 18 | - redis 19 | - db 20 | networks: 21 | - front-tier 22 | - back-tier 23 | 24 | result: 25 | build: . 26 | ports: ["80"] 27 | depends_on: 28 | - redis 29 | - db 30 | networks: 31 | - front-tier 32 | - back-tier 33 | 34 | worker: 35 | build: ../worker/ 36 | depends_on: 37 | - redis 38 | - db 39 | networks: 40 | - back-tier 41 | 42 | redis: 43 | image: redis:alpine 44 | ports: ["6379"] 45 | networks: 46 | - back-tier 47 | 48 | db: 49 | image: postgres:9.4 50 | volumes: 51 | - "db-data:/var/lib/postgresql/data" 52 | networks: 53 | - back-tier 54 | 55 | volumes: 56 | db-data: 57 | 58 | networks: 59 | front-tier: 60 | back-tier: 61 | -------------------------------------------------------------------------------- /exercises/example-voting-app/result/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "result", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "server.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "MIT", 11 | "dependencies": { 12 | "body-parser": "^1.14.1", 13 | "cookie-parser": "^1.4.0", 14 | "express": "^4.13.3", 15 | "method-override": "^2.3.5", 16 | "async": "^1.5.0", 17 | "pg": "^4.4.3", 18 | "socket.io": "^1.3.7" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /exercises/example-voting-app/result/server.js: -------------------------------------------------------------------------------- 1 | var express = require('express'), 2 | async = require('async'), 3 | pg = require("pg"), 4 | cookieParser = require('cookie-parser'), 5 | bodyParser = require('body-parser'), 6 | methodOverride = require('method-override'), 7 | app = express(), 8 | server = require('http').Server(app), 9 | io = require('socket.io')(server); 10 | 11 | io.set('transports', ['polling']); 12 | 13 | var port = process.env.PORT || 4000; 14 | 15 | io.sockets.on('connection', function (socket) { 16 | 17 | socket.emit('message', { text : 'Welcome!' }); 18 | 19 | socket.on('subscribe', function (data) { 20 | socket.join(data.channel); 21 | }); 22 | }); 23 | 24 | async.retry( 25 | {times: 1000, interval: 1000}, 26 | function(callback) { 27 | pg.connect('postgres://postgres@db/postgres', function(err, client, done) { 28 | if (err) { 29 | console.error("Waiting for db"); 30 | } 31 | callback(err, client); 32 | }); 33 | }, 34 | function(err, client) { 35 | if (err) { 36 | return console.err("Giving up"); 37 | } 38 | console.log("Connected to db"); 39 | getVotes(client); 40 | } 41 | ); 42 | 43 | function getVotes(client) { 44 | client.query('SELECT vote, COUNT(id) AS count FROM votes GROUP BY vote', [], function(err, result) { 45 | if (err) { 46 | console.error("Error performing query: " + err); 47 | } else { 48 | var votes = collectVotesFromResult(result); 49 | io.sockets.emit("scores", JSON.stringify(votes)); 50 | } 51 | 52 | setTimeout(function() {getVotes(client) }, 1000); 53 | }); 54 | } 55 | 56 | function collectVotesFromResult(result) { 57 | var votes = {a: 0, b: 0}; 58 | 59 | result.rows.forEach(function (row) { 60 | votes[row.vote] = parseInt(row.count); 61 | }); 62 | 63 | return votes; 64 | } 65 | 66 | app.use(cookieParser()); 67 | app.use(bodyParser()); 68 | app.use(methodOverride('X-HTTP-Method-Override')); 69 | app.use(function(req, res, next) { 70 | res.header("Access-Control-Allow-Origin", "*"); 71 | res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); 72 | res.header("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS"); 73 | next(); 74 | }); 75 | 76 | app.use(express.static(__dirname + '/views')); 77 | 78 | app.get('/', function (req, res) { 79 | res.sendFile(path.resolve(__dirname + '/views/index.html')); 80 | }); 81 | 82 | server.listen(port, function () { 83 | var port = server.address().port; 84 | console.log('App running on port ' + port); 85 | }); 86 | -------------------------------------------------------------------------------- /exercises/example-voting-app/result/tests/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node 2 | RUN npm install -g phantomjs 3 | ADD . /app 4 | WORKDIR /app 5 | CMD ["/app/tests.sh"] 6 | -------------------------------------------------------------------------------- /exercises/example-voting-app/result/tests/render.js: -------------------------------------------------------------------------------- 1 | var system = require('system'); 2 | var page = require('webpage').create(); 3 | var url = system.args[1]; 4 | 5 | page.onLoadFinished = function() { 6 | setTimeout(function(){ 7 | console.log(page.content); 8 | phantom.exit(); 9 | }, 1000); 10 | }; 11 | 12 | page.open(url, function() { 13 | page.evaluate(function() { 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /exercises/example-voting-app/result/tests/tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | while ! timeout 1 bash -c "echo > /dev/tcp/vote/80"; do sleep 1; done 3 | curl -sS -X POST --data "vote=b" http://vote > /dev/null 4 | sleep 10 5 | if phantomjs render.js http://result | grep -q '1 vote'; then 6 | echo -e "\e[42m------------" 7 | echo -e "\e[92mTests passed" 8 | echo -e "\e[42m------------" 9 | exit 0 10 | fi 11 | echo -e "\e[41m------------" 12 | echo -e "\e[91mTests failed" 13 | echo -e "\e[41m------------" 14 | exit 1 15 | -------------------------------------------------------------------------------- /exercises/example-voting-app/result/views/app.js: -------------------------------------------------------------------------------- 1 | var app = angular.module('catsvsdogs', []); 2 | var socket = io.connect({transports:['polling']}); 3 | 4 | var bg1 = document.getElementById('background-stats-1'); 5 | var bg2 = document.getElementById('background-stats-2'); 6 | 7 | app.controller('statsCtrl', function($scope){ 8 | $scope.aPercent = 50; 9 | $scope.bPercent = 50; 10 | 11 | var updateScores = function(){ 12 | socket.on('scores', function (json) { 13 | data = JSON.parse(json); 14 | var a = parseInt(data.a || 0); 15 | var b = parseInt(data.b || 0); 16 | 17 | var percentages = getPercentages(a, b); 18 | 19 | bg1.style.width = percentages.a + "%"; 20 | bg2.style.width = percentages.b + "%"; 21 | 22 | $scope.$apply(function () { 23 | $scope.aPercent = percentages.a; 24 | $scope.bPercent = percentages.b; 25 | $scope.total = a + b; 26 | }); 27 | }); 28 | }; 29 | 30 | var init = function(){ 31 | document.body.style.opacity=1; 32 | updateScores(); 33 | }; 34 | socket.on('message',function(data){ 35 | init(); 36 | }); 37 | }); 38 | 39 | function getPercentages(a, b) { 40 | var result = {}; 41 | 42 | if (a + b > 0) { 43 | result.a = Math.round(a / (a + b) * 100); 44 | result.b = 100 - result.a; 45 | } else { 46 | result.a = result.b = 50; 47 | } 48 | 49 | return result; 50 | } -------------------------------------------------------------------------------- /exercises/example-voting-app/result/views/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Cake vs Beer -- Result 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
Cake
24 |
{{aPercent | number:1}}%
25 |
26 |
27 |
28 |
Beer
29 |
{{bPercent | number:1}}%
30 |
31 |
32 |
33 |
34 |
35 | No votes yet 36 | {{total}} vote 37 | {{total}} votes 38 |
39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /exercises/example-voting-app/result/views/stylesheets/style.css: -------------------------------------------------------------------------------- 1 | @import url(//fonts.googleapis.com/css?family=Open+Sans:400,700,600); 2 | 3 | *{ 4 | box-sizing:border-box; 5 | } 6 | html,body{ 7 | margin:0; 8 | padding:0; 9 | height:100%; 10 | font-family: 'Open Sans'; 11 | } 12 | body{ 13 | opacity:0; 14 | transition: all 1s linear; 15 | } 16 | 17 | .divider{ 18 | height: 150px; 19 | width:2px; 20 | background-color: #C0C9CE; 21 | position: relative; 22 | top: 50%; 23 | float: left; 24 | transform: translateY(-50%); 25 | } 26 | 27 | #background-stats-1{ 28 | background-color: #2196f3; 29 | } 30 | 31 | #background-stats-2{ 32 | background-color: #00cbca; 33 | } 34 | 35 | #content-container{ 36 | z-index:2; 37 | position:relative; 38 | margin:0 auto; 39 | display:table; 40 | padding:10px; 41 | max-width:940px; 42 | height:100%; 43 | } 44 | #content-container-center{ 45 | display:table-cell; 46 | text-align:center; 47 | vertical-align:middle; 48 | } 49 | #result{ 50 | z-index: 3; 51 | position: absolute; 52 | bottom: 40px; 53 | right: 20px; 54 | color: #fff; 55 | opacity: 0.5; 56 | font-size: 45px; 57 | font-weight: 600; 58 | } 59 | #choice{ 60 | transition: all 300ms linear; 61 | line-height:1.3em; 62 | background:#fff; 63 | box-shadow: 10px 0 0 #fff, -10px 0 0 #fff; 64 | vertical-align:middle; 65 | font-size:40px; 66 | font-weight: 600; 67 | width: 450px; 68 | height: 200px; 69 | } 70 | #choice a{ 71 | text-decoration:none; 72 | } 73 | #choice a:hover, #choice a:focus{ 74 | outline:0; 75 | text-decoration:underline; 76 | } 77 | 78 | #choice .choice{ 79 | width: 49%; 80 | position: relative; 81 | top: 50%; 82 | transform: translateY(-50%); 83 | text-align: left; 84 | padding-left: 50px; 85 | } 86 | 87 | #choice .choice .label{ 88 | text-transform: uppercase; 89 | } 90 | 91 | #choice .choice.dogs{ 92 | color: #00cbca; 93 | float: right; 94 | } 95 | 96 | #choice .choice.cats{ 97 | color: #2196f3; 98 | float: left; 99 | } 100 | #background-stats{ 101 | z-index:1; 102 | height:100%; 103 | width:100%; 104 | position:absolute; 105 | } 106 | #background-stats div{ 107 | transition: width 400ms ease-in-out; 108 | display:inline-block; 109 | margin-bottom:-4px; 110 | width:50%; 111 | height:100%; 112 | } 113 | -------------------------------------------------------------------------------- /exercises/example-voting-app/vote/Dockerfile: -------------------------------------------------------------------------------- 1 | # Using official python runtime base image 2 | FROM python:2.7-alpine 3 | 4 | # Set the application directory 5 | WORKDIR /app 6 | 7 | # Install our requirements.txt 8 | ADD requirements.txt /app/requirements.txt 9 | RUN pip install -r requirements.txt 10 | 11 | # Copy our code from the current folder to /app inside the container 12 | ADD . /app 13 | 14 | # Make port 80 available for links and/or publish 15 | EXPOSE 80 16 | 17 | # Define our command to be run when launching the container 18 | CMD ["gunicorn", "app:app", "-b", "0.0.0.0:80", "--log-file", "-", "--access-logfile", "-", "--workers", "4", "--keep-alive", "0"] 19 | -------------------------------------------------------------------------------- /exercises/example-voting-app/vote/app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template, request, make_response, g 2 | from redis import Redis 3 | import os 4 | import socket 5 | import random 6 | import json 7 | 8 | option_a = os.getenv('OPTION_A', "Cake") 9 | option_b = os.getenv('OPTION_B', "Beer") 10 | hostname = socket.gethostname() 11 | 12 | app = Flask(__name__) 13 | 14 | def get_redis(): 15 | if not hasattr(g, 'redis'): 16 | g.redis = Redis(host="redis", db=0, socket_timeout=5) 17 | return g.redis 18 | 19 | @app.route("/", methods=['POST','GET']) 20 | def hello(): 21 | voter_id = request.cookies.get('voter_id') 22 | if not voter_id: 23 | voter_id = hex(random.getrandbits(64))[2:-1] 24 | 25 | vote = None 26 | 27 | if request.method == 'POST': 28 | redis = get_redis() 29 | vote = request.form['vote'] 30 | data = json.dumps({'voter_id': voter_id, 'vote': vote}) 31 | redis.rpush('votes', data) 32 | 33 | resp = make_response(render_template( 34 | 'index.html', 35 | option_a=option_a, 36 | option_b=option_b, 37 | hostname=hostname, 38 | vote=vote, 39 | )) 40 | resp.set_cookie('voter_id', voter_id) 41 | return resp 42 | 43 | 44 | if __name__ == "__main__": 45 | app.run(host='0.0.0.0', port=80, debug=True, threaded=True) 46 | -------------------------------------------------------------------------------- /exercises/example-voting-app/vote/requirements.txt: -------------------------------------------------------------------------------- 1 | Flask 2 | Redis 3 | gunicorn 4 | -------------------------------------------------------------------------------- /exercises/example-voting-app/vote/static/stylesheets/style.css: -------------------------------------------------------------------------------- 1 | @import url(//fonts.googleapis.com/css?family=Open+Sans:400,700,600); 2 | 3 | *{ 4 | box-sizing:border-box; 5 | } 6 | html,body{ 7 | margin: 0; 8 | padding: 0; 9 | background-color: #F7F8F9; 10 | height: 100vh; 11 | font-family: 'Open Sans'; 12 | } 13 | 14 | button{ 15 | border-radius: 0; 16 | width: 100%; 17 | height: 50%; 18 | } 19 | 20 | button[type="submit"] { 21 | -webkit-appearance:none; -webkit-border-radius:0; 22 | } 23 | 24 | button i{ 25 | float: right; 26 | padding-right: 30px; 27 | margin-top: 3px; 28 | } 29 | 30 | button.a{ 31 | background-color: #1aaaf8; 32 | } 33 | 34 | button.b{ 35 | background-color: #00cbca; 36 | } 37 | 38 | #tip{ 39 | text-align: left; 40 | color: #c0c9ce; 41 | font-size: 14px; 42 | } 43 | 44 | #hostname{ 45 | position: absolute; 46 | bottom: 100px; 47 | right: 0; 48 | left: 0; 49 | color: #8f9ea8; 50 | font-size: 24px; 51 | } 52 | 53 | #content-container{ 54 | z-index: 2; 55 | position: relative; 56 | margin: 0 auto; 57 | display: table; 58 | padding: 10px; 59 | max-width: 940px; 60 | height: 100%; 61 | } 62 | #content-container-center{ 63 | display: table-cell; 64 | text-align: center; 65 | } 66 | 67 | #content-container-center h3{ 68 | color: #254356; 69 | } 70 | 71 | #choice{ 72 | transition: all 300ms linear; 73 | line-height: 1.3em; 74 | display: inline; 75 | vertical-align: middle; 76 | font-size: 3em; 77 | } 78 | #choice a{ 79 | text-decoration:none; 80 | } 81 | #choice a:hover, #choice a:focus{ 82 | outline:0; 83 | text-decoration:underline; 84 | } 85 | 86 | #choice button{ 87 | display: block; 88 | height: 80px; 89 | width: 330px; 90 | border: none; 91 | color: white; 92 | text-transform: uppercase; 93 | font-size:18px; 94 | font-weight: 700; 95 | margin-top: 10px; 96 | margin-bottom: 10px; 97 | text-align: left; 98 | padding-left: 50px; 99 | } 100 | 101 | #choice button.a:hover{ 102 | background-color: #1488c6; 103 | } 104 | 105 | #choice button.b:hover{ 106 | background-color: #00a2a1; 107 | } 108 | 109 | #choice button.a:focus{ 110 | background-color: #1488c6; 111 | } 112 | 113 | #choice button.b:focus{ 114 | background-color: #00a2a1; 115 | } 116 | 117 | #background-stats{ 118 | z-index:1; 119 | height:100%; 120 | width:100%; 121 | position:absolute; 122 | } 123 | #background-stats div{ 124 | transition: width 400ms ease-in-out; 125 | display:inline-block; 126 | margin-bottom:-4px; 127 | width:50%; 128 | height:100%; 129 | } 130 | -------------------------------------------------------------------------------- /exercises/example-voting-app/vote/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {{option_a}} vs {{option_b}}! 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 |

{{option_a}} vs {{option_b}}!

17 |
18 | 19 | 20 |
21 |
22 | (Tip: you can change your vote) 23 |
24 |
25 | Processed by container ID {{hostname}} 26 |
27 |
28 |
29 | 30 | 31 | 32 | {% if vote %} 33 | 47 | {% endif %} 48 | 49 | 50 | -------------------------------------------------------------------------------- /exercises/example-voting-app/worker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM microsoft/dotnet:1.0-sdk 2 | 3 | ADD src/Worker /code/src/Worker 4 | 5 | WORKDIR /code/src/Worker 6 | 7 | RUN dotnet restore -v minimal 8 | RUN dotnet publish -c Release 9 | 10 | CMD dotnet /code/src/Worker/bin/Release/netcoreapp1.0/Worker.dll 11 | -------------------------------------------------------------------------------- /exercises/example-voting-app/worker/Dockerfile.j: -------------------------------------------------------------------------------- 1 | FROM java:openjdk-8-jdk-alpine 2 | 3 | RUN MAVEN_VERSION=3.3.3 \ 4 | && cd /usr/share \ 5 | && wget http://archive.apache.org/dist/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz -O - | tar xzf - \ 6 | && mv /usr/share/apache-maven-$MAVEN_VERSION /usr/share/maven \ 7 | && ln -s /usr/share/maven/bin/mvn /usr/bin/mvn 8 | 9 | WORKDIR /code 10 | 11 | ADD pom.xml /code/pom.xml 12 | RUN ["mvn", "dependency:resolve"] 13 | RUN ["mvn", "verify"] 14 | 15 | # Adding source, compile and package into a fat jar 16 | ADD src/main /code/src/main 17 | RUN ["mvn", "package"] 18 | 19 | CMD ["java", "-jar", "target/worker-jar-with-dependencies.jar"] 20 | -------------------------------------------------------------------------------- /exercises/example-voting-app/worker/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | worker 7 | worker 8 | 1.0-SNAPSHOT 9 | 10 | 11 | 12 | 13 | org.json 14 | json 15 | 20140107 16 | 17 | 18 | 19 | redis.clients 20 | jedis 21 | 2.7.2 22 | jar 23 | compile 24 | 25 | 26 | 27 | org.postgresql 28 | postgresql 29 | 9.4-1200-jdbc41 30 | 31 | 32 | 33 | 34 | 35 | 36 | org.apache.maven.plugins 37 | maven-jar-plugin 38 | 2.4 39 | 40 | worker 41 | 42 | 43 | true 44 | worker.Worker 45 | dependency-jars/ 46 | 47 | 48 | 49 | 50 | 51 | org.apache.maven.plugins 52 | maven-compiler-plugin 53 | 3.1 54 | 55 | 1.7 56 | 1.7 57 | 58 | 59 | 60 | org.apache.maven.plugins 61 | maven-assembly-plugin 62 | 63 | 64 | 65 | attached 66 | 67 | package 68 | 69 | worker 70 | 71 | jar-with-dependencies 72 | 73 | 74 | 75 | worker.Worker 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /exercises/example-voting-app/worker/src/Worker/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data.Common; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Net.Sockets; 6 | using System.Threading; 7 | using Newtonsoft.Json; 8 | using Npgsql; 9 | using StackExchange.Redis; 10 | 11 | namespace Worker 12 | { 13 | public class Program 14 | { 15 | public static int Main(string[] args) 16 | { 17 | try 18 | { 19 | var pgsql = OpenDbConnection("Server=db;Username=postgres;"); 20 | var redisConn = OpenRedisConnection("redis"); 21 | var redis = redisConn.GetDatabase(); 22 | 23 | // Keep alive is not implemented in Npgsql yet. This workaround was recommended: 24 | // https://github.com/npgsql/npgsql/issues/1214#issuecomment-235828359 25 | var keepAliveCommand = pgsql.CreateCommand(); 26 | keepAliveCommand.CommandText = "SELECT 1"; 27 | 28 | var definition = new { vote = "", voter_id = "" }; 29 | while (true) 30 | { 31 | // Reconnect redis if down 32 | if (redisConn == null || !redisConn.IsConnected) { 33 | Console.WriteLine("Reconnecting Redis"); 34 | redis = OpenRedisConnection("redis").GetDatabase(); 35 | } 36 | string json = redis.ListLeftPopAsync("votes").Result; 37 | if (json != null) 38 | { 39 | var vote = JsonConvert.DeserializeAnonymousType(json, definition); 40 | Console.WriteLine($"Processing vote for '{vote.vote}' by '{vote.voter_id}'"); 41 | // Reconnect DB if down 42 | if (!pgsql.State.Equals(System.Data.ConnectionState.Open)) 43 | { 44 | Console.WriteLine("Reconnecting DB"); 45 | pgsql = OpenDbConnection("Server=db;Username=postgres;"); 46 | } 47 | else 48 | { // Normal +1 vote requested 49 | UpdateVote(pgsql, vote.voter_id, vote.vote); 50 | } 51 | } 52 | else 53 | { 54 | keepAliveCommand.ExecuteNonQuery(); 55 | } 56 | } 57 | } 58 | catch (Exception ex) 59 | { 60 | Console.Error.WriteLine(ex.ToString()); 61 | return 1; 62 | } 63 | } 64 | 65 | private static NpgsqlConnection OpenDbConnection(string connectionString) 66 | { 67 | NpgsqlConnection connection; 68 | 69 | while (true) 70 | { 71 | try 72 | { 73 | connection = new NpgsqlConnection(connectionString); 74 | connection.Open(); 75 | break; 76 | } 77 | catch (SocketException) 78 | { 79 | Console.Error.WriteLine("Waiting for db"); 80 | Thread.Sleep(1000); 81 | } 82 | catch (DbException) 83 | { 84 | Console.Error.WriteLine("Waiting for db"); 85 | Thread.Sleep(1000); 86 | } 87 | } 88 | 89 | Console.Error.WriteLine("Connected to db"); 90 | 91 | var command = connection.CreateCommand(); 92 | command.CommandText = @"CREATE TABLE IF NOT EXISTS votes ( 93 | id VARCHAR(255) NOT NULL UNIQUE, 94 | vote VARCHAR(255) NOT NULL 95 | )"; 96 | command.ExecuteNonQuery(); 97 | 98 | return connection; 99 | } 100 | 101 | private static ConnectionMultiplexer OpenRedisConnection(string hostname) 102 | { 103 | // Use IP address to workaround hhttps://github.com/StackExchange/StackExchange.Redis/issues/410 104 | var ipAddress = GetIp(hostname); 105 | Console.WriteLine($"Found redis at {ipAddress}"); 106 | 107 | while (true) 108 | { 109 | try 110 | { 111 | Console.Error.WriteLine("Connecting to redis"); 112 | return ConnectionMultiplexer.Connect(ipAddress); 113 | } 114 | catch (RedisConnectionException) 115 | { 116 | Console.Error.WriteLine("Waiting for redis"); 117 | Thread.Sleep(1000); 118 | } 119 | } 120 | } 121 | 122 | private static string GetIp(string hostname) 123 | => Dns.GetHostEntryAsync(hostname) 124 | .Result 125 | .AddressList 126 | .First(a => a.AddressFamily == AddressFamily.InterNetwork) 127 | .ToString(); 128 | 129 | private static void UpdateVote(NpgsqlConnection connection, string voterId, string vote) 130 | { 131 | var command = connection.CreateCommand(); 132 | try 133 | { 134 | command.CommandText = "INSERT INTO votes (id, vote) VALUES (@id, @vote) ON CONFLICT (id) DO UPDATE SET vote = @vote"; 135 | command.Parameters.AddWithValue("@id", voterId); 136 | command.Parameters.AddWithValue("@vote", vote); 137 | command.ExecuteNonQuery(); 138 | } 139 | catch (DbException) 140 | { 141 | command.CommandText = "UPDATE votes SET vote = @vote WHERE id = @id"; 142 | command.ExecuteNonQuery(); 143 | } 144 | finally 145 | { 146 | command.Dispose(); 147 | } 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /exercises/example-voting-app/worker/src/Worker/Worker.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp1.0 5 | true 6 | Worker 7 | Exe 8 | Worker 9 | true 10 | 1.0.4 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /exercises/example-voting-app/worker/src/main/java/worker/Worker.java: -------------------------------------------------------------------------------- 1 | package worker; 2 | 3 | import redis.clients.jedis.Jedis; 4 | import redis.clients.jedis.exceptions.JedisConnectionException; 5 | import java.sql.*; 6 | import org.json.JSONObject; 7 | 8 | class Worker { 9 | public static void main(String[] args) { 10 | try { 11 | Jedis redis = connectToRedis("redis"); 12 | Connection dbConn = connectToDB("db"); 13 | 14 | System.err.println("Watching vote queue"); 15 | 16 | while (true) { 17 | String voteJSON = redis.blpop(0, "votes").get(1); 18 | JSONObject voteData = new JSONObject(voteJSON); 19 | String voterID = voteData.getString("voter_id"); 20 | String vote = voteData.getString("vote"); 21 | 22 | System.err.printf("Processing vote for '%s' by '%s'\n", vote, voterID); 23 | updateVote(dbConn, voterID, vote); 24 | } 25 | } catch (SQLException e) { 26 | e.printStackTrace(); 27 | System.exit(1); 28 | } 29 | } 30 | 31 | static void updateVote(Connection dbConn, String voterID, String vote) throws SQLException { 32 | PreparedStatement insert = dbConn.prepareStatement( 33 | "INSERT INTO votes (id, vote) VALUES (?, ?)"); 34 | insert.setString(1, voterID); 35 | insert.setString(2, vote); 36 | 37 | try { 38 | insert.executeUpdate(); 39 | } catch (SQLException e) { 40 | PreparedStatement update = dbConn.prepareStatement( 41 | "UPDATE votes SET vote = ? WHERE id = ?"); 42 | update.setString(1, vote); 43 | update.setString(2, voterID); 44 | update.executeUpdate(); 45 | } 46 | } 47 | 48 | static Jedis connectToRedis(String host) { 49 | Jedis conn = new Jedis(host); 50 | 51 | while (true) { 52 | try { 53 | conn.keys("*"); 54 | break; 55 | } catch (JedisConnectionException e) { 56 | System.err.println("Waiting for redis"); 57 | sleep(1000); 58 | } 59 | } 60 | 61 | System.err.println("Connected to redis"); 62 | return conn; 63 | } 64 | 65 | static Connection connectToDB(String host) throws SQLException { 66 | Connection conn = null; 67 | 68 | try { 69 | 70 | Class.forName("org.postgresql.Driver"); 71 | String url = "jdbc:postgresql://" + host + "/postgres"; 72 | 73 | while (conn == null) { 74 | try { 75 | conn = DriverManager.getConnection(url, "postgres", ""); 76 | } catch (SQLException e) { 77 | System.err.println("Waiting for db"); 78 | sleep(1000); 79 | } 80 | } 81 | 82 | PreparedStatement st = conn.prepareStatement( 83 | "CREATE TABLE IF NOT EXISTS votes (id VARCHAR(255) NOT NULL UNIQUE, vote VARCHAR(255) NOT NULL)"); 84 | st.executeUpdate(); 85 | 86 | } catch (ClassNotFoundException e) { 87 | e.printStackTrace(); 88 | System.exit(1); 89 | } 90 | 91 | System.err.println("Connected to db"); 92 | return conn; 93 | } 94 | 95 | static void sleep(long duration) { 96 | try { 97 | Thread.sleep(duration); 98 | } catch (InterruptedException e) { 99 | System.exit(1); 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /exercises/hello/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:latest 2 | WORKDIR /app 3 | COPY hello.sh run 4 | ENV GREETEE World 5 | CMD ["/app/run"] 6 | -------------------------------------------------------------------------------- /exercises/hello/hello.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | while true; do 4 | echo "Hello, ${GREETEE-stranger}!" 5 | sleep 1 6 | done 7 | -------------------------------------------------------------------------------- /exercises/index.md: -------------------------------------------------------------------------------- 1 | # Try it: Hello world! 2 | 3 | "Pull" an image: 4 | 5 | ``` 6 | $ `docker pull hello-world` 7 | 8 | Using default tag: latest 9 | latest: Pulling from library/hello-world 10 | c04b14da8d14: Pull complete 11 | Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9 12 | Status: Downloaded newer image for hello-world:latest 13 | ``` 14 | 15 | Run a container: 16 | 17 | ``` 18 | $ `docker run hello-world` 19 | 20 | Hello from Docker. 21 | … 22 | ``` 23 | 24 | # Try it: different Linux distros 25 | 26 | Run Ubuntu: 27 | 28 | ``` 29 | $ `docker run ubuntu dpkg -l` 30 | ``` 31 | 32 | or CentOS: 33 | 34 | ``` 35 | $ `docker run centos rpm -qa` 36 | ``` 37 | 38 | -- 39 | … 40 | 41 | Speedy, huh? 42 | 43 | # Try it: run a shell 44 | 45 | ``` 46 | $ `docker run -i -t ubuntu bash` 47 | ``` 48 | 49 | * `-i` = Keep STDIN open 50 | * `-t` = Allocate a pseudo-TTY 51 | 52 | Now, try doing an Ubuntu thing: 53 | 54 | ``` 55 | root@container# `apt update` 56 | ``` 57 | 58 | # Try it: which kernel? 59 | 60 | Run `uname -a` on both `ubuntu` and `centos`: 61 | 62 | ``` 63 | $ `docker run ubuntu uname -a` 64 | $ `docker run centos uname -a` 65 | ``` 66 | 67 | Can you explain the result? 68 | 69 | -- 70 | 71 | Different distros, same kernel. 72 | 73 | .center[ 74 | ![2 distros, one kernel](diagrams/two-distros-one-kernel.png) 75 | ] 76 | 77 | # Try it: overhead, much? 78 | 79 | Use "time" to measure the overhead of running a command in a container. 80 | 81 | ``` 82 | $ `time docker run ubuntu bash -c "time sleep 1"` 83 | ``` 84 | 85 | How much time did Docker add? 86 | 87 | # Try it: test container file system isolation 88 | 89 | Attempt to cripple your Ubuntu image: 90 | 91 | ``` 92 | $ `docker run -i -t ubuntu bash` 93 | root@3256d8252fe6:/# `ls /usr/bin` 94 | root@3256d8252fe6:/# `rm -fr /usr/bin` 95 | root@3256d8252fe6:/# `ls /usr/bin` 96 | ^D 97 | ``` 98 | 99 | Now, start another container: 100 | 101 | ``` 102 | $ `docker run -i -t ubuntu bash` 103 | root@3ed46bfba026:/# `ls /usr/bin` 104 | ``` 105 | 106 | # Try it: check out those layers 107 | 108 | Use `docker history` to view image layers 109 | 110 | ``` 111 | $ `docker history ubuntu` 112 | IMAGE CREATED CREATED BY 113 | 07c86167cdc4 2 days ago /bin/sh -c #(nop) CMD ["/bin 114 | 2 days ago /bin/sh -c sed -i 's/^#\s*\( 115 | 2 days ago /bin/sh -c echo '#!/bin/sh' 116 | 2 days ago /bin/sh -c #(nop) ADD file:b 117 | 118 | ``` 119 | 120 | # Try it: a long-running container 121 | 122 | Run a container as a daemon (in the background): 123 | 124 | ``` 125 | $ `docker run -d realestate/ciao` 126 | ``` 127 | 128 | List the running containers: 129 | 130 | ``` 131 | $ `docker ps` 132 | ``` 133 | 134 | List ALL the containers: 135 | 136 | ``` 137 | $ `docker ps -a` 138 | ``` 139 | 140 | ??? 141 | 142 | `-d` starts a long-running process. 143 | 144 | Containers have an exit-status, and can be restarted with `docker start`. 145 | 146 | # Try it: container cleanup 147 | 148 | Remove a container: 149 | 150 | ``` 151 | $ `docker rm ` 152 | ``` 153 | 154 | Remove a RUNNING container: 155 | 156 | ``` 157 | $ `docker rm -f ` 158 | ``` 159 | 160 | Cleanup dead containers: 161 | 162 | ``` 163 | $ `docker rm $(docker ps -aq) 2>/dev/null` 164 | ``` 165 | 166 | # Try it: name your containers 167 | 168 | Start a container with a `--name`: 169 | 170 | ``` 171 | $ `docker run -d --name app realestate/ciao` 172 | ``` 173 | 174 | Now you can use the NAME rather than an ID: 175 | 176 | ``` 177 | $ `docker rm -f app` 178 | ``` 179 | 180 | # Try it: map a port to a host port 181 | 182 | ``` 183 | $ `docker run -d --name app -p 5678:80 realestate/ciao` 184 | ``` 185 | 186 | .center[ 187 | 188 | ] 189 | 190 | ``` 191 | $ `curl localhost:5678` 192 | ``` 193 | 194 | # Try it: use a random host port 195 | 196 | If you don't specify a host port, Docker will choose one: 197 | 198 | ``` 199 | $ `docker run -d --name app -p 80 realestate/ciao` 200 | ``` 201 | 202 | .center[ 203 | 204 | ] 205 | 206 | Use `docker port` to discover which one it chose: 207 | 208 | ``` 209 | $ `docker port app 80` 210 | ``` 211 | 212 | Hit it: 213 | 214 | ``` 215 | $ `curl $(docker port app 80)` 216 | ``` 217 | 218 | # Try it: logs 219 | 220 | You can get the output using `docker logs`: 221 | 222 | ``` 223 | $ `docker logs app` 224 | ``` 225 | 226 | Again, with timestamps: 227 | 228 | ``` 229 | $ `docker logs --timestamps app` 230 | ``` 231 | 232 | or even follow along in real time: 233 | 234 | ``` 235 | $ `docker logs --follow --timestamps app` 236 | ``` 237 | 238 | # Try it: set environment variables 239 | 240 | Assuming your application looks for environment variables, e.g. 241 | 242 | ```javascript 243 | var MESSAGE = (process.env.MESSAGE || "Ciao mondo."); 244 | ``` 245 | 246 | You can set them to provide configuration: 247 | 248 | ``` 249 | $ `docker run -d --name app -p 5678:80 \` 250 | `-e MESSAGE='Hey, guys!' \` 251 | `realestate/ciao` 252 | ``` 253 | 254 | Test the result: 255 | 256 | ``` 257 | $ `curl localhost:5678` 258 | ``` 259 | 260 | # Try it: inter-container networking 261 | 262 | Create a "network": 263 | 264 | ``` 265 | $ `docker network create shared` 266 | $ `docker network ls` 267 | ``` 268 | 269 | Attach some containers: 270 | 271 | ``` 272 | $ `docker rm -f app proxy` 273 | $ `docker run -d --net=shared --name app \` 274 | `realestate/ciao` 275 | $ `docker run -d --net=shared --name proxy \` 276 | `-p 5678:80 \` 277 | `realestate/ciao-proxy` 278 | ``` 279 | 280 | ``` 281 | $ `curl -si localhost:5678` 282 | ``` 283 | 284 | # Try it: explore the network 285 | 286 | ``` 287 | $ `docker network inspect shared` 288 | ``` 289 | 290 | .center[ 291 | 292 | ] 293 | 294 | ``` 295 | $ `docker run -it --rm --network shared busybox` 296 | / # `nslookup app` 297 | ``` 298 | 299 | # Try it: volume from host 300 | 301 | Mount your home directory from the "host": 302 | 303 | ``` 304 | $ `docker run -it --rm -v $HOME:/myhome ubuntu bash` 305 | root@c10a43c38793:/# `mount | grep home` 306 | root@c10a43c38793:/# `cd /myhome; ls` 307 | root@c10a43c38793:/# `echo HELLO FROM DOCKER > written-from-docker` 308 | root@c10a43c38793:/# `exit` 309 | $ `ls $HOME` 310 | ``` 311 | 312 | # Try it: named cache volume 313 | 314 | ``` 315 | $ `docker run -it --rm -v my-cache:/cache ubuntu bash` 316 | root@c10a43c38793:/# `echo TESTING > /cache/test` 317 | ^D 318 | ``` 319 | 320 | Observe, volume created: 321 | 322 | ``` 323 | $ `docker volume ls` 324 | ``` 325 | 326 | Use it again: 327 | 328 | ``` 329 | $ `docker run -it --rm -v my-cache:/cache ubuntu bash` 330 | root@f5be5dec8a5a:/# `ls /cache` 331 | ``` 332 | 333 | Clean up: 334 | 335 | ``` 336 | $ `docker volume rm my-cache` 337 | ``` 338 | 339 | # Try it: anonymous volume for extra writable space 340 | 341 | ``` 342 | $ `docker run -it --rm --read-only -v /scratch ubuntu` 343 | root@c10a43c38793:/# `echo TESTING > /tmp/test` 344 | root@c10a43c38793:/# `echo TESTING > /scratch/test` 345 | ``` 346 | 347 | .center[ 348 | 349 | ] 350 | 351 | Tip: read-only root volume is great for security! 352 | 353 | # Try it: share a volume with another container 354 | 355 | Create a container, with a volume: 356 | 357 | ``` 358 | $ `docker run -it --rm --name provider -v data:/published ubuntu` 359 | root@118f38503653:/# `echo ohai > /published/stuff` 360 | ``` 361 | 362 | .center[ 363 | 364 | ] 365 | 366 | Use the volume from a different container: 367 | 368 | ``` 369 | $ `docker run -it --rm --name consumer -v data:/provided:ro ubuntu` 370 | root@d88a7a468b01:/# `cat /provided/stuff` 371 | ``` 372 | 373 | # Try it: list images 374 | 375 | View images on your Docker host: 376 | 377 | ``` 378 | $ `docker images` 379 | REPOSITORY TAG IMAGE ID CREATED SIZE 380 | busybox latest e02e811dd08f 4 days ago 1.093 MB 381 | debian latest ddf73f48a05d 2 weeks ago 123 MB 382 | nginx latest ba6bed934df2 2 weeks ago 181.4 MB 383 | ruby 2.3-alpine 2467a614f30b 2 weeks ago 125.8 MB 384 | ... 385 | ubuntu 16.04 45bc58500fa3 3 weeks ago 126.9 MB 386 | ubuntu latest 45bc58500fa3 3 weeks ago 126.9 MB 387 | ubuntu 45bc58500fa3 3 weeks ago 126.9 MB 388 | ``` 389 | 390 | -- 391 | 392 | View images in the `ubuntu` repository: 393 | 394 | ``` 395 | $ `docker images ubuntu` 396 | ``` 397 | 398 | # Try it: use an image tag 399 | 400 | Image repositories can contain multiple images, identified by tag: 401 | 402 | .center[ 403 | `[:]` 404 | ] 405 | 406 | Run different versions of Ruby: 407 | 408 | ``` 409 | $ `docker run ruby:2.3 ruby --version` 410 | $ `docker run ruby:2.4 ruby --version` 411 | ``` 412 | 413 | -- 414 | 415 | By convention, there's usually a `latest` tag: 416 | 417 | ``` 418 | $ `docker run ruby:latest ruby --version` 419 | ``` 420 | 421 | which is the default: 422 | 423 | ``` 424 | $ `docker run ruby ruby --version` 425 | ``` 426 | 427 | # Try it: stable image references 428 | 429 | Image can also be addressed with immutable digests: 430 | 431 | .center[ 432 | `[@]` 433 | ] 434 | 435 | ``` 436 | $ `docker pull ruby:2.4 | grep Digest` 437 | ``` 438 | 439 | Use the digest: 440 | 441 | ``` 442 | $ `docker run ruby@sha256:ec92755b46504ec2d27d8a2887d080ca9ef799dfe7c010b7019b2165f875c738 \` 443 | `ruby --version` 444 | ``` 445 | 446 | Or, a different (older) one: 447 | 448 | ``` 449 | $ `docker run ruby@sha256:450ce48d8021d33c306168654256b9c960711e6c02991f270d55488caf860410 \` 450 | `ruby --version` 451 | ``` 452 | 453 | # Try it: non-standard namespace 454 | 455 | Repositories can have an optional namespace: 456 | 457 | .center[ 458 | `[/]` 459 | ] 460 | 461 | Use a community image: 462 | 463 | ``` 464 | $ `docker run -it supertest2014/nyan` 465 | ``` 466 | 467 | # Try it: build an image, the hard way 468 | 469 | Install some software in an `ubuntu` container: 470 | 471 | ``` 472 | $ `docker run -it ubuntu bash` 473 | root@f55393e5dc31:/# `apt-get update && apt-get install -y curl` 474 | … 475 | root@f55393e5dc31:/# `exit` 476 | ``` 477 | 478 | Now, `commit` that container to create an image: 479 | 480 | ``` 481 | $ `container=$(docker ps -lq)` 482 | $ `image=$(docker commit $container)` 483 | ``` 484 | 485 | Try it out: 486 | 487 | ``` 488 | $ `docker run ubuntu curl http://example.com` 489 | $ `docker run $image curl http://example.com` 490 | ``` 491 | 492 | # Try it: name your image 493 | 494 | Attach a tag to an existing image: 495 | 496 | ``` 497 | $ `docker tag $image curly` 498 | ``` 499 | 500 | Or, when making it: 501 | 502 | ``` 503 | $ `docker commit $container curly` 504 | ``` 505 | 506 | For later use: 507 | 508 | ``` 509 | $ `docker run curly curl http://example.com` 510 | ``` 511 | 512 | 513 | # Try it: build an image, the easy way 514 | 515 | Use a `Dockerfile`: 516 | 517 | ``` 518 | FROM ubuntu 519 | RUN apt-get update && apt-get install -y curl 520 | ``` 521 | 522 | to build an image: 523 | 524 | ``` 525 | $ `docker build exercises/ubuntu-with-curl` 526 | Sending build context to Docker daemon 2.048 kB 527 | Step 1 : FROM ubuntu 528 | ---> 07c86167cdc4 529 | Step 2 : RUN apt-get update && apt-get install -y curl 530 | ---> Running in 51bf195331b7 531 | Ign http://archive.ubuntu.com trusty InRelease 532 | Get:1 http://archive.ubuntu.com trusty-updates InRelease [64.4 kB] 533 | … 534 | ---> 70b42c74bb66 535 | Removing intermediate container 51bf195331b7 536 | Successfully built 70b42c74bb66 537 | ``` 538 | 539 | # Try it: leverage the "build cache" 540 | 541 | Use the recipe provided: 542 | 543 | ``` 544 | FROM node:6.2.2 545 | 546 | COPY package.json /app/ 547 | WORKDIR /app 548 | RUN npm install 549 | COPY index.js /app/ 550 | 551 | ENV PORT 80 552 | CMD ["node", "/app/index.js"] 553 | ``` 554 | 555 | to build an image: 556 | 557 | ``` 558 | $ `docker build -t ciao exercises/ciao` 559 | ``` 560 | 561 | # Try it: invalidate the "build cache" 562 | 563 | Build it again: 564 | 565 | ``` 566 | $ `docker build -t ciao exercises/ciao` 567 | ``` 568 | 569 | Faster, eh? Observe: "Using cache". 570 | 571 | -- 572 | 573 | Now try this: 574 | 575 | * Edit `exercises/ciao/index.js`, changing the default MESSAGE from "Ciao mondo" to something else, then build again. What happens at "Step 5"? 576 | 577 | -- 578 | 579 | * Make a change to `exercises/ciao/package.json`, and build again. What happens at "Step 4"? 580 | 581 | # Try it: push an image to Docker Hub 582 | 583 | Authenticate to Docker Hub: 584 | 585 | ``` 586 | $ `docker login` 587 | ``` 588 | 589 | "Tag" an image into _your_ namespace: 590 | 591 | ``` 592 | $ `docker tag ciao YOURNAMEHERE/ciao` 593 | ``` 594 | 595 | Now you can push it: 596 | 597 | ``` 598 | $ `docker push YOURNAMEHERE/ciao` 599 | ``` 600 | 601 | # Try it: pull an image someone else pushed 602 | 603 | Talk to the esteemed colleague next to you, and ask them 604 | for their Docker Hub username. Then, you shoud be able to 605 | fetch the image _they_ pushed. 606 | 607 | ``` 608 | $ `docker pull YOURNEIGHBOUR/ciao` 609 | ``` 610 | 611 | # Try it: docker-compose 612 | 613 | Given YAML config file: 614 | 615 | ``` 616 | version: '3' 617 | 618 | services: 619 | 620 | app: 621 | image: realestate/ciao 622 | 623 | proxy: 624 | image: realestate/ciao-proxy 625 | depends_on: 626 | - app 627 | environment: 628 | BACKEND: app 629 | ports: 630 | - 5678:80 631 | ``` 632 | 633 | You can start the containers with: 634 | 635 | ``` 636 | $ `cd exercises/composed/basic` 637 | $ `docker-compose up` 638 | ``` 639 | 640 | # Try it: under the covers of compose 641 | 642 | In a different window, generate some traffic: 643 | 644 | ``` 645 | $ `curl localhost:5678` 646 | ``` 647 | 648 | What containers are running? 649 | 650 | ``` 651 | $ `docker ps` 652 | $ `cd exercises/composed/basic` 653 | $ `docker-compose ps` 654 | ``` 655 | 656 | How about networking? 657 | 658 | ``` 659 | $ `docker inspect basic_app_1 \` 660 | `| jq '.[0].NetworkSettings.Networks'` 661 | ``` 662 | 663 | Take it all down: 664 | 665 | ``` 666 | $ `docker-compose down` 667 | ``` 668 | 669 | # Try it: get compose to build your images 670 | 671 | ``` 672 | version: '3' 673 | 674 | services: 675 | 676 | app: 677 | `build: ../../ciao` 678 | 679 | proxy: 680 | `build: ../../ciao-proxy` 681 | depends_on: 682 | - app 683 | environment: 684 | BACKEND: app:80 685 | ports: 686 | - 5678:80 687 | ``` 688 | -- 689 | 690 | ``` 691 | $ `cd exercises/composed/autobuilt` 692 | $ `docker-compose up` 693 | ``` 694 | 695 | # Try it: add a "client" container 696 | 697 | ``` 698 | version: '3' 699 | 700 | services: 701 | app: ... 702 | proxy: ... 703 | 704 | client: 705 | build: ../../ubuntu-with-curl 706 | depends_on: 707 | - proxy 708 | command: sh -c "while true; do curl http://proxy; sleep 1; done" 709 | ``` 710 | 711 | ``` 712 | $ `cd exercises/composed/with-curl` 713 | $ `docker-compose up` 714 | ``` 715 | 716 | (Press Ctrl-C to tear everything down.) 717 | 718 | # Try it: docker-compose run 719 | 720 | Try "running" a "client" container: 721 | 722 | ``` 723 | $ `docker-compose run --rm client` 724 | ``` 725 | 726 | Or, go interactive: 727 | 728 | ``` 729 | $ `docker-compose run --rm client bash` 730 | root@ebb0d01e63b0:/# `curl -i app` 731 | root@ebb0d01e63b0:/# `curl -i proxy` 732 | ``` 733 | 734 | # Try it: sharing a volume 735 | 736 | ``` 737 | version: '3' 738 | 739 | volumes: 740 | shared: {} 741 | 742 | services: 743 | 744 | producer: 745 | image: busybox 746 | volumes: 747 | - shared:/out 748 | command: sh -c "while true; do date; sleep 1; done > /out/dates" 749 | 750 | consumer: 751 | image: ubuntu:16.04 752 | depends_on: 753 | - producer 754 | volumes: 755 | - shared:/data 756 | command: tail -f /data/dates 757 | ``` 758 | 759 | ``` 760 | $ `cd exercises/composed/sharing` 761 | $ `docker-compose up` 762 | ``` 763 | 764 | # Try it: Python and Redis and .Net and PostgreSQL and Node.js 765 | 766 | ``` 767 | $ `cd exercises/example-voting-app` 768 | $ `docker-compose up` 769 | ``` 770 | 771 | .center[ 772 | 773 | ] 774 | 775 | # Try it: Python and Redis and .Net and PostgreSQL and Node.js 776 | 777 | Once it's started running ... 778 | 779 | * voting-app at http://localhost:5000 780 | * result-app at http://localhost:5001 781 | 782 | When you're done, clean up: 783 | 784 | ``` 785 | $ `^C` 786 | $ `docker-compose down` 787 | ``` 788 | 789 | -------------------------------------------------------------------------------- /exercises/mysite/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:latest 2 | 3 | RUN apt-get update && apt-get install -y -q apache2 4 | 5 | RUN mkdir -p /var/lock/apache2 /var/log/apache2 6 | 7 | env APACHE_RUN_USER www-data 8 | env APACHE_RUN_GROUP www-data 9 | env APACHE_PID_FILE /var/run/apache2.pid 10 | env APACHE_RUN_DIR /var/run/apache2 11 | env APACHE_LOCK_DIR /var/lock/apache2 12 | env APACHE_LOG_DIR /var/log/apache2 13 | env LANG C 14 | 15 | CMD ["apache2", "-D", "FOREGROUND"] 16 | 17 | COPY docs/* /var/www/html/ 18 | -------------------------------------------------------------------------------- /exercises/mysite/docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Docker Dojo 7 | 8 | 22 | 23 | 24 | 25 | 26 | 27 |

Hello, Docker.

28 | 29 |

30 | I heard you like containers, so I put your containers in a box. 31 |

32 | 33 | 34 | -------------------------------------------------------------------------------- /exercises/refdata/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:16.04 2 | 3 | COPY words /ref/ 4 | VOLUME /ref 5 | -------------------------------------------------------------------------------- /exercises/ubuntu-with-curl/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu 2 | RUN apt-get update && apt-get install -y curl 3 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | An introduction to Docker 5 | 6 | 7 | 8 | 9 | 10 | 1809 | 1811 | 1817 | 1818 | 1819 | -------------------------------------------------------------------------------- /media/REA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/media/REA.png -------------------------------------------------------------------------------- /media/compose.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/media/compose.png -------------------------------------------------------------------------------- /media/docker-hub.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/media/docker-hub.png -------------------------------------------------------------------------------- /media/docker/small_h-dark-trans.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/media/docker/small_h-dark-trans.png -------------------------------------------------------------------------------- /media/docker/small_h-dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/media/docker/small_h-dark.png -------------------------------------------------------------------------------- /media/docker/small_h-trans.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/media/docker/small_h-trans.png -------------------------------------------------------------------------------- /media/docker/small_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/media/docker/small_h.png -------------------------------------------------------------------------------- /media/docker/small_v-dark-trans.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/media/docker/small_v-dark-trans.png -------------------------------------------------------------------------------- /media/docker/small_v-dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/media/docker/small_v-dark.png -------------------------------------------------------------------------------- /media/docker/small_v-trans.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/media/docker/small_v-trans.png -------------------------------------------------------------------------------- /media/docker/small_v.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/media/docker/small_v.png -------------------------------------------------------------------------------- /media/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realestate-com-au/intro-to-docker/2433efef043d2f4602eb744479efac775daa94d2/media/favicon.png -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | yay() { 4 | echo -ne "\033[32mYAY: \033[0m"; echo "$1" 5 | } 6 | 7 | boo() { 8 | (echo -ne "\033[31mBOO: \033[0m"; echo "$1") >&2 9 | exit 1 10 | } 11 | 12 | umm() { 13 | (echo -ne "\033[33mUMM: \033[0m"; echo "$1") >&2 14 | } 15 | 16 | beat() { 17 | echo "" 18 | } 19 | 20 | docker_sock=/var/run/docker.sock 21 | if test -n "$DOCKER_HOST"; then 22 | yay "\$DOCKER_HOST is set" 23 | docker_addr=$(echo $DOCKER_HOST | sed -e 's|tcp://\(.*\):[0-9]*|\1|') 24 | if test -e $docker_sock; then 25 | umm "$docker_sock exists, too - that's weird" 26 | echo " Beware of confusion between Docker for Mac and docker-machine!" 27 | fi 28 | elif test -e $docker_sock; then 29 | yay "$docker_sock exists" 30 | docker_addr=localhost 31 | else 32 | boo "No \$DOCKER_HOST, no $docker_sock ... where's Docker?" 33 | fi 34 | 35 | if docker info > /dev/null; then 36 | yay "I can talk to docker" 37 | else 38 | boo "I can't talk to docker" 39 | fi 40 | 41 | beat 42 | 43 | echo "Docker is at $docker_addr" 44 | 45 | beat 46 | 47 | version_of() { 48 | $1 --version | egrep -o '[0-9]+(\.[0-9]+)+' 49 | } 50 | 51 | version_lte() { 52 | [ "$1" = "`echo -e "$1\n$2" | docker run -i debian:stable sort -V | head -n1`" ] 53 | } 54 | 55 | check_version() { 56 | app=$1 57 | expected_version=$2 58 | actual_version=$(version_of $app) 59 | if version_lte $expected_version $actual_version; then 60 | yay "$app version $actual_version >= $expected_version" 61 | else 62 | boo "$app version $actual_version < $expected_version" 63 | fi 64 | } 65 | 66 | check_version docker 1.13.0 67 | check_version docker-compose 1.13.0 68 | 69 | beat 70 | 71 | pull() { 72 | echo "" 73 | echo "=== $1" 74 | docker pull $1 75 | } 76 | 77 | echo "Pulling some images to get you started ..." 78 | pull alpine 79 | pull busybox 80 | pull centos 81 | pull debian 82 | pull ubuntu 83 | pull ubuntu:16.04 84 | pull microsoft/dotnet:1.0-sdk 85 | pull node:5.11.0-slim 86 | pull node:6.2.2 87 | pull postgres:9.6 88 | pull python:2.7-alpine 89 | pull ruby:2.3 90 | pull ruby:2.4 91 | pull ruby 92 | pull realestate/ciao 93 | pull realestate/ciao-proxy 94 | -------------------------------------------------------------------------------- /styles.css: -------------------------------------------------------------------------------- 1 | @import url(https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz); 2 | @import url(https://fonts.googleapis.com/css?family=Noto+Sans:400,700,400italic); 3 | @import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic); 4 | 5 | body { font-family: 'Noto Sans', sans-serif; } 6 | h1, h2, h3 { 7 | font-weight: normal; 8 | } 9 | .moar-space ul li { 10 | line-height: 150%; 11 | padding-bottom:0.667rem; 12 | } 13 | .remark-code, .remark-inline-code { 14 | font-family: monospace; 15 | } 16 | 17 | .remark-code-span-highlighted { 18 | background-color: inherit; 19 | color: #ffc; 20 | } 21 | 22 | .hljs-obsidian pre .hljs { 23 | background-color: inherit; 24 | padding: 0; 25 | } 26 | 27 | .remark-slide-content h1 { 28 | font-size: 40px; 29 | line-height: 110%; 30 | text-shadow: 3px 3px 3px #ccc; 31 | } 32 | 33 | pre { 34 | padding: 6px; 35 | border: 1px solid #eee; 36 | border-radius: 3px; 37 | background: black; 38 | color: #ddd; 39 | } 40 | 41 | .remark-inline-code { 42 | border: 1px solid #eee; 43 | font-size: 90%; 44 | padding: 2px; 45 | } 46 | 47 | div.lhs { 48 | float: left; 49 | width: 49%; 50 | } 51 | div.rhs { 52 | float: right; 53 | width: 49%; 54 | } 55 | 56 | div.clear { 57 | clear: both; 58 | } 59 | 60 | .big { 61 | font-size: 150%; 62 | } 63 | .small { 64 | font-size: 75%; 65 | } 66 | 67 | a:link { 68 | text-decoration: none; 69 | } 70 | 71 | table.compare { 72 | border-collapse: collapse; 73 | margin: auto; 74 | } 75 | 76 | table.compare th, table.compare td { 77 | border: 1px solid #aaa; 78 | padding: 6px 10px; 79 | text-align: center; 80 | } 81 | 82 | table.compare td.factor { 83 | font-style: italic; 84 | } 85 | 86 | table.docker-image { 87 | margin: 10px auto; 88 | border-collapse: collapse; 89 | width: 60%; 90 | } 91 | 92 | table.docker-image td { 93 | text-align: center; 94 | } 95 | 96 | table.docker-image td.writable { 97 | padding: 5px; 98 | border: 2px dashed #666; 99 | } 100 | 101 | table.docker-image td.snapshot { 102 | padding: 5px; 103 | background-color: #f8f8f8; 104 | border: 2px solid #666; 105 | } 106 | 107 | table.docker-image td.labels { 108 | text-align: left; 109 | padding-left: 20px; 110 | font-family: 'Ubuntu Mono', monospace; 111 | } 112 | --------------------------------------------------------------------------------