Skip to content

Commit a688741

Browse files
committed
completing docker compose chapter
1 parent c57b216 commit a688741

4 files changed

Lines changed: 166 additions & 5 deletions

File tree

attendees/docker-compose.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
mysqldb:
2+
image: mysql
3+
environment:
4+
MYSQL_DATABASE: sample
5+
MYSQL_USER: mysql
6+
MYSQL_PASSWORD: mysql
7+
MYSQL_ROOT_PASSWORD: supersecret
8+
mywildfly:
9+
image: arungupta/wildfly-mysql-javaee7
10+
links:
11+
- mysqldb:db
12+

chapters/docker-compose.adoc

Lines changed: 148 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,155 @@
33
[quote, github.com/docker/compose]
44
Docker Compose is a tool for defining and running complex applications with Docker. With Compose, you define a multi-container application in a single file, then spin your application up in a single command which does everything that needs to be done to get it running.
55

6-
Docker Compose script is only downloadable for OSX and Linux.
6+
An application using Docker containers will typically consist of multiple containers. With Docker Compose, there is no need to write shell scripts to start your containers. All the containers are defined in a configuration file using _services_, and then `docker-compose` script is used to start, stop, and restart the application and all the services in that application, and all the containers within that service. The complete list of commands is:
77

8-
TODO: What are the exact steps to get it running on Windows?
8+
[options="header"]
9+
|====
10+
| Command | Purpose
11+
| `build` | Build or rebuild services
12+
| `help` | Get help on a command
13+
| `kill` | Kill containers
14+
| `logs` | View output from containers
15+
| `port` | Print the public port for a port binding
16+
| `ps` | List containers
17+
| `pull` | Pulls service images
18+
| `restart` | Restart services
19+
| `rm` | Remove stopped containers
20+
| `run` | Run a one-off command
21+
| `scale` | Set number of containers for a service
22+
| `start` | Start services
23+
| `stop` | Stop services
24+
| `up` | Create and start containers
25+
| `migrate-to-labels Recreate containers to add labels
26+
|====
927

10-
Multiple containers, as in <<JavaEE_Application_Docker_Cluster>> can be easily started using Docker Compose, or Compose for short.
28+
Docker Compose script is only available for OSX and Linux. https://github.com/arun-gupta/docker-java/issues/3 is used for tracking Docker Compose on Windows.
1129

12-
If you have some additional time, you can take this part of the lab:
30+
### Configuration File
31+
32+
. Entry point to Compose is `docker-compose.yml`. Lets use the following file:
33+
+
34+
[source, yml]
35+
----
36+
mysqldb:
37+
image: dockerhost:5000/mysql
38+
environment:
39+
MYSQL_DATABASE: sample
40+
MYSQL_USER: mysql
41+
MYSQL_PASSWORD: mysql
42+
MYSQL_ROOT_PASSWORD: supersecret
43+
mywildfly:
44+
image: dockerhost:5000/arungupta/wildfly-mysql-javaee7
45+
links:
46+
- mysqldb:db
47+
ports:
48+
- 8080:8080
49+
----
50+
+
51+
This file is available in link:../attendees/docker-compose.yml[] and shows:
52+
+
53+
.. Two services are defined by the name `mysqldb` and `mywildfly`
54+
.. Image name for each service is defined using `image`
55+
.. Environment variables for the MySQL container are defined in `environment`
56+
.. MySQL container is linked with WildFly container using `links`
57+
.. Port forwarding is achieved using `ports`
58+
59+
### Start Services
60+
61+
. All the services can be started, in detached mode, by giving the command:
62+
+
63+
docker-compose up -d
64+
+
65+
And this shows the output as:
66+
+
67+
Creating attendees_mysqldb_1...
68+
Creating attendees_mywildfly_1...
69+
+
70+
An alternate compose file name can be specified using `-f`.
71+
+
72+
An alternate directory where the compose file exists can be specified using `-p`.
73+
+
74+
. Started services can be verified as:
75+
+
76+
[source, text]
77+
----
78+
> docker-compose ps
79+
Name Command State Ports
80+
-------------------------------------------------------------------------------------------------
81+
attendees_mysqldb_1 /entrypoint.sh mysqld Up 3306/tcp
82+
attendees_mywildfly_1 /opt/jboss/wildfly/customi ... Up 0.0.0.0:8080->8080/tcp, 9990/tcp
83+
----
84+
+
85+
This provides a consolidated view of all the services started, and containers within them.
86+
+
87+
Alternatively, the containers in this application, and any additional containers running on this Docker host can be verified by using the usual `docker ps` command:
88+
+
89+
[source, text]
90+
----
91+
> docker ps
92+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
93+
3598e545bd2f arungupta/wildfly-mysql-javaee7:latest "/opt/jboss/wildfly/ 59 seconds ago Up 58 seconds 0.0.0.0:8080->8080/tcp, 9990/tcp attendees_mywildfly_1
94+
b8cf6a3d518b mysql:latest "/entrypoint.sh mysq 2 minutes ago Up 2 minutes 3306/tcp attendees_mysqldb_1
95+
----
96+
+
97+
. Service logs can be seen as:
98+
+
99+
[source, text]
100+
----
101+
> docker-compose logs
102+
Attaching to attendees_mywildfly_1, attendees_mysqldb_1
103+
mywildfly_1 | => Starting WildFly server
104+
mywildfly_1 | => Waiting for the server to boot
105+
mywildfly_1 | =========================================================================
106+
mywildfly_1 |
107+
mywildfly_1 | JBoss Bootstrap Environment
108+
mywildfly_1 |
109+
mywildfly_1 | JBOSS_HOME: /opt/jboss/wildfly
110+
mywildfly_1 |
111+
mywildfly_1 | JAVA: /usr/lib/jvm/java/bin/java
112+
mywildfly_1 |
113+
mywildfly_1 | JAVA_OPTS: -server -Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true
114+
mywildfly_1 |
115+
116+
. . .
117+
118+
mywildfly_1 | 15:40:20,866 INFO [org.jboss.resteasy.spi.ResteasyDeployment] (MSC service thread 1-2) Deploying javax.ws.rs.core.Application: class org.javaee7.samples.employees.MyApplication
119+
mywildfly_1 | 15:40:20,914 INFO [org.wildfly.extension.undertow] (MSC service thread 1-2) JBAS017534: Registered web context: /employees
120+
mywildfly_1 | 15:40:21,032 INFO [org.jboss.as.server] (ServerService Thread Pool -- 28) JBAS018559: Deployed "employees.war" (runtime-name : "employees.war")
121+
mywildfly_1 | 15:40:21,077 INFO [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management
122+
mywildfly_1 | 15:40:21,077 INFO [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
123+
mywildfly_1 | 15:40:21,077 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.2.0.Final "Tweek" started in 9572ms - Started 280 of 334 services (92 services are lazy, passive or on-demand)
124+
mysqldb_1 | Running mysql_install_db
125+
mysqldb_1 | 2015-06-05 15:38:31 0 [Note] /usr/sbin/mysqld (mysqld 5.6.25) starting as process 27 ...
126+
mysqldb_1 | 2015-06-05 15:38:31 27 [Note] InnoDB: Using atomics to ref count buffer pool pages
127+
128+
. . .
129+
130+
mysqldb_1 | 2015-06-05 15:38:40 1 [Note] Event Scheduler: Loaded 0 events
131+
mysqldb_1 | 2015-06-05 15:38:40 1 [Note] mysqld: ready for connections.
132+
mysqldb_1 | Version: '5.6.25' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
133+
mysqldb_1 | 2015-06-05 15:40:18 1 [Warning] IP address '172.17.0.24' could not be resolved: Name or service not known
134+
----
135+
136+
### Verify Application
137+
138+
. Access the application at http://dockerhost:8080/employees/resources/employees/. This is shown in the browser as:
139+
140+
.Output From Servers Run Using Docker Compose
141+
image::../images/docker-compose-output.png[]
142+
143+
### Stop Services
144+
145+
. Stop the services as:
146+
+
147+
[source, text]
148+
----
149+
> docker-compose stop
150+
Stopping attendees_mywildfly_1...
151+
Stopping attendees_mysqldb_1...
152+
----
153+
154+
### Scale Services
155+
156+
https://github.com/arun-gupta/docker-java/issues/51
13157

14-
http://blog.arungupta.me/docker-compose-orchestrate-containers-techtip77/

images/docker-compose-output.png

234 KB
Loading

instructor/push-images-to-registry.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@ docker push localhost:5000/javaee7-hol
3030
docker pull mysql:latest
3131
docker tag mysql localhost:5000/mysql
3232
docker push localhost:5000/mysql
33+
34+
# WildFly MySQL
35+
docker pull arungupta/wildfly-mysql-javaee7
36+
docker tag arungupta/wildfly-mysql-javaee7 localhost:5000/wildfly-mysql-javaee7
37+
docker push localhost:5000/wildfly-mysql-javaee7
38+

0 commit comments

Comments
 (0)