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: chapters/docker-basics.adoc
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -18,16 +18,16 @@ You can certainly provide an installation script that will download and install
18
18
19
19
Docker has three main components:
20
20
21
-
. __Images__ are *build component* of Docker and a read-only template of application operating system.
22
-
. __Containers__ are *run component* of Docker, and created from, images.Containers can be run, started, stopped, moved, and deleted.
23
-
. Images are stored, shared, and managed in a __registry__, the *distribution component* of Docker. The publically available registry is known as Docker Hub (available at http://hub.docker.com).
21
+
. __Images__ are the *build component* of Docker and are the read-only templates defining an application operating system.
22
+
. __Containers__ are the *run component* of Docker and created from images.Containers can be run, started, stopped, moved, and deleted.
23
+
. Images are stored, shared, and managed in a __registry__ and are the *distribution component* of Docker. Docker Hub is a publicly available registry and is available at http://hub.docker.com.
24
24
25
-
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.
25
+
In order for these three components to work together, the *Docker Daemon* runs on a host machine and does the heavy lifting of building, running, and distributing Docker containers. In addition, the *Client* is a Docker binary which accepts commands from the user and communicates back and forth with the Daemon.
26
26
27
27
.Docker architecture
28
28
image::docker-architecture.png[]
29
29
30
-
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.
30
+
The Client communicates with a Daemon that is either co-located on the same host or on a different host. Use the `pull` command on the Client to request the Daemon to pull an image from the registry. The Daemon then downloads the image from Docker Hub, or whichever registry is configured. Multiple images can be downloaded from the registry and installed on the Daemon host. To run an Image, use the `run` command on the Client to request the Daemon to create a container on-demand based on the image.
Copy file name to clipboardExpand all lines: chapters/docker-preface.adoc
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,6 @@ Containers are enabling developers to package their applications (and underlying
4
4
5
5
Docker is the developer-friendly Linux container technology that enables creation of your stack: OS, JVM, app server, app, and all your custom configuration. So with all it offers, how comfortable are you and your team taking Docker from development to production? Are you hearing developers say, “But it works on my machine!” when code breaks in production?
6
6
7
-
This lab offers developers an intro-level, hands-on session with Docker, from installation, to exploring Docker Hub, to crafting their own images, to adding Java apps and running custom containers. It will also explain how to use Swarm to orchesorchestrate these containers together. This is a BYOL (bring your own laptop) session, so bring your Windows, OSX, or Linux laptop and be ready to dig into a tool that promises to be at the forefront of our industry for some time to come.
7
+
This lab offers developers an intro-level, hands-on session with Docker, from installation, to exploring Docker Hub, to crafting their own images, to adding Java apps and running custom containers. It will also explain how to use Swarm to orchestrate these containers together. This is a BYOL (bring your own laptop) session, so bring your Windows, OSX, or Linux laptop and be ready to dig into a tool that promises to be at the forefront of our industry for some time to come.
8
8
9
9
NOTE: Latest content of this workshop is always at https://github.com/javaee-samples/docker-java
Detailed explanation for this is available in <<Docker_Swarm>>.
58
-
59
40
#### Create Docker Host Mapping
60
41
61
42
. To make it easier to start/stop the containers, an entry is added into the host mapping table of your operating system. Find out the IP address of your machine:
Copy file name to clipboardExpand all lines: chapters/docker-swarm.adoc
+35-30Lines changed: 35 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,26 @@
1
1
[[Docker_Swarm]]
2
2
## Deploy Application on Docker Swarm Cluster
3
3
4
-
Docker Swarm is native clustering for Docker. It allows you create and access to a pool of Docker hosts using the full suite of Docker tools. Because Docker Swarm serves the standard Docker API, any tool that already communicates with a Docker daemon can use Swarm to transparently scale to multiple hosts.
4
+
Docker Swarm is native clustering for Docker. It allows you to create and access a pool of Docker hosts using the full suite of Docker tools. Because Docker Swarm serves the standard Docker API, any tool that already communicates with a Docker daemon can use Swarm to transparently scale to multiple hosts.
5
5
6
6
### Key Components of Docker Swarm
7
7
8
8
.Key Components of Docker Swarm
9
9
image::docker-swarm-components.png[]
10
10
11
-
*Swarm Manager*: Docker Swarm has a Manager, that is a pre-defined Docker Host, and is a single point for all administration. Swarm manager orchestrates and schedules containers on the entire cluster. Swarm Manager can be configured in https://docs.docker.com/swarm/multi-manager-setup/[High Availability].
11
+
*Swarm Manager*: Docker Swarm has a Manager that is a pre-defined Docker Host and is a single point for all administration. Swarm manager orchestrates and schedules containers in the entire cluster. Swarm Manager can be configured to enable https://docs.docker.com/swarm/multi-manager-setup/[High Availability].
12
12
13
13
*Swarm Nodes*: The containers are deployed on Nodes that are additional Docker Hosts. Each Swarm Node must be accessible by the manager, each node must listen to the same network interface (TCP port). Each node runs a Docker Swarm agent that registers the referenced Docker daemon, monitors it, and updates the discovery backend with the node’s status. The containers run on a node.
14
14
15
15
*Scheduler Strategy*: Different scheduler strategies ("`binpack`", "`spread`" (default), and "`random`") can be applied to pick the best node to run your container. The default strategy optimizes the node for least number of running containers. There are multiple kinds of filters, such as constraints and affinity. This should allow for a decent scheduling algorithm.
16
16
17
-
*Node Discovery Service*: Swarm manager talks to a hosted discovery service. This service maintains a list of IPs in Swarm cluster. Docker Hub hosts a discovery service that can be used during development. In production, this is replaced by other services such as `etcd`, `consul`, or `zookeeper`. You can even use a static file. This is particularly useful if there is no access to Internet, or you are running the setup in a closed network.
17
+
*Node Discovery Service*: Swarm manager talks to a hosted discovery service. This service maintains a list of IPs in the Swarm cluster. Docker Hub hosts a discovery service that can be used during development. In production, this is replaced by other services such as `etcd`, `consul`, or `zookeeper`. You can even use a static file. This is particularly useful if there is no Internet access or you are running in a closed network.
18
18
19
-
**Standard Docker API:** Docker Swarm serves the standard Docker API and thus any tool that talks to a single Docker host will seamlessly scale to multiple hosts now. That means that if you were using shell scripts using Docker CLI to configure multiple Docker hosts, the same CLI would can now talk to Swarm cluster.
19
+
*Standard Docker API*: Docker Swarm serves the standard Docker API and thus any tool that talks to a single Docker host will seamlessly scale to multiple hosts now. That means that if you were using shell scripts using Docker CLI to configure multiple Docker hosts, the same CLI could now talk to the Swarm cluster.
20
20
21
21
There are a lots of other concepts but these are the main ones.
22
22
23
-
This section will deploy an application that will provide a CRUD/REST interface on a data bucket in Couchbase. This is achieved by using a Java EE application deployed on WildFly and accessing the database.
23
+
This section will deploy an application that will provide a CRUD/REST interface on a data bucket in Couchbase. This is achieved by using a Java EE application deployed on WildFly to access the database.
. Connect to the Swarm cluster by using the command:
144
144
+
145
145
eval "$(docker-machine env --swarm swarm-master)"
146
146
+
147
-
NOTE: If you're on Windows, use the `docker-machine env swarm-master` command only and copy the output into an editor to replace all appearances of EXPORT with SET and issue the three commands at your command prompt, remove the quotes and all duplicate appearences of "/".
147
+
NOTE: `--swarm` is specified to connect to the Swarm cluster. Otherwise the command will connect to `swarm-master` Machine only. However, if you're on Windows, then use the `docker-machine env swarm-master` command only. Then copy the output into an editor to replace all appearances of EXPORT with SET, remove the quotes, and all appearances of "/" with "\". Finally, issue the three commands at your command prompt.
148
148
+
149
-
. Find some information about the cluster:
149
+
. Get information about the cluster:
150
150
+
151
151
[source, text]
152
152
----
@@ -169,7 +169,7 @@ Name: d074fd97682e
169
169
+
170
170
This cluster has one node and that node has two containers.
171
171
+
172
-
. Create a new Machine to join this cluster:
172
+
. Create the first Swarm node to join this cluster:
The machines that are part of the cluster have cluster’s name in the SWARM column, blank otherwise. For example, `consul-machine` is a standalone machine where as all other machines are part of the `swarm-master` cluster. The Swarm master is also identified by (master) in the SWARM column.
222
+
The machines that are part of the cluster have cluster’s name in the SWARM column. If the SWARM column is blank, then it is a standalone machine. For example, `consul-machine` is a standalone machine as opposed to all other machines which are part of the `swarm-master` cluster. The Swarm master is identified by (master) in the SWARM column.
223
223
+
224
-
. Connect to the Swarm cluster and find some information about it:
225
-
226
-
eval "$(docker-machine env --swarm swarm-master)"
227
-
docker info
228
-
+
229
-
Note, `--swarm` is specified to connect to the Swarm cluster. Otherwise the command will connect to `swarm-master` Machine only.
230
-
+
231
-
This shows the output as:
224
+
. Get information about the cluster again:
232
225
+
233
226
[source, text]
234
227
----
@@ -259,9 +252,18 @@ Total Memory: 3.064 GiB
259
252
Name: d074fd97682e
260
253
----
261
254
+
262
-
There are 3 nodes – one Swarm master and 2 Swarm _worker_ nodes. There is a total of 4 containers running in this cluster – one Swarm agent on master and each node, and there is an additional swarm-agent-master running on the master. This can be verified by connecting to the master and listing all the containers.
255
+
Now there are 3 nodes – one Swarm master and 2 Swarm _worker_ nodes. There are a total of 4 containers running in this cluster – a swarm-agent on each node and an additional swarm-agent-master running on the master. This can be verified by connecting to the master Machine (without specifying `--swarm`) and listing all the containers:
256
+
+
257
+
[source, text]
258
+
----
259
+
eval "$(docker-machine env swarm-master)"
260
+
docker ps
261
+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
262
+
cf5edbf4ada7 swarm:latest "/swarm join --advert" 49 seconds ago Up 49 seconds 2375/tcp swarm-agent
263
+
c7c3b80bceb4 swarm:latest "/swarm manage --tlsv" 49 seconds ago Up 49 seconds 2375/tcp, 0.0.0.0:3376->3376/tcp swarm-agent-master
264
+
----
263
265
+
264
-
. List nodes in the cluster with the following command:
266
+
. You can also query the Consul discovery service while connected to the Swarm cluster, master, or any worker node in the cluster to list the nodes in the cluster:
265
267
+
266
268
[source, text]
267
269
----
@@ -273,8 +275,10 @@ docker run swarm list consul://$(docker-machine ip consul-machine):8500
273
275
274
276
### Start Application Environment Using Docker Compose
275
277
276
-
Make sure you are connected to the cluster by giving the command `eval "$(docker-machine env --swarm swarm-master)"`.
Docker create three networks for each host automatically:
299
+
Docker creates three networks for each host automatically:
296
300
+
297
301
[options="header", cols="1,3", width="80%"]
298
302
|====
@@ -302,7 +306,7 @@ Docker create three networks for each host automatically:
302
306
| `host` | Adds a container on hosts networking stack. Network configuration is identical to the host.
303
307
|====
304
308
+
305
-
This explains a total of nine networks, three for each node, as shown in this Swarm cluster.
309
+
A total of nine networks are created for this three-node Swarm cluster because three networks are created for each node.
306
310
+
307
311
. Use Compose file to start WildFly and Couchbase:
308
312
+
@@ -420,22 +424,23 @@ As seen, `wildflycouchbasejavaee7` overlay network exists on all Machines. This
420
424
+
421
425
Read more about https://docs.docker.com/engine/userguide/networking/dockernetworks/[Docker Networks].
422
426
+
423
-
. Verify that WildFly and Couchbase are running:
427
+
. Connect to the Swarm cluster and verify that WildFly and Couchbase are running:
424
428
+
425
429
[source, text]
426
430
----
431
+
eval "$(docker-machine env --swarm swarm-master)"
427
432
docker ps
428
433
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
429
434
23a581295a2b couchbase/server "/entrypoint.sh couch" 9 seconds ago Up 8 seconds 192.168.99.102:8091-8093->8091-8093/tcp, 11207/tcp, 11211/tcp, 192.168.99.102:11210->11210/tcp, 18091-18092/tcp swarm-master/db
430
435
7a8a885b23f3 arungupta/wildfly-admin "/opt/jboss/wildfly/b" 9 seconds ago Up 8 seconds 192.168.99.103:8080->8080/tcp, 192.168.99.103:9990->9990/tcp swarm-node-01/wildflycouchbasejavaee7_mywildfly_1
431
436
----
432
437
+
433
-
Note thatCouchbase server is running on `swarm-master` node and WildFly is running on `swarm-node-01`.
438
+
Note that, in this example, the Couchbase server is running on `swarm-master` node and WildFly is running on `swarm-node-01`. Take a note on which nodes your Couchbase and WildFly servers are running and update the following commands accordingly.
434
439
435
440
### Configure Couchbase server
436
441
437
442
. Clone https://github.com/arun-gupta/couchbase-javaee.git. This workspace contains a simple Java EE application that is deployed on WildFly and provides a REST API over `travel-sample` bucket in Couchbase.
438
-
. Couchbase server can be configured using http://developer.couchbase.com/documentation/server/4.0/rest-api/rest-endpoints-all.html[REST API]. The application contains a Maven profile that allows to configure Couchbase server with `travel-sample` bucket. This can be invoked as:
443
+
. Couchbase server can be configured using http://developer.couchbase.com/documentation/server/4.0/rest-api/rest-endpoints-all.html[REST API]. The application contains a Maven profile that allows to configure the Couchbase server with `travel-sample` bucket. This can be invoked as: (Note that you may need to replace `swarm-master` with the node in your cluster that is running Couchbase)
439
444
+
440
445
[source, text]
441
446
----
@@ -462,7 +467,7 @@ mvn install -Pcouchbase -Ddocker.host=$(docker-machine ip swarm-master)
462
467
463
468
Deploy the application to WildFly by specifying three parameters:
464
469
465
-
. Host IP address where WildFly is running
470
+
. Host IP address where WildFly is running (swarm-node-01 in this example but update as needed for your cluster)
466
471
. Username of a user in WildFly's administrative realm
467
472
. Password of the user specified in WildFly's administrative realm
468
473
@@ -488,7 +493,7 @@ INFO: JBoss Remoting version 4.0.9.Final
488
493
489
494
### Access Application
490
495
491
-
Now that WildFly and Couchbase server have started, lets access the application. You need to specify IP address of the Machine where WildFly is running:
496
+
Now that the WildFly and Couchbase servers have started, lets access the application. You need to specify the IP address of the Machine where WildFly is running (swarm-node-01 in this example but update as needed for your cluster):
492
497
493
498
[source, text]
494
499
----
@@ -498,4 +503,4 @@ curl http://$(docker-machine ip swarm-node-01):8080/couchbase-javaee/resources/a
498
503
499
504
Check state of the cluster by connecting to different nodes.
500
505
501
-
Add container visualiation using https://github.com/javaee-samples/docker-java/issues/55.
506
+
Add container visualization using https://github.com/javaee-samples/docker-java/issues/55.
0 commit comments