Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 7cdc22a

Browse files
author
Mano Marks
authored
Merge pull request #365 from arun-gupta/dockercon1
#DockerCon sprint
2 parents 1cb986a + 839ab97 commit 7cdc22a

File tree

7 files changed

+56
-75
lines changed

7 files changed

+56
-75
lines changed

developer-tools/java/chapters/ch01-setup.adoc

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,61 +16,26 @@ NOTE: An older version of the operating system may be used. The installation ins
1616

1717
== Install Docker
1818

19-
Docker runs natively on Mac, Windows and Linux. This lab will use https://www.docker.com/community-edition[Docker Community Edition]. Follow the https://www.docker.com/community-edition[instructions] to install Docker.
19+
Docker runs natively on Mac, Windows and Linux. This lab will use https://www.docker.com/community-edition[Docker Community Edition (CE)]. Download the Docker CE edition for your machine from the https://store.docker.com/search?type=edition&offering=community[Docker Store].
2020

21-
This workshop is tested with Docker Community Edition `17.09.0-ce-rc2, build 363a3e7` on Mac OS X `10.12.5`.
22-
23-
NOTE: Docker Community Edition have requirements for a fairly recent operating system version. If your machine does not meet these requirements, then you need to install https://www.docker.com/products/docker-toolbox[Docker Toolbox]. However, the workshop instructions are all explained using Docker CE.
24-
25-
=== Additional components
26-
27-
If Docker is installed using Docker CE or Docker Toolbox, then this section is not required.
28-
29-
Install the following additional components:
21+
NOTE: Docker CE requires a fairly recent operating system version. If your machine does not meet the requirements, then you need to install https://www.docker.com/products/docker-toolbox[Docker Toolbox].
3022

31-
. https://docs.docker.com/compose/install/[Docker Compose]
32-
33-
=== Docker Toolbox Notes
34-
35-
Skip this section if you are using Docker CE.
36-
37-
. *Default Docker Machine*: Docker Toolbox creates a Docker Machine named `default`. To make it easier to start/stop the containers, an entry is added into the host mapping table of your operating system.
38-
+
39-
Find out the IP address of your Docker Machine:
40-
+
41-
```
42-
docker-machine ip default
43-
```
44-
+
45-
This will provide the IP address associated with the Docker Machine created by Toolbox.
46-
+
47-
Edit `/etc/hosts` (Mac OS) or `C:\Windows\System32\drivers\etc\hosts` (Windows) and add:
48-
+
49-
[source, text]
50-
----
51-
<IP ADDRESS> dockerhost
52-
----
53-
+
54-
This allows to access Docker containers using `dockerhost`.
55-
+
56-
. *Docker CLI Shell*: Any Docker CLI command needs to be issued from the Terminal or Command Prompt where `eval $(docker-machine env default)` command was issued. This will make sure Docker CLI is configured to talk to the VM created by Docker Toolbox.
23+
This workshop is tested with Docker Community Edition `17.09.0-ce-rc2, build 363a3e7` on Mac OS X `10.12.5`.
5724

5825
== Download Images
5926

6027
This tutorial uses a few Docker images and software. Let's download them before we start the tutorial.
6128

62-
Download the file from https://raw.githubusercontent.com/docker/labs/master/developer-tools/java/scripts/docker-compose-pull-images.yml and give the command to pull all the images:
29+
Download the file from https://raw.githubusercontent.com/docker/labs/master/developer-tools/java/scripts/docker-compose-pull-images.yml and use the following command to pull the required images:
6330

64-
```
65-
docker-compose -f docker-compose-pull-images.yml pull --parallel
66-
```
67-
68-
NOTE: `--parallel` switch will not work for Docker Compose version prior to 1.12. If you are using an older version then remove the `--parallel` switch.
31+
docker-compose -f docker-compose-pull-images.yml pull --parallel
6932

7033
NOTE: For Linux, `docker-compose` and `docker` commands need `sudo` access. So prefix all commands with `sudo`.
7134

7235
== Other Software
7336

37+
The software in this section is specific to certain parts of the workshop. Install them only if you plan to attempt them.
38+
7439
. Install https://git-scm.com//[git].
7540
. Install Docker Cloud CLI following the https://docs.docker.com/docker-cloud/installing-cli/[instructions].
7641
. Download Java IDE based upon your choice and install.

developer-tools/java/chapters/ch02-basic-concepts.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
*PURPOSE*: This chapter introduces the basic terminology of Docker.
99

1010
[quote, docs.docker.com/]
11-
Docker is a platform for developers and sysadmins to build, ship, and run applications. Docker lets you quickly assemble applications from components and eliminates the friction that can come when shipping code. Docker lets you get your code tested and deployed into production as fast as possible.
11+
Docker is a platform for developers and sysadmins to build, ship, and run applications. Docker lets you quickly assemble applications from components and eliminates the friction that can come when shipping code. Docker lets you test and deploy your code into production as fast as possible.
1212

1313
Docker simplifies software delivery by making it easy to build and share images that contain your application’s entire environment, or _application operating system_.
1414

1515
**What does it mean by an application operating system ?**
1616

17-
Your application typically require a specific version of operating system, application server, JDK, database server, may require to tune the configuration files, and similarly multiple other dependencies. The application may need binding to specific ports and certain amount of memory. The components and configuration together required to run your application is what is referred to as application operating system.
17+
Your application typically requires specific versions for your operating system, application server, JDK, and database server, may require to tune the configuration files, and similarly multiple other dependencies. The application may need binding to specific ports and certain amount of memory. The components and configuration together required to run your application is what is referred to as application operating system.
1818

1919
You can certainly provide an installation script that will download and install these components. Docker simplifies this process by allowing to create an image that contains your application and infrastructure together, managed as one component. These images are then used to create Docker containers which run on the container virtualization platform, provided by Docker.
2020

developer-tools/java/chapters/ch03-build-image-java-9.adoc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ constraints are honored.
4444

4545
Build the image using the command:
4646

47-
docker build -t jdk-9-debian-slim -f jdk-9-debian-slim.Dockerfile .
47+
docker image build -t jdk-9-debian-slim -f jdk-9-debian-slim.Dockerfile .
4848

4949
List the images available using `docker image ls`:
5050

@@ -89,15 +89,15 @@ $1 ==> 100
8989
----
9090

9191
Notice that the Java process is honoring memory constraints (see the `--memory`
92-
of `docker run`) and will not allocate memory beyond that specified for the
92+
of `docker container run`) and will not allocate memory beyond that specified for the
9393
container.
9494

9595
In a future release of the JDK it will no longer be necessary to specify an
9696
experimental flag (`-XX:+UnlockExperimentalVMOptions`) once the mechanism by
9797
which memory constraints are efficiently detected is stable.
9898

9999
JDK 9 supports the set CPUs constraint (see the `--cpuset-cpus` of
100-
`docker run`) but does not currently support other CPU constraints such as
100+
`docker container run`) but does not currently support other CPU constraints such as
101101
CPU shares. This is ongoing work http://openjdk.java.net/jeps/8182070[tracked]
102102
in the OpenJDK project.
103103

@@ -234,7 +234,7 @@ The image is configured in the same manner as for the `debian`-based image.
234234

235235
Build the image using the command:
236236

237-
docker build -t jdk-9-alpine -f jdk-9-alpine.Dockerfile .
237+
docker image build -t jdk-9-alpine -f jdk-9-alpine.Dockerfile .
238238

239239
List the images available using `docker image ls`:
240240

@@ -268,7 +268,7 @@ so you can make modifications.)
268268
Enter the directory `helloworld-java-9` and build the project from within a
269269
running Docker container with JDK 9 installed:
270270

271-
docker run --volume $PWD:/helloworld-java-9 --workdir /helloworld-java-9 \
271+
docker container run --volume $PWD:/helloworld-java-9 --workdir /helloworld-java-9 \
272272
-it --rm openjdk:9-jdk-slim \
273273
./mvnw package
274274

@@ -298,7 +298,7 @@ CMD java -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap \
298298
Build a Docker image containing the simple Java application based of the Docker
299299
image `jdk-9-debian-slim`:
300300

301-
docker build -t helloworld-jdk-9 -f helloworld-jdk-9.Dockerfile .
301+
docker image build -t helloworld-jdk-9 -f helloworld-jdk-9.Dockerfile .
302302

303303
List the images available using `docker image ls`:
304304

@@ -317,7 +317,7 @@ Notice how large the application image `helloworld-jdk-9`.
317317

318318
Run the `jdeps` tool to see what modules the application depends on:
319319

320-
docker run -it --rm helloworld-jdk-9 jdeps --list-deps /opt/helloworld/helloworld-1.0-SNAPSHOT.jar
320+
docker container run -it --rm helloworld-jdk-9 jdeps --list-deps /opt/helloworld/helloworld-1.0-SNAPSHOT.jar
321321

322322
and observe that the application only depends on the `java.base` module.
323323

@@ -332,7 +332,7 @@ that in application Docker image.
332332
Create a custom Java runtime that is small and only contains the `java.base`
333333
module:
334334

335-
docker run --rm \
335+
docker container run --rm \
336336
--volume $PWD:/out \
337337
jdk-9-debian-slim \
338338
jlink --module-path /opt/jdk-9/jmods \
@@ -344,7 +344,7 @@ module:
344344

345345
This command exists as `create-minimal-java-runtime.sh` script in the repo earlier checked out from link:https://github.com/PaulSandoz/helloworld-java-9[helloworld-java-9].
346346

347-
The JDK 9 tool `jlink` is used to create the custom Java runtime. Read more jlink in the https://docs.oracle.com/javase/9/tools/jlink.htmp[Tools Reference]. The tool
347+
The JDK 9 tool `jlink` is used to create the custom Java runtime. Read more jlink in the https://docs.oracle.com/javase/9/tools/jlink.htm[Tools Reference]. The tool
348348
is executed from with the container containing JDK 9 and directory where the
349349
modules reside, `/opt/jdk-9/jmods`, is declared in the module path. Only the
350350
`java.base` module is selected.
@@ -387,7 +387,7 @@ CMD java -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap \
387387
Build a Docker image containing the simple Java application based of the Docker
388388
image `debian:stable-slim`:
389389

390-
docker build -t helloworld-jdk-9-base -f helloworld-jdk-9-base.Dockerfile .
390+
docker image build -t helloworld-jdk-9-base -f helloworld-jdk-9-base.Dockerfile .
391391

392392
List the images available using `docker image ls`:
393393

developer-tools/java/chapters/ch03-build-image.adoc

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
== Dockerfile
1010

11-
Docker build images by reading instructions from a _Dockerfile_. A _Dockerfile_ is a text document that contains all the commands a user could call on the command line to assemble an image. `docker build` command uses this file and executes all the commands in succession to create an image.
11+
Docker build images by reading instructions from a _Dockerfile_. A _Dockerfile_ is a text document that contains all the commands a user could call on the command line to assemble an image. `docker image build` command uses this file and executes all the commands in succession to create an image.
1212

1313
`build` command is also passed a context that is used during image creation. This context can be a path on your local filesystem or a URL to a Git repository.
1414

@@ -96,7 +96,7 @@ If you do not see the expected output, check your Dockerfile that the content ex
9696

9797
Change the base image from `ubuntu` to `busybox` in `Dockerfile`. Build the image again:
9898

99-
docker build -t helloworld:2 .
99+
docker image build -t helloworld:2 .
100100

101101
and view the images using `docker image ls` command:
102102

@@ -172,10 +172,7 @@ Let's package this application as a Docker image.
172172

173173
Run the OpenJDK container in an interactive manner:
174174

175-
[source, text]
176-
----
177-
docker run -it openjdk
178-
----
175+
docker container run -it openjdk
179176

180177
This will open a terminal in the container. Check the version of Java:
181178

@@ -206,11 +203,11 @@ CMD java -cp /usr/src/helloworld-1.0-SNAPSHOT.jar org.examples.java.App
206203

207204
Build the image:
208205

209-
docker build -t hello-java:latest .
206+
docker image build -t hello-java:latest .
210207

211208
Run the image:
212209

213-
docker run hello-java:latest
210+
docker container run hello-java:latest
214211

215212
This displays the output:
216213

@@ -274,7 +271,7 @@ This will show an output like:
274271
[INFO] DOCKER> [hellojava:latest]: Waited on log out 'Hello World!' 510 ms
275272
----
276273

277-
This is similar output when running the Java application using `java` CLI or the Docker container using `docker run` command.
274+
This is similar output when running the Java application using `java` CLI or the Docker container using `docker container run` command.
278275

279276
The container is running in the foreground. Use `Ctrl` + `C` to interrupt the container and return back to terminal.
280277

@@ -342,17 +339,17 @@ Only one change was required in the project to enable Docker packaging and runni
342339

343340
Default entry point for a container is `/bin/sh`, the default shell.
344341

345-
Running a container as `docker run -it ubuntu` uses that command and starts the default shell. The output is shown as:
342+
Running a container as `docker container run -it ubuntu` uses that command and starts the default shell. The output is shown as:
346343

347344
```console
348-
> docker run -it ubuntu
345+
> docker container run -it ubuntu
349346
root@88976ddee107:/#
350347
```
351348

352349
`ENTRYPOINT` allows to override the entry point to some other command, and even customize it. For example, a container can be started as:
353350

354351
```console
355-
> docker run -it --entrypoint=/bin/cat ubuntu /etc/passwd
352+
> docker container run -it --entrypoint=/bin/cat ubuntu /etc/passwd
356353
root:x:0:0:root:/root:/bin/bash
357354
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
358355
bin:x:2:2:bin:/bin:/usr/sbin/nologin

developer-tools/java/chapters/ch08-aws.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ It will take a few minutes for the CloudFormation template to complete. The outp
5959
.Swarm CloudFormation complete
6060
image::docker-aws-7.png[]
6161

62-
https://console.aws.amazon.com/ec2/v2/home?region=us-east-1#Instances:search=docker;sort=instanceState[EC2 Console] will show the EC2 instances for manager and worker.
62+
https://console.aws.amazon.com/ec2/v2/home?#Instances:search=docker;sort=instanceState[EC2 Console] will show the EC2 instances for manager and worker.
6363

6464
.EC2 console
6565
image::docker-aws-8.png[]
@@ -371,7 +371,7 @@ More details about the service can be obtained using `docker -H localhost:2374 s
371371
]
372372
```
373373

374-
Logs for the service are redirected to CloudWatch and thus cannot be seen using `docker service logs`. This will be fixed with https://github.com/moby/moby/issues/30691[#30691]. Let's view the logs using using https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logs:prefix=Docker[CloudWatch Logs].
374+
Logs for the service are redirected to CloudWatch and thus cannot be seen using `docker service logs`. This will be fixed with https://github.com/moby/moby/issues/30691[#30691]. Let's view the logs using using https://console.aws.amazon.com/cloudwatch/home?#logs:prefix=Docker[CloudWatch Logs].
375375

376376
.CloudWatch log group
377377
image::docker-aws-10.png[]
@@ -390,7 +390,7 @@ image::docker-aws-12.png[]
390390

391391
Application is accessed using manager's IP address and on port 8080. By default, the port 8080 is not open.
392392

393-
In https://console.aws.amazon.com/ec2/v2/home?region=us-east-1#Instances:search=docker;sort=instanceState[EC2 Console], select an EC2 instance with name `Docker-Manager`, click on `Docker-Managerxxx` in `Security groups`. Click on `Inbound`, `Edit`, `Add Rule`, and create a rule to enable TCP traffic on port 8080.
393+
In https://console.aws.amazon.com/ec2/v2/home?#Instances:search=docker;sort=instanceState[EC2 Console], select an EC2 instance with name `Docker-Manager`, click on `Docker-Managerxxx` in `Security groups`. Click on `Inbound`, `Edit`, `Add Rule`, and create a rule to enable TCP traffic on port 8080.
394394

395395
.Open port 8080 in Docker manager
396396
image::docker-aws-13.png[]

developer-tools/java/chapters/ch10-monitoring.adoc

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,25 @@ to see the output:
5353
+
5454
```
5555
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
56-
55198043b6aa 0.12% 267.3MiB / 1.952GiB 13.38% 782B / 0B 0B / 4.1kB 53
57-
5b5dd33b675d 0.11% 274.2MiB / 1.952GiB 13.72% 782B / 0B 0B / 4.1kB 53
58-
6e98a9597e6a 0.10% 273.2MiB / 1.952GiB 13.67% 1.03kB / 0B 0B / 4.1kB 51
56+
1f9d5a1c08a8 0.24% 294.9MiB / 1.952GiB 14.75% 828B / 0B 96.5MB / 4.1kB 115
5957
```
6058
+
61-
Note that the container id is shown in this case instead of container's name.
59+
Note that the container id is shown instead of container's name in this case.
60+
+
61+
. Scale the service to 3 replicas:
62+
+
63+
```
64+
docker service scale web=3
65+
```
66+
+
67+
. The stats are now shown for all three containers:
68+
+
69+
```
70+
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
71+
1f9d5a1c08a8 0.14% 287.8MiB / 1.952GiB 14.40% 1.03kB / 0B 96.5MB / 4.1kB 53
72+
a3395efbb6ff 0.77% 263.4MiB / 1.952GiB 13.18% 578B / 0B 0B / 4.1kB 114
73+
f484ff2f4c12 0.06% 294.8MiB / 1.952GiB 14.75% 578B / 0B 0B / 4.1kB 114
74+
```
6275
+
6376
. Display only container id and percent CPU utilization using the command `docker container stats --format "{{.Container}}: {{.CPUPerc}}"`:
6477
+
@@ -802,7 +815,7 @@ This section will explain how to start Grafana, use Prometheus as the data sourc
802815
. Start Grafana:
803816
+
804817
```
805-
docker run \
818+
docker container run \
806819
-d \
807820
-p 3000:3000 \
808821
--name=grafana \

developer-tools/java/scripts/docker-compose-pull-images.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ services:
1919
jenkins:
2020
image: tailtarget/jenkins:2.32.3
2121
prometheus:
22-
image: prom/prometheus
22+
image: prom/prometheus:latest
2323
node-exporter:
2424
image: prom/node-exporter
2525
cadvisor:
2626
image: google/cadvisor:latest
2727
grafana:
2828
image: grafana/grafana
29+
debian:
30+
image: debian:stable-slim
31+
alpine:
32+
image: alpine:3.6
33+
openjdk-slim:
34+
image: openjdk:9-jdk-slim

0 commit comments

Comments
 (0)