Permalink
Browse files

first commit

  • Loading branch information...
Jimmy Huang
Jimmy Huang committed Aug 28, 2014
0 parents commit 9734fbf67a4733271cbfa1161594838fd58e3542
Showing with 5,751 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. BIN assets/building-images-with-dockerfiles/docker-hub-sign-up.png
  3. BIN assets/building-images-with-dockerfiles/making-containers.jpg
  4. BIN assets/common/boot2docker.png
  5. BIN assets/common/learning-docker-logo.png
  6. BIN assets/common/learning-tutorial-figures.pptx
  7. BIN assets/common/macosx-logo.png
  8. BIN assets/common/postgresql-logo.png
  9. BIN assets/common/rails-logo.png
  10. BIN assets/docker-container-deep-dive/deep-diving-whale.jpg
  11. BIN assets/dockerfile-walkthrough/filbert-steps.jpg
  12. BIN assets/get-started-with-docker/shipping-containers.jpg
  13. BIN assets/getting-inside-running-docker-containers-without-ssh/open-shipping-container.jpg
  14. BIN ...-application-database-mac-os-x-host/dockerized-rails-application-postgresql-database-mac-os-x.jpg
  15. BIN assets/preflight-checks/preflight-check.jpg
  16. BIN assets/running-boot2docker-mac-os-x/boot2docker-applications-folder.jpg
  17. BIN assets/running-boot2docker-mac-os-x/mac-os-x-laptop.jpg
  18. BIN ...nning-postgresql-service-docker-container/dockerized-postgresql-database-mac-os-x-boot2docker.jpg
  19. BIN ...rails-app-over-two-docker-containers/dockerized-rails-app-two-containers-mac-os-x-boot2docker.jpg
  20. BIN assets/running-rails-app-over-two-docker-containers/hartl-sample-app.jpg
  21. BIN assets/starting-over-mac-os-x/delete-all-files.jpg
  22. BIN assets/starting-over-mac-os-x/remove-boot2docker-virtual-machine.jpg
  23. BIN assets/starting-over-mac-os-x/second-verse-same-as-the-first.jpg
  24. +34 −0 generate-pdf.md
  25. +253 −0 html/building-images-with-dockerfiles.html
  26. +150 −0 html/docker-container-deep-dive.html
  27. +123 −0 html/dockerfile-walkthrough.html
  28. +51 −0 html/getting-inside-running-docker-containers-without-ssh.html
  29. +1,634 −0 html/learning-docker.html
  30. +154 −0 html/linking-dockerized-application-database-mac-os-x-host.html
  31. +47 −0 html/preflight-checks.html
  32. +130 −0 html/running-boot2docker-mac-os-x.html
  33. +102 −0 html/running-postgresql-service-docker-container.html
  34. +227 −0 html/running-rails-app-over-two-docker-containers.html
  35. +49 −0 html/starting-over-mac-os-x.html
  36. +269 −0 src/building-images-with-dockerfiles.md
  37. +165 −0 src/docker-container-deep-dive.md
  38. +136 −0 src/dockerfile-walkthrough.md
  39. +3 −0 src/get-started-with-docker.md
  40. +59 −0 src/getting-inside-running-docker-containers-without-ssh.md
  41. +1,396 −0 src/learning-docker.md
  42. +170 −0 src/linking-dockerized-application-database-mac-os-x-host.md
  43. +49 −0 src/preflight-checks.md
  44. +120 −0 src/running-boot2docker-mac-os-x.md
  45. +115 −0 src/running-postgresql-service-docker-container.md
  46. +254 −0 src/running-rails-app-over-two-docker-containers.md
  47. +59 −0 src/starting-over-mac-os-x.md
@@ -0,0 +1,2 @@
downloads
draft
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,34 @@
http://www.snip2code.com/Snippet/63811/Installing-pandoc-on-Mac-OSX-using-Homeb

1. Generate `learning-docker.md`.

```
Host% cat get-started-with-docker.md running-boot2docker-mac-os-x.md getting-inside-running-docker-containers-without-ssh.md preflight-checks.md running-postgresql-service-docker-container.md running-rails-app-over-two-docker-containers.md docker-container-deep-dive.md building-images-with-dockerfiles.md dockerfile-walkthrough.md linking-dockerized-application-database-mac-os-x-host.md starting-over-mac-os-x.md > learning-docker.md
```

2. Generate `learning-docker.html` from `learning-docker.md`.

3. Add author `<meta>` tag in `<header>`.

```
<meta name="author" content="Jimmy Y. Huang">
```

4. Remove these two lines.

```
<h2>Learning Docker</h2>
<h5>Jimmy Y. Huang</h5>
```

5. Generate `learning-docker.pdf` from `learning-docker.html`.

```
Host% pandoc learning-docker.html \
-V geometry:margin=1in \
-V geometry:paperwidth=10in \
-V geometry:paperheight=16in \
--latex-engine=xelatex \
-o learning-docker.pdf
```
@@ -0,0 +1,253 @@
<p><img src="https://s3.amazonaws.com/learningdocker/wordpress/building-images-with-dockerfiles/making-containers.jpg" alt="image" /></p>

<p>As part of going through the steps outlined under <em><a href="http://learningdocker.com/running-rails-app-over-two-docker-containers/">Running a Rails App over Two Docker Containers</a></em>, we pulled the <code>learningdocker/docker_quick_start</code> image from Docker Hub onto the Boot2Docker virtual machine. Instead of using an already made image, we will now build the Rails application's Docker image on the Boot2Docker virtual machine via our Mac OS X host and push the final image onto our Docker Hub accounts.</p>

<ol>
<li><p>Please create an account on <a href="https://hub.docker.com">Docker Hub</a>.</p>

<p><img src="https://s3.amazonaws.com/learningdocker/wordpress/building-images-with-dockerfiles/docker-hub-sign-up.png" alt="image" /></p></li>
<li><p>Log into your Docker Hub account from the command-line console.</p>

<pre><code>Host% docker login
Username: &lt;Your Docker Hub Username&gt;
Password: &lt;Your Docker Hub Password&gt;
Email: &lt;Your Email Address&gt;
Login Succeeded

Host% export $DOCKERUSER=&lt;Your Docker Hub Username&gt;
</code></pre></li>
<li><p>Delete the <code>learningdocker/docker_quick_start</code> image.</p>

<pre><code>Host% docker images
REPOSITORY TAG IMAGE ID VIRTUAL SIZE
learningdocker/docker_quick_start latest 223ac352ac09 781 MB
jpetazzo/nsenter latest 1084fe82d2fe 323.4 MB
kamui/postgresql latest 249dad1e2537 387.5 MB

Host% docker rmi learningdocker/docker_quick_start

Host% docker images
REPOSITORY TAG IMAGE ID VIRTUAL SIZE
jpetazzo/nsenter latest 1084fe82d2fe 323.4 MB
kamui/postgresql latest 249dad1e2537 387.5 MB
</code></pre></li>
<li><p>Download the <a href="https://github.com/LearningDocker/docker_quick_start">dockerized Ruby on Rails Tutorial sample application</a>. This sample application is forked from the one developed and maintained by Michael Hartl for his self-paced learning program <a href="http://www.railstutorial.org/">Ruby on Rails Tutorial: Learn Web Development with Rails</a>.</p>

<pre><code>Host% git clone http://github.com/LearningDocker/docker_quick_start.git
</code></pre></li>
<li><p>Run <code>docker build</code> on the Dockerfile. On this particular build, the process took almost 18 minutes to complete. While waiting for the image build to finish, please check out <em><a href="http://LearningDocker.com/dockerfile-walkthrough/">Dockerfile Walkthrough</a></em> to see how each Dockerfile instruction works to generate one layer in the final image.</p>

<pre><code>Host% time docker build -t $DOCKERUSER/docker_quick_start .
Sending build context to Docker daemon 1.505 MB
Sending build context to Docker daemon
Step 0 : FROM debian:jessie
Pulling repository debian
431dac4e3917: Download complete
511136ea3c5a: Download complete
a70fb0647e6e: Download complete
---&gt; 431dac4e3917
Step 1 : MAINTAINER Learning Docker &lt;jimmy.huang@learningdocker.com&gt;
---&gt; Running in b7e69ec93d59
---&gt; 9ce1ff063603
Removing intermediate container b7e69ec93d59
Step 2 : RUN apt-get update &amp;&amp; apt-get install -qy \
curl git libpq-dev libprocps3 libprocps3-dev nodejs postgresql procps
---&gt; Running in 5369bbee7a61
Upgrading Debian packages already installed

Downloading and installing Debian packages
in the RUN instruction and their dependencies
---&gt; a9f3925e86a6
Removing intermediate container 5369bbee7a61
Step 3 : RUN curl -sSL https://get.rvm.io | bash -s stable
---&gt; Running in 6d0fef8a067f
Downloading https://github.com/wayneeseguin/rvm/archive/stable.tar.gz
Installing RVM to /usr/local/rvm/
---&gt; 1dd60b90bb1b
Removing intermediate container 6d0fef8a067f
Step 4 : RUN ["/bin/bash", "-l", "-c",
"rvm requirements;
rvm install 2.1.2;
gem install bundler --no-ri --no-rdoc"]
---&gt; Running in 7983ef880f73
Checking requirements for debian.
Installing requirements for debian.
Updating system..
Installing required packages: bzip2, gawk, g++, make, libreadline6-dev,
libyaml-dev, libsqlite3-dev, sqlite3,
autoconf, libgdbm-dev, libncurses5-dev,
automake, libtool, bison, pkg-config,
libffi-dev...................
Requirements installation successful.
Searching for binary rubies, this might take some time.
Found remote file
https://rvm.io/binaries/debian/jessie_sid/x86_64/ruby-2.1.2.tar.bz2
Checking requirements for debian.
Requirements installation successful.
ruby-2.1.2 - #configure
ruby-2.1.2 - #download
ruby-2.1.2 - #validate archive
ruby-2.1.2 - #extract
ruby-2.1.2 - #validate binary
ruby-2.1.2 - #setup
ruby-2.1.2 - #gemset created /usr/local/rvm/gems/ruby-2.1.2@global
ruby-2.1.2 - #importing gemset /usr/local/rvm/gemsets/global.gems
ruby-2.1.2 - #generating global wrappers........
ruby-2.1.2 - #gemset created /usr/local/rvm/gems/ruby-2.1.2
ruby-2.1.2 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems
evaluated to empty gem list
ruby-2.1.2 - #generating default wrappers........
Successfully installed bundler-1.6.5
1 gem installed
---&gt; 1c27744233bc
Removing intermediate container 7983ef880f73
Step 5 : COPY Gemfile /app/Gemfile
---&gt; 49df2bda31e0
Removing intermediate container d35914bdd291
Step 6 : COPY Gemfile.lock /app/Gemfile.lock
---&gt; 2e42214a73fd
Removing intermediate container e3478ee33811
Step 7 : WORKDIR /app
---&gt; Running in a5d240ae639e
---&gt; 59d5871db18b
Removing intermediate container a5d240ae639e
Step 8 : RUN ["/bin/bash", "-l", "-c", "bundle install"]
---&gt; Running in a430cb96a6cf
Installing gems specified in the Gemfile
Your bundle is complete!

&lt;= 1.8.6 : unsupported
= 1.8.7 : gem install rdoc-data; rdoc-data --install
= 1.9.1 : gem install rdoc-data; rdoc-data --install
&gt;= 1.9.2 : nothing to do! Yay!
---&gt; 7ecb9e9182eb
Removing intermediate container a430cb96a6cf
Step 9 : ADD . /app
---&gt; 32cd50a4f4c0
Removing intermediate container 0a9f5038b38a
Step 10 : COPY config/container/start-server.sh /usr/bin/start-server
---&gt; f58f16a503e3
Removing intermediate container 4c9408bb70e8
Step 11 : RUN chmod +x /usr/bin/start-server
---&gt; Running in 60b34f80c640
---&gt; c18bb67237cd
Removing intermediate container 60b34f80c640
Step 12 : EXPOSE 3000
---&gt; Running in 0df7cc5c63f4
---&gt; a17e78e23b90
Removing intermediate container 0df7cc5c63f4
Step 13 : CMD ["/usr/bin/start-server"]
---&gt; Running in dcdba9afcffc
---&gt; baa539e0e7af
Removing intermediate container dcdba9afcffc
Successfully built baa539e0e7af

real 17m37.900s
user 0m0.061s
sys 0m0.058s
</code></pre></li>
<li><p>See what images got built.</p>

<pre><code>Host% docker images
REPOSITORY TAG IMAGE ID VIRTUAL SIZE
$DOCKERUSER/docker_quick_start latest baa539e0e7af 765.3 MB
debian jessie 431dac4e3917 90.08 MB
jpetazzo/nsenter latest 1084fe82d2fe 323.4 MB
kamui/postgresql latest 249dad1e2537 387.5 MB
</code></pre></li>
<li><p>Call <code>docker history</code> on <code>$DOCKERUSER/docker_quick_start</code> to see how Docker built this image step by step in reverse chronological order.</p>

<pre><code>Host$ docker history $DOCKERUSER/docker_quick_start
IMAGE CREATED BY SIZE
baa539e0e7af /bin/sh -c #(nop) CMD [/usr/bin/start-server] 0 B
a17e78e23b90 /bin/sh -c #(nop) EXPOSE map[3000/tcp:{}] 0 B
c18bb67237cd /bin/sh -c chmod +x /usr/bin/start-server 191 B
f58f16a503e3 /bin/sh -c #(nop) COPY file:8afcdbd735a94d703
/usr/bin/start-server 191 B
32cd50a4f4c0 /bin/sh -c #(nop) ADD dir:ee1c51c599d1ff1ad19
in /app 1.339 MB
7ecb9e9182eb /bin/sh -c /bin/bash -l -c "bundle install" 155.8 MB
59d5871db18b /bin/sh -c #(nop) WORKDIR /app 0 B
2e42214a73fd /bin/sh -c #(nop) COPY file:3a3f329c666dbce04
/app/Gemfile.lock 6.054 kB
49df2bda31e0 /bin/sh -c #(nop) COPY file:afdf4c2baf9660cfc
in /app/Gemfile 1.287 kB
1c27744233bc /bin/bash -l -c rvm requirements;
rvm install 2.1.2; gem install bundler --no-ri
--no-rdoc 192.4 MB
1dd60b90bb1b /bin/sh -c curl -sSL https://get.rvm.io |
bash -s stable 7.718 MB
a9f3925e86a6 /bin/sh -c apt-get update &amp;&amp; apt-get install
-qy curl git libpq-dev libprocps3 libprocps3-dev
nodejs postgresql procps 332.7 MB
9ce1ff063603 /bin/sh -c #(nop) MAINTAINER Learning Docker 0 B
431dac4e3917 /bin/sh -c #(nop) CMD [/bin/bash] 0 B
a70fb0647e6e /bin/sh -c #(nop) ADD file:29e52cbeed164d50b3
in / 89.59 MB
511136ea3c5a 0 B
</code></pre></li>
<li><p>Run <code>docker build</code> on the same Dockerfile again. This time <code>docker build</code> was able to take advantage of its image cache and complete the build in just a little bit over one second.</p>

<pre><code>Host% time docker build -t $DOCKERUSER/docker_quick_start .
Sending build context to Docker daemon 1.511 MB
Sending build context to Docker daemon
Step 0 : FROM debian:jessie
---&gt; 431dac4e3917
Step 1 : MAINTAINER Learning Docker &lt;jimmy.huang@learningdocker.com&gt;
---&gt; Using cache
---&gt; 9ce1ff063603
Step 2 : RUN apt-get update &amp;&amp; apt-get install -qy \
curl git libpq-dev libprocps3 libprocps3-dev nodejs postgresql procps
---&gt; Using cache
---&gt; a9f3925e86a6
Step 3 : RUN curl -sSL https://get.rvm.io | bash -s stable
---&gt; Using cache
---&gt; 1dd60b90bb1b
Step 4 : RUN ["/bin/bash", "-l", "-c", "rvm requirements; rvm install 2.1.2; gem install bundler --no-ri --no-rdoc"]
---&gt; Using cache
---&gt; 1c27744233bc
Step 5 : COPY Gemfile /app/Gemfile
---&gt; Using cache
---&gt; 49df2bda31e0
Step 6 : COPY Gemfile.lock /app/Gemfile.lock
---&gt; Using cache
---&gt; 2e42214a73fd
Step 7 : WORKDIR /app
---&gt; Using cache
---&gt; 59d5871db18b
Step 8 : RUN ["/bin/bash", "-l", "-c", "bundle install"]
---&gt; Using cache
---&gt; 7ecb9e9182eb
Step 9 : ADD . /app
---&gt; Using cache
---&gt; 32cd50a4f4c0
Step 10 : COPY config/container/start-server.sh /usr/bin/start-server
---&gt; Using cache
---&gt; f58f16a503e3
Step 11 : RUN chmod +x /usr/bin/start-server
---&gt; Using cache
---&gt; c18bb67237cd
Step 12 : EXPOSE 3000
---&gt; Using cache
---&gt; a17e78e23b90
Step 13 : CMD ["/usr/bin/start-server"]
---&gt; Using cache
---&gt; baa539e0e7af
Successfully built baa539e0e7af

real 0m0.206s
user 0m0.014s
sys 0m0.036s
</code></pre></li>
<li><p>Push the newly created Docker image to your Docker Hub account.</p>

<pre><code>Host% docker push $DOCKERUSER/docker_quick_start
</code></pre></li>
</ol>


<h3>How Docker Image Caching Works</h3>

<p>Docker starts the image building process by first launching a container from the base image. Each instruction in Dockerfile makes a change to the container's filesystem. Docker commits that change as a new image and then launches another container from the new image.</p>

<p>As Docker steps through a given Dockerfile, it will use the image generated by the previous instruction (parent image) and the current instruction to do the cache lookup. Docker will iterate over all the images that depend on the parent image and look for one with the same instruction applied to it as the current instruction. If a match surfaces, Docker will skip to the next instruction in the Dockerfile; if no match is found, Docker will execute the current instruction on a container launched from the parent image and commit the resulting change as a new image. The process repeats until all the instructions in the Dockerfile have been evaluated.</p>
Oops, something went wrong.

0 comments on commit 9734fbf

Please sign in to comment.