Skip to content

Commit 6074ae3

Browse files
londoncallingMano Marks
authored and
Mano Marks
committed
more docs edits per examples walkthru, incl d4mac and d4win updates, and documenting the glitch with seqvence/static-site for now (docker#42)
Signed-off-by: Victoria Bialas <victoria.bialas@docker.com>
1 parent f2914e5 commit 6074ae3

File tree

1 file changed

+47
-19
lines changed

1 file changed

+47
-19
lines changed

beginner/chapters/webapps.md

+47-19
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,56 @@ Great! So you have now looked at `docker run`, played with a docker container an
66
77
Let's start by taking baby-steps. First, we'll use Docker to run a dead-simple static website. You're going to pull a Docker image from the Docker Hub, run the container and see how easy it is to set up a web server.
88

9-
The image that you are going to use is a single-page website that was already created for this demo and is available on the Docker Hub as [`seqvence/static-site`](https://hub.docker.com/r/seqvence/static-site/). You can download and run the image directly in one go using `docker run`.
9+
The image that you are going to use is a single-page website that was already created for this demo and is available on the Docker Hub as [`seqvence/static-site`](https://hub.docker.com/r/seqvence/static-site/). You can download and run the image directly in one go using `docker run` as follows.
1010

1111
```
12-
$ docker run seqvence/static-site
12+
$ docker run -d seqvence/static-site
1313
```
14-
Since the image doesn't exist on your Docker host, the Docker daemon first fetches the image from the registry and then runs the image.
1514

16-
* Okay, now that the server is running, do you see the website?
17-
* What port is it running on?
18-
* And more importantly, how do you access the container directly from our host machine?
15+
>**Note:** The current version of this image doesn't run without the `-d` flag, although it should. The `-d` flag enables **detached mode**, which detaches the running container from the terminal/shell and returns your prompt after the container starts. We are debugging the problem with this image but for now, use `-d` even for this first example.
1916
20-
In this case, the client didn't tell the Docker Engine to publish any of the ports, so you need to re-run the `docker run` command. We'll take the oportunity to publish ports and pass your name to the container to customize the message displayed. While we are at it, you should also find a way so that our terminal is not attached to the running container. So that you can happily close your terminal and keep the container running. This is called the **detached** mode.
17+
So, what happens when you run this command?
2118

22-
Before we look at the **detached** mode, we should first find out a way to stop the container that you have just launched.
19+
Since the image doesn't exist on your Docker host, the Docker daemon first fetches the it from the registry and then runs it as a container.
20+
21+
Now that the server is running, do you see the website? What port is it running on? And more importantly, how do you access the container directly from our host machine?
22+
23+
Actually, you probably won't be able to answer any of these questions yet! &#9786; In this case, the client didn't tell the Docker Engine to publish any of the ports, so you need to re-run the `docker run` command to add this instruction.
24+
25+
Let's re-run the command with some new flags to publish ports and pass your name to the container to customize the message displayed. We'll use the *-d* option again to run the container in detached mode.
26+
27+
First, stop the container that you have just launched. In order to do this, we need the container ID.
28+
29+
Since we ran the container in detached mode, we don't have to launch another terminal to do this. Run `docker ps` to view the running containers.
2330

24-
First up, launch another terminal (command window) and execute the following command. If you're using docker-machine you need to run `eval $(docker-machine env <YOUR_DOCKER_MACHINE_NAME>)` in each new terminal otherwise you'll get the error "Cannot connect to the Docker daemon. Is the docker daemon running on this host?".
2531
```
2632
$ docker ps
2733
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2834
a7a0e504ca3e seqvence/static-site "/bin/sh -c 'cd /usr/" 28 seconds ago Up 26 seconds 80/tcp, 443/tcp stupefied_mahavira
2935
```
3036

31-
Check out the `CONTAINER ID` column. You will need to use this `CONTAINER ID` value, a long sequence of characters and first stop the running container and then remove the running container as given below. The example below provides the `CONTAINER ID` on our system, you should use the value that you see in your terminal.
37+
Check out the `CONTAINER ID` column. You will need to use this `CONTAINER ID` value, a long sequence of characters, to identify the container you want to stop, and then to remove it. The example below provides the `CONTAINER ID` on our system; you should use the value that you see in your terminal.
3238
```
3339
$ docker stop a7a0e504ca3e
3440
$ docker rm a7a0e504ca3e
3541
```
3642

37-
Note: A cool feature is that you do not need to specify the entire `CONTAINER ID`. You can just specify a few starting characters and if it is unique among all the containers that you have launched, the Docker client will intelligently pick it up.
43+
>**Note:** A cool feature is that you do not need to specify the entire `CONTAINER ID`. You can just specify a few starting characters and if it is unique among all the containers that you have launched, the Docker client will intelligently pick it up.
3844
39-
Now, let us launch a container in **detached** mode as shown below:
45+
Now, let's launch a container in **detached** mode as shown below:
4046

4147
```
4248
$ docker run --name static-site -e AUTHOR="Your Name" -d -P seqvence/static-site
4349
e61d12292d69556eabe2a44c16cbd54486b2527e2ce4f95438e504afb7b02810
4450
```
4551

46-
In the above command, `-d` will create a container with the process detached from our terminal, `-P` will publish all the exposed container ports to random ports on the Docker host, `-e` is how you pass environment variables to the container, and finally `--name` allows you to specify a container name. `AUTHOR` is the environment variable name and `Your Name` is the value that you can pass.
52+
In the above command:
53+
54+
* `-d` will create a container with the process detached from our terminal
55+
* `-P` will publish all the exposed container ports to random ports on the Docker host
56+
* `-e` is how you pass environment variables to the container
57+
* `--name` allows you to specify a container name
58+
* `AUTHOR` is the environment variable name and `Your Name` is the value that you can pass
4759

4860
Now you can see the ports by running the `docker port` command.
4961

@@ -53,13 +65,15 @@ $ docker port static-site
5365
80/tcp -> 0.0.0.0:32773
5466
```
5567

56-
If you're on Linux, you can open [http://localhost:32773](http://localhost:32773) (replace 32773 with your port for 80/tcp) in your browser. If you're on Windows or a Mac, you need to find the IP of the hostname.
68+
If you are running [Docker for Mac](https://docs.docker.com/docker-for-mac/), [Docker for Windows](https://docs.docker.com/docker-for-windows/), or Docker on Linux, you can open `http://localhost:YOUR_PORT_FOR 80/tcp`. For our example this is `http://localhost:32773`.
69+
70+
If you are using Docker Machine on Mac or Windows, you can find the hostname on the command line using `docker-machine` as follows (assuming you are using the `default` machine).
5771

5872
```
5973
$ docker-machine ip default
6074
192.168.99.100
6175
```
62-
You can now open [http://192.168.99.100:32773](http://192.168.99.100:32773) (replace 32773 with your port for 80/tcp) to see your site live!
76+
You can now open `http://<YOUR_IPADDRESS>:YOUR_PORT_FOR 80/tcp` to see your site live! For our example, this is: `http://192.168.99.100:32773`.
6377

6478
You can also run a second webserver at the same time, specifying a custom host port mapping to the container's webserver.
6579

@@ -68,13 +82,27 @@ $ docker run --name static-site-2 -e AUTHOR="Your Name" -d -p 8888:80 seqvence/s
6882
```
6983
<img src="../images/static.png" title="static">
7084

71-
I'm sure you agree that was super simple. To deploy this on a real server you would just need to install docker, and run the above docker command.
85+
I'm sure you agree that was super simple. To deploy this on a real server you would just need to install Docker, and run the above `docker` command.
86+
87+
Now that you've seen how to run a webserver inside a Docker image, you must be wondering - how do I create my own Docker image? This is the question we'll explore in the next section.
7288

73-
Now that you've seen how to run a webserver inside a docker image, you must be wondering - how do I create my own docker image? This is the question we'll be exploring in the next section. But first, let's stop and remove the containers since you won't be using them anymore.
89+
But first, let's stop and remove the containers since you won't be using them anymore.
7490

7591
```
76-
$ docker stop static-site static-site-2
77-
$ docker rm static-site static-site-2
92+
$ docker stop static-site static-site
93+
$ docker rm static-site static-site
94+
```
95+
96+
Let's use a shortcut to remove the second site:
97+
98+
```
99+
$ docker rm -f static-site static-site-2
100+
```
101+
102+
Run `docker ps` to make sure the containers are gone.
103+
```
104+
$ docker ps
105+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
78106
```
79107

80108
### 2.2 Docker Images

0 commit comments

Comments
 (0)