You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+72-10Lines changed: 72 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -6,12 +6,40 @@ Supplemental materials and reference guide for the Introduction to Docker presen
6
6
7
7
Mac and Windows users will need to install the Docker Toolbox to run and control containers (download for [Windows](https://docs.docker.com/engine/installation/windows/) or [Mac OS](https://docs.docker.com/engine/installation/mac/)).
8
8
9
-
Linux users can [install Docker directly](https://docs.docker.com/engine/installation/linux/) on various distributions.
9
+
Linux users can [install Docker Engine directly](https://docs.docker.com/engine/installation/linux/) on various distributions.
10
10
11
11
##### A note for Mac and Windows users
12
-
While you can't run Docker containers *directly* on your Mac or Windows machine, you can manage and control them as though they were. Docker Toolbox comes with a Mac and Windows native version of the `docker` command that knows how to proxy into the Docker Machine and control containers executing inside that "machine." (This was previously not possible on Windows with boot2docker; Docker Machine fixed this limitation.)
12
+
While you can't run Docker containers *directly* on your Mac or Windows machine, you can manage and control them as though they were. Docker Toolbox comes with a Mac and Windows native version of the `docker` command that knows how to proxy into the Docker Machine and control containers executing inside that "machine" just as though they were executing on your host.
13
13
14
-
*Why should I care?* This feature has the effect of letting native Mac and Windows processes directly control and manage Docker containers. This is especially useful if you're developing code in which your build scripts or integration tests expect to be able to build, start and run a container. Of course, keep in mind that your container-to-host port forwarding will not expose the container's port to your Mac or Windows, but only to your Docker Machine VM. If you need to access your container's ports directly from Mac OS or Windows, you'll need to forward those same ports from the Docker Machine guest OS to your host. (Sound of head exploding, here.)
14
+
**Why should I care?** This feature has the effect of letting native Mac and Windows processes directly control and manage Docker containers. This is especially useful if you're developing code in which your build scripts or integration tests expect to be able to build, start and run a container.
15
+
16
+
Keep in mind that your container-to-host port publishing will not expose the container's port through your Mac or Windows, but only ports to your Docker Machine VM. That is, a container which exposes port 8080 will be accessible from port 8080 on the Docker Machine, *not port 8080 on the Mac or Windows machine*. (Sound of head exploding, here.)
17
+
18
+
To access your container's ports from Mac OS or Windows, you'll need to either:
19
+
20
+
* Direct the request to the IP address of your Docker Machine (use `docker-machine ip` to determine its address), or
21
+
* Forward the same ports your container exposes from the Docker Machine to your host OS (using VirtualBox, typically).
22
+
23
+
For example, lets say you're a Mac user with Docker Toolbox installed and you've just started a container running a web server on port 8080. To reach the web server from a Mac OS terminal, you'd need to first determine the IP address of the Docker Machine:
24
+
25
+
```
26
+
$ docker-machine ip
27
+
192.168.99.104
28
+
```
29
+
30
+
Then make your web request to this IP address:
31
+
32
+
```
33
+
$ curl 192.168.99.104:8080
34
+
Hello World!
35
+
```
36
+
37
+
Of course, if you were to open a shell on the Docker Machine (either via the Quickstart Terminal or with `docker-machine ssh`) then you could access the ports via `localhost`:
38
+
39
+
```
40
+
$ curl localhost:8080
41
+
Hello World!
42
+
```
15
43
16
44
## Docker Command Reference
17
45
@@ -73,12 +101,12 @@ Whenever referring to an image or container by its ID hash (i.e., `fb6bcff347c8`
73
101
To run these examples, you'll need a shell inside the Docker Machine and the contents of this repository. Get started by:
74
102
75
103
1. Start a shell inside your Docker Machine by using the Docker Quickstart Terminal app that was installed on Mac and Windows (Linux users can skip this step). See the "Docker Quickstart Terminal" section of the [Windows](https://docs.docker.com/engine/installation/windows/) and [Mac OS](https://docs.docker.com/engine/installation/mac/) install guide for details.
76
-
2. Clone this repository using the git command `git clone http://github.com/TBD`
104
+
2. Clone this repository using the git command `git clone https://github.com/defano/docker-tutorial.git`
77
105
78
-
As you work through these examples be sure to read, understand, and follow all safety rules that came with your power tools. Also, take a look at the example Dockerfiles. They're commented to explain what's happening in each step.
106
+
As you work through these examples be sure to read, understand, and follow all safety rules that came with your power tools. Also, take a look at the example Dockerfiles. They're commented to explain what's happening at each step.
79
107
80
108
#### Example 1: Static Web Server
81
-
In this example, we'll create a Docker container based on the Ubuntu distribution, install the Nginx server on it and have it serve a single HTML document (one that will be "baked" into the Docker image).
109
+
In this example, we'll create a Docker container from the Ubuntu distribution, install the Nginx server on it, and have it serve a single HTML document (one that will be "baked into" the Docker image).
82
110
83
111
1. Enter the example directory: `cd webserver-example`
84
112
2. Build a Docker image from the Dockerfile using `docker build -t example/nginx-img .` Upon success, this will have create a new Docker image called `example/nginx-img`.
@@ -147,9 +175,43 @@ Then...
147
175
192.168.1.90 redishost
148
176
```
149
177
150
-
In this case, our Redis container is going to be linked into the `springserver` container using the hostname `redishost`. If you were to open a shell in the web server's container (use `docker exec -it springredis bash`) and examine the `/etc/host` file, you'd file a `redisthost` entry similar to that shown above. With this, our Spring Boot web app container can reach the Redis container by referring to it's hostname `redishost`.
178
+
In this case, our Redis container is going to be linked into the `springserver` container using the hostname `redishost`. If you were to open a shell in the web server's container (use `docker exec -it springredis bash`) and examine the `/etc/host` file, you'd find a `redisthost` entry similar to that shown in the last line above. With this host entry in place, our Spring Boot web app container can reach the Redis container by referring to it's hostname `redishost`. Neat.
179
+
180
+
#### Example 5: Orchestrating containers with Docker Compose
181
+
Linking containers is pretty cool. That said, it's not hard to imagine how this could become quite unmanageable as the number of containers that need to communicate with one another grow within a distributed system. Docker provides the Compose tool for scripting the creation and linking of containers (very handy for development and CI environments).
182
+
183
+
This time, we'll reproduce the Redis / Spring Web App system we created in the last example, but provision it with Docker Compose.
184
+
185
+
Mac and Windows users should already have the Docker Compose tool installed (as a result of installing Docker Toolbox); Linux users may need to [install it directly](https://docs.docker.com/compose/install/).
186
+
187
+
Note that the Docker Compose tool is installed on your host operating system (i.e., Mac or Windows), not the Docker Machine VM. If you've been working inside a shell on the VM (i.e., the Quickstart Terminal) you'll need to create a new terminal on your host, pull this repository onto your host and proceed with the following steps there.
188
+
189
+
1. Enter the `compose-example` directory, `cd compose-example`.
190
+
2. Examine the contents of the `docker-compose.yml` file in this directory; this file scripts how to build and link the Spring Boot and Redis containers.
191
+
3. Fire up the system with `docker-compose up`. Provided all goes according to plan, you'll see both containers start up in "attached" mode (that is, their output is written to your terminal). Passing `-d` will run them in "detached" mode (as we've been doing when starting these containers manually).
192
+
193
+
Then...
194
+
195
+
1. Verify that both containers are running and linked just as you did in the last example: `curl 'localhost:8080/set?key=k&value=v'` followed by `curl 'localhost:8080/get?key=k'`
196
+
197
+
## What next?
198
+
199
+
We have not been able to cover every aspect--or even every tool--of the Docker ecosystem. Here are a few paths to explore on your own:
200
+
201
+
#### Docker Swarm
202
+
203
+
You may have noticed one glaring limitation in all of these examples and tools: All of our containers are running on the same physical machine. Creating, scaling, and managing a system of containers distributed across physical hosts introduces its own challenges.
204
+
205
+
Docker Swarm is designed to manage container provisioning across hosts. You can learn more about it, [here](https://docs.docker.com/swarm/overview/).
206
+
207
+
#### Docker Hub
208
+
209
+
Each of our examples have built Docker images from a base image that "automagically" made it onto your host. Where did these Ubuntu distributions come from? Docker Hub. A repository--not unlike Maven Central, CPAN or Github--for publishing Docker images. Docker Hub is a terrific resource for getting started with Docker and virtually any other tool.
210
+
211
+
Wanna experiment with Cassandra without having to figure out how to install and configure a basic instance? Use Docker Hub to find an open sourced image. Need a quick Node.JS installation to test some Javascript on? Find it on Docker Hub.
212
+
213
+
Search for ready-to-use Docker images [on the web](https://hub.docker.com/explore/), or directly from the command line using `docker search <search-terms>`.
151
214
152
-
#### Example 5: Linking containers with Docker Compose
153
-
Linking containers is pretty cool. That said, it's not hard to imagine how this could become quite unmanageable as the number of containers that need to communicate with one another grow within a distributed system. Docker provides the Compose tool for scripting the creation and linking of many containers (very handy for development and CI environments).
215
+
After you've found an image you like, use the `docker pull <image-name>` to download it into your cache.
154
216
155
-
In this example, we'll reproduce the Redis / Spring Web App system we created in the last example, but this time we'll provision it with Docker Compose.
217
+
And when you've created an image worth sharing with the world, publish it to Docker Hub with the `docker push` command.
0 commit comments