Skip to content

Commit 458c71b

Browse files
committed
refactoring to multiple chapters, adding a script to generate PDF, added a PDF
1 parent 9f4a956 commit 458c71b

25 files changed

Lines changed: 1264 additions & 1184 deletions

chapters/container-cluster.adoc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
A frequent requirement for Java EE based applications is running them on a cluster of application server. While setup and test can be complicated on developer machines, this is where Docker can play to it's full potential. With the help of images and automatic port mapping, we're ready to test Ticket Monster on a couple of WildFly instances and add and remove them randomly.
2+
3+
The diagram below shows what will be achieved in this section:
4+
5+
.Standalone Cluster with WildFly and mod_cluster
6+
image::../images/wildfly_cluster1.png[]
7+
8+
. Start Apache HTTPD server
9+
+
10+
[source, text]
11+
----
12+
docker run -d --name modcluster -p 80:80 <INSTRUCTOR_IP>:5000/mod_cluster
13+
----
14+
+
15+
. Open http://dockerhost/mod_cluster_manager in your browser to see the empty console as:
16+
+
17+
.Apache HTTPD runing mod_cluster_manager interface
18+
image::../images/wildfly_cluster2.png[]
19+
+
20+
. Start the first WildFly instance:
21+
+
22+
[source, text]
23+
----
24+
docker run -d --name server1 --link db:db --link modcluster:modcluster <INSTRUCTOR_IP>:5000/ticketmonster-pgsql-wildfly
25+
----
26+
+
27+
Besides linking the database container using `--link db:db`, we also link the ``modcluster'' container. This should be done rather quickly and if you now revisit the http://dockerhost/mod_cluster_manager/[mod_cluster_manager] in your browser, then you can see that the first server was registered with the loadbalancer:
28+
+
29+
.First WildFly instance registered with Load Balancer
30+
image::../images/wildfly_cluster3.png[]
31+
+
32+
. To make sure the Ticket Monster application is also running just visit http://dockerhost/ticket-monster and you will be presented with the Ticket Monster welcome screen.
33+
+
34+
.Clustered Ticket Monster Application
35+
image::../images/wildfly_cluster4.png[]
36+
+
37+
. Start as many WildFly instances as you want (and your computer memory can handle):
38+
+
39+
[source, text]
40+
----
41+
docker run -d --name server2 --link db:db --link modcluster:modcluster <INSTRUCTOR_IP>:5000/ticketmonster-pgsql-wildfly
42+
docker run -d --name server3 --link db:db --link modcluster:modcluster <INSTRUCTOR_IP>:5000/ticketmonster-pgsql-wildfly
43+
docker run -d --name server4 --link db:db --link modcluster:modcluster <INSTRUCTOR_IP>:5000/ticketmonster-pgsql-wildfly
44+
----
45+
+
46+
. Stop some servers and check the application behavior:
47+
+
48+
[source, text]
49+
----
50+
docker stop server1
51+
docker stop server3
52+
----
53+
54+
TODO: Pick the parts that need to be described in more detail from https://goldmann.pl/blog/2013/10/07/wildfly-cluster-using-docker-on-fedora/

chapters/docker-basics.adoc

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
Docker simplifies software delivery by making it easy to build and share images that contain your application’s entire environment, or application operating system.
2+
3+
**What does it mean by an application operating system ?**
4+
5+
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.
6+
7+
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.
8+
9+
**What can a Java Developer use Docker for?**
10+
11+
. *Faster delivery of your applications*: Docker helps you with the development lifecycle.
12+
Docker allows you to develop on local containers that contain your applications
13+
and services. It can then integrate into a continuous integration and
14+
deployment workflow.
15+
+
16+
For example, you write code locally and share the development stack
17+
via Docker with colleagues. When everybody is ready, you push the
18+
code and the stack you all are developing onto a test environment
19+
and execute any required tests.
20+
+
21+
From the testing environment, you can then push the Docker images
22+
into production and deploy your code.
23+
+
24+
. *Deploying and scaling more easily*: Docker's container-based platform allows for portable workloads. Docker containers can run on a developer's local host, on physical
25+
or virtual machines in a data center, or in the Cloud.
26+
+
27+
Docker's portability and lightweight nature also make dynamically managing workloads easy. You can use Docker to quickly scale up or tear down applications and services. Docker is so fast, that scaling can be near real time.
28+
29+
**How is it different from VM?**
30+
31+
Docker is an open source container virtualization platform.
32+
33+
Docker has three main components:
34+
35+
. __Images__ are *build component* of Docker and a read-only template of application operating system.
36+
. __Containers__ are *run component* of Docker, and created from, images.Containers can be run, started, stopped, moved, and deleted.
37+
. Images are stored, shared, and managed in a __registry__, the *distribution component* of Docker. The publically available registry is known as Docker Hub.
38+
39+
In order for these three components to work together, there is *Docker Daemon* that runs on a host machine and does the heavy lifting of building, running, and distributing Docker containers. In addition, there is *Client* that is a Docker binary which accepts commands from the user and communicates back and forth with the daemon.
40+
41+
.Docker architecture
42+
image::../images/docker-architecture.png[]
43+
44+
Client communicates with Daemon, either co-located on the same host, or on a different host. It requests the Daemon to pull an image from the repository using `pull` command. The Daemon then downloads the image from Docker Hub, or whatever registry is configured. Multiple images can be downloaded from the registry and installed on Daemon host. Images are run using `run` command to create containers on demand.
45+
46+
**How does a Docker Image work?**
47+
48+
We've already seen that Docker images are read-only templates from which Docker containers are launched. Each image consists of a series of layers. Docker makes use of union file systems to combine these layers into a single image. Union file systems allow files and directories of separate file systems, known as branches, to be transparently overlaid, forming a single coherent file system.
49+
50+
One of the reasons Docker is so lightweight is because of these layers. When you change a Docker image—for example, update an application to a new version— a new layer gets built. Thus, rather than replacing the whole image or entirely rebuilding, as you may do with a virtual machine, only that layer is added or updated. Now you don't need to distribute a whole new image, just the update, making distributing Docker images faster and simpler.
51+
52+
Every image starts from a base image, for example `ubuntu`, a base Ubuntu image, or `fedora`, a base Fedora image. You can also use images of your own as the basis for a new image, for example if you have a base Apache image you could use this as the base of all your web application images.
53+
54+
NOTE: By default, Docker obtains these base images from Docker Hub.
55+
56+
Docker images are then built from these base images using a simple, descriptive set of steps we call instructions. Each instruction creates a new layer in our image. Instructions include actions like:
57+
58+
. Run a command.
59+
. Add a file or directory.
60+
. Create an environment variable.
61+
. What process to run when launching a container from this image.
62+
63+
These instructions are stored in a file called a Dockerfile. Docker reads this Dockerfile when you request a build of an image, executes the instructions, and returns a final image.
64+
65+
**How does a Container work?**
66+
67+
A container consists of an operating system, user-added files, and meta-data. As we've seen, each container is built from an image. That image tells Docker what the container holds, what process to run when the container is launched, and a variety of other configuration data. The Docker image is read-only. When Docker runs a container from an image, it adds a read-write layer on top of the image (using a union file system as we saw earlier) in which your application can then run.

chapters/docker-client.adoc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The client communicates with the demon process on your host and let's you work with images and containers.
2+
3+
Check if your client is working using the following command:
4+
5+
[source, text]
6+
----
7+
docker -v
8+
----
9+
10+
The most important options you'll be using frequently are:
11+
12+
. `run` - runs a container
13+
. `ps`- lists containers
14+
. `stop` - stops a container
15+
16+
Get a full list of available commands with
17+
[source, text]
18+
----
19+
docker
20+
----

chapters/docker-compose.adoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Docker Compose script is only downloadable for OSX and Linux.
2+
3+
TODO: What are the exact steps to get it running on Windows?
4+
5+
Multiple containers, as in <<JavaEE_Application_Docker_Cluster>> can be easily started using Docker Compose, or Compose for short.
6+
7+
If you have some additional time, you can take this part of the lab:
8+
9+
http://blog.arungupta.me/docker-compose-orchestrate-containers-techtip77/

chapters/docker-eclipse.adoc

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
The Docker tooling is aimed at providing at minimum the same basic level features as the command-line interface, but also provide some advantages by having access to a full fledged UI.
2+
3+
### Install Docker Tools Plugins
4+
5+
As this is still in early access stage, you will have to install it first:
6+
7+
. Download and Install https://devstudio.redhat.com/9.0/snapshots/builds/devstudio.product_master/latest/installer/[JBoss Developer Studio 9.0 Nightly], take defaults through out the installation.
8+
+
9+
Alternatively, download http://www.eclipse.org/downloads/index-developer-default.php[Eclipse Mars latest build] and configure JBoss Tools plugin from the update site http://download.jboss.org/jbosstools/updates/nightly/mars/.
10+
+
11+
. Open JBoss Developer Studio 9.0 Nightly
12+
. Add a new site using the menu items: ``Help'' > ``Install New Software...'' > ``Add...''. Specify the ``Name:'' as ``Docker Nightly'' and ``Location:'' as http://download.eclipse.org/linuxtools/updates-docker-nightly/.
13+
+
14+
.Add Docker Tooling To JBoss Developer Studio
15+
image::../images/jbds-docker-tools1.png[]
16+
+
17+
. Expand Linux Tools, select ``Docker Client'' and ``Docker Tooling''.
18+
+
19+
.Add Docker Tooling
20+
image::../images/jbds-docker-tools-nightly-setup.png[]
21+
+
22+
. Click on ``Next >'', ``Next >'', accept the terms of the license agreement, and click on ``Finish''. This will complete the installation of plugins.
23+
+
24+
Restart the IDE for the changes to take effect.
25+
26+
### Docker Explorer
27+
28+
The Docker Explorer provides a wizard to establish a new connection to a Docker daemon. This wizard can detect default settings if the user’s machine runs Docker natively (such as in Linux) or in a VM using Boot2Docker (such as in Mac or Windows). Both Unix sockets on Linux machines and the REST API on other OSes are detected and supported. The wizard also allows remote connections using custom settings.
29+
30+
. Use the menu ``Window'', ``Show View'', ``Other...''. Type ``docker'' to see the output as:
31+
+
32+
image::../images/jbds-docker-tools-docker-view.png[]
33+
+
34+
. Select ``Docker Explorer'' to open Docker Explorer.
35+
+
36+
image::../images/jbds-docker-tools-docker-explorer-view.png[]
37+
+
38+
. Click on the link in this window to create a connection to Docker Host. Specify the settings as shown:
39+
+
40+
.Docker Explorer
41+
image::../images/jbds-docker-tools2.png[]
42+
+
43+
Make sure to get IP address of the Docker Host as:
44+
+
45+
[source, text]
46+
----
47+
docker-machine ip lab
48+
----
49+
+
50+
Also, make sure to specify the correct directory for `.docker` on your machine.
51+
+
52+
. Click on ``Test Connection'' to check the connection. This should show the output as:
53+
+
54+
.Docker Explorer
55+
image::../images/jbds-docker-tools-test-connection-output.png[]
56+
+
57+
Click on ``OK'' and ``Finish'' to exit out of the wizard.
58+
+
59+
. Docker Explorer itself is a tree view that handles multiple connections and provides users with quick overview of the existing images and containers.
60+
+
61+
.Docker Explorer Tree View
62+
image::../images/jbds-docker-tools3.png[]
63+
+
64+
. Customize the view by clicking on the arrow in toolbar:
65+
+
66+
.Docker Explorer Customize View
67+
image::../images/jbds-docker-tools-customize-view-option.png[]
68+
+
69+
Built-in filters can show/hide intermediate and `dangling' images, as well as stopped containers.
70+
+
71+
.Docker Explorer Customize View Wizard
72+
image::../images/jbds-docker-tools-customize-view-wizard.png[]
73+
74+
### Docker Images
75+
76+
The Docker Images view lists all images in the Docker host selected in the Docker Explorer view. This view allows user to manage images, including:
77+
78+
. Pull/push images from/to the Docker Hub Registry (other registries will be supported as well, https://bugs.eclipse.org/bugs/show_bug.cgi?id=469306[#469306])
79+
. Build images from a Dockerfile
80+
. Create a container from an image
81+
82+
Lets take a look at it.
83+
84+
. Use the menu ``Window'', ``Show View'', ``Other...'', select ``Docker Images''. It shows the list of images on Docker Host:
85+
+
86+
.Docker Images View
87+
image::../images/jbds-docker-tools4.png[]
88+
+
89+
. Right-click on the image ending with ``wildfly:latest'' and click on the green arrow in the toolbar. This will show the following wizard:
90+
+
91+
.Docker Run Container Wizard
92+
image::../images/jbds-docker-tools-run-container-wizard.png[]
93+
+
94+
By default, all exports ports from the image are mapped to random ports on the host interface. This setting can be changed by unselecting the first checkbox and specify exact port mapping.
95+
+
96+
Click on ``Finish'' to start the container.
97+
+
98+
. When the container is started, all logs are streamed into Eclipse Console:
99+
+
100+
.Docker Container Logs
101+
image::../images/jbds-docker-tools5.png[]
102+
103+
### Docker Containers
104+
105+
Docker Containers view lets the user manage the containers. The view toolbar provides commands to start, stop, pause, unpause, display the logs and kill containers.
106+
107+
. Use the menu ``Window'', ``Show View'', ``Other...'', select ``Docker Containers''. It shows the list of running containers on Docker Host:
108+
+
109+
.Docker Containers View
110+
image::../images/jbds-docker-tools6.png[]
111+
+
112+
. Pause the container by clicking on the ``pause'' button in the toolbar (https://bugs.eclipse.org/bugs/show_bug.cgi?id=469310[#469310]). Show the complete list of containers by clicking on the ``View Menu'', ``Show all containers''.
113+
+
114+
.All Docker Containers
115+
image::../images/jbds-docker-tools-all-containers.png[]
116+
+
117+
. Select the paused container, and click on the green arrow in the toolbar to restart the container.
118+
. Right-click on any running container and select ``Display Log'' to view the log for this container.
119+
+
120+
.Eclipse Properties View
121+
image::../images/jbds-docker-tools-display-log.png[]
122+
123+
TODO: Users can also attach an Eclipse console to a running Docker container to follow the logs and use the STDIN to interact with it.
124+
125+
### Information and Inspect on Images and Containers
126+
127+
Eclipse Properties view is used to provide more information about the containers and images.
128+
129+
. Just open the Properties View and click on a Connection, Container, or Image in any of the Docker Explorer View, Docker Containers View, or Docker Images View. This will fill in data in the Properties view.
130+
+
131+
Info view is shown as:
132+
+
133+
.Docker Container Properties View Info
134+
image::../images/jbds-docker-tools-properties-info.png[]
135+
+
136+
Inspect view is shown as:
137+
+
138+
.Docker Container Properties View Inspect
139+
image::../images/jbds-docker-tools-properties-inspect.png[]

chapters/docker-intellij.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
http://blog.jetbrains.com/idea/2015/03/docker-support-in-intellij-idea-14-1/

chapters/docker-javaee7.adoc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
https://github.com/javaee-samples/javaee7-hol[Java EE 7 Hands-on Lab] has been delivered all around the world and is a pretty standard application that shows design patterns and anti-patterns for a typical Java EE 7 application.
2+
3+
.Java EE 7 Application Architecture
4+
image::../images/javaee7-hol.png[]
5+
6+
Pull the Docker image that contains WildFly and pre-built Java EE 7 application WAR file as shown:
7+
8+
[source, text]
9+
----
10+
docker pull <INSTRUCTOR_IP>:5000/javaee7-hol
11+
----
12+
13+
The javaee7-hol link:https://github.com/arun-gupta/docker-images/blob/master/javaee7-hol/Dockerfile[Dockerfile] is based on `jboss/wildfly` and adds the movieplex7 application as war file.
14+
15+
Run it as:
16+
17+
[source, text]
18+
----
19+
docker run -it -p 8080:8080 <INSTRUCTOR_IP>:5000/javaee7-hol
20+
----
21+
22+
See the application in action at http://dockerhost:8080/movieplex7/.
23+
24+
Only two changes are required to the standard `jboss/wildfly` image:
25+
26+
. Start WildFly in full platform:
27+
+
28+
[source, text]
29+
----
30+
CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-c", "standalone-full.xml", "-b", "0.0.0.0"]
31+
----
32+
+
33+
. WAR file is copied to `standalone/deployments` directory as:
34+
+
35+
[source, text]
36+
----
37+
RUN curl -L https://github.com/javaee-samples/javaee7-hol/blob/jrebel/solution/movieplex7-1.0-SNAPSHOT.war?raw=true -o /opt/jboss/wildfly/standalone/deployments/movieplex7-1.0-SNAPSHOT.war
38+
----

chapters/docker-machine.adoc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Machine makes it really easy to create Docker hosts on your computer, on cloud providers and inside your own data center. It creates servers, installs Docker on them, then configures the Docker client to talk to them.
2+
3+
Once your Docker host has been created, it then has a number of commands for managing them:
4+
5+
. Starting, stopping, restarting
6+
. Upgrading Docker
7+
. Configuring the Docker client to talk to your host
8+
9+
You used Docker Machine already during the attendee setup. We won't need it too much further on. But if you need to create hosts, it's a very handy tool to know about. From now on we're mostly going to use the docker client.
10+
11+
Find out more about the details at the link:https://docs.docker.com/machine/[Official Docker Machine Website]
12+
13+
Check if docker machine is working using the following command:
14+
15+
[source, text]
16+
----
17+
docker-machine -v
18+
----

chapters/docker-maven-plugin.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
http://blog.arungupta.me/javaee-docker-maven-plugin/

chapters/docker-netbeans.adoc

Whitespace-only changes.

0 commit comments

Comments
 (0)