Introduction to Docker Compose


Bhaskar S 04/08/2017


Overview

In the article Introduction to Multi Docker Containers, we demonstrated how one could link 2 containers (business tier and data tier) to emulate a simple web application using the docker run command.

Is there a way to automate this process (in a repeatable way) of linking multiple Docker containers ???

Enter Docker Compose !!!

Docker Compose is a simple orchestration tool that helps in defining, building, starting, and linking multiple container(s) together to form the desired application stack.

The set of Docker container(s) (referred to as services in the Docker Compose parlance) that need to be started and linked together is defined in a docker-compose.yml file. Docker Compose uses this configuration file to compose the desired application stack.

Installation

The installation is on a Ubuntu 16.04 LTS based Linux desktop.

To install Docker Compose, execute the following commands:

$ sudo apt-get update

$ sudo apt-get install docker-compose

Execute the following command to check everything was ok:

$ docker-compose version

The following would be a typical output:

Output.1

docker-compose version 1.5.2, build unknown
docker-py version: 1.8.0
CPython version: 2.7.12
OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016

The above installation procedure installs Docker Compose from the official Ubuntu repository which is not be the latest.

To install the most current version of Docker Compose (1.11.2 at time of this writing), execute the following command:

$ sudo curl -o /usr/bin/docker-compose -L "https://github.com/docker/compose/releases/download/1.11.2/docker-compose-$(uname -s)-$(uname -m)"

Now, re-execute the following command to make sure everything is ok:

$ docker-compose version

The following would be a typical output:

Output.2

docker-compose version 1.11.2, build dfed245
docker-py version: 2.1.0
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.0.1t  3 May 2016

Setup

For this multi-container demonstration using Docker Compose, we will leverage this Setup. Please follow the steps before proceeding futher in this aritcle.

Basics

For a multi-container application stack, Docker Compose uses a YAML file called docker-compose.yml to define a set of services (Docker containers) that make up the application stack along with their runtime configuration options.

The following is the general format of the docker-compose.yml file:

docker-compose.yml
version: '2'

services:
    name-1:
        [configuration options]

    name-2:
        [configuration options]

    name-3:
        [configuration options]

    .
    .
    .

    name-n:
        [configuration options]

The following are some of the commonly used configuration options in a docker-compose.yml:

As indicated, the above docker-compose.yml configuration options are the most commonly used ones, so that one can get started - it not the complete exhaustive list of all the options.

Hands-on with Docker Compose

In this section, we will create the docker-compose.yml to link the multiple containers (data and business tier containers in our example) and demonstrate how to launch the corresponding application stack using Docker Compose.

For this multi-container demonstration, we will use the Docker image mysql_hellodb for the data tier and the Docker image tomcat_hellodb for the business tier.

Let us assume the current directory is /home/alice/hello.

Create the following docker-compose.yml file in the current directory:

docker-compose.yml
version: '2'

services:
    mysql:
        image: mysql_hellodb
        volumes:
            - "/home/alice/data:/var/lib/mysql"
        restart: always

    tomcat:
        depends_on:
            - mysql
        image: tomcat_hellodb
        links:
            - mysql:db
        ports:
            - "8080:8080"
        restart: always

To start our application stack (with the business tier and data tier) using the above docker-compose.yml, execute the following command:

$ docker-compose up

The following would be a typical output:

Output.3

Creating hello_mysql_1
Creating hello_tomcat_1
Attaching to hello_mysql_1, hello_tomcat_1
mysql_1   | Initializing database
mysql_1   | 2017-04-08T19:12:36.990983Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mysql_1   | 2017-04-08T19:12:38.499112Z 0 [Warning] InnoDB: New log files created, LSN=45790
tomcat_1  | 08-Apr-2017 19:12:38.509 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.5.13
tomcat_1  | 08-Apr-2017 19:12:38.511 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Mar 27 2017 14:25:04 UTC
tomcat_1  | 08-Apr-2017 19:12:38.511 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.5.13.0
tomcat_1  | 08-Apr-2017 19:12:38.511 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
tomcat_1  | 08-Apr-2017 19:12:38.511 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            4.4.0-53-generic
tomcat_1  | 08-Apr-2017 19:12:38.511 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
tomcat_1  | 08-Apr-2017 19:12:38.511 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /usr/lib/jvm/java-8-openjdk-amd64/jre
tomcat_1  | 08-Apr-2017 19:12:38.512 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_121-8u121-b13-1~bpo8+1-b13
tomcat_1  | 08-Apr-2017 19:12:38.512 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
tomcat_1  | 08-Apr-2017 19:12:38.512 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /usr/local/tomcat
tomcat_1  | 08-Apr-2017 19:12:38.512 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /usr/local/tomcat
tomcat_1  | 08-Apr-2017 19:12:38.512 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
tomcat_1  | 08-Apr-2017 19:12:38.512 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
tomcat_1  | 08-Apr-2017 19:12:38.512 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
tomcat_1  | 08-Apr-2017 19:12:38.513 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
tomcat_1  | 08-Apr-2017 19:12:38.513 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
tomcat_1  | 08-Apr-2017 19:12:38.513 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
tomcat_1  | 08-Apr-2017 19:12:38.513 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
tomcat_1  | 08-Apr-2017 19:12:38.513 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library 1.2.12 using APR version 1.5.1.
tomcat_1  | 08-Apr-2017 19:12:38.513 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
tomcat_1  | 08-Apr-2017 19:12:38.513 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
tomcat_1  | 08-Apr-2017 19:12:38.516 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized (OpenSSL 1.1.0e  16 Feb 2017)
tomcat_1  | 08-Apr-2017 19:12:38.581 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
tomcat_1  | 08-Apr-2017 19:12:38.593 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
tomcat_1  | 08-Apr-2017 19:12:38.595 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
tomcat_1  | 08-Apr-2017 19:12:38.596 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
tomcat_1  | 08-Apr-2017 19:12:38.597 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 415 ms
tomcat_1  | 08-Apr-2017 19:12:38.613 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
tomcat_1  | 08-Apr-2017 19:12:38.613 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.13
tomcat_1  | 08-Apr-2017 19:12:38.667 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive /usr/local/tomcat/webapps/helloworld3.war
mysql_1   | 2017-04-08T19:12:38.848315Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
tomcat_1  | 08-Apr-2017 19:12:39.004 WARNING [localhost-startStop-1] org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory.getObjectInstance Name = hellodb Property removeAbandoned is not used in DBCP2, use one or both of removeAbandonedOnBorrow or removeAbandonedOnMaintenance instead. Both have default value set to false. You have set value of "true" for "removeAbandoned" property, which is being ignored.
tomcat_1  | 08-Apr-2017 19:12:39.041 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
mysql_1   | 2017-04-08T19:12:39.079151Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 550b40bb-1c8f-11e7-902d-0242ac120002.
tomcat_1  | INFO  2017-04-08 19:12:39,107 [localhost-startStop-1] com.polarsparc.HelloServlet3  - Servlet  has been initialized
tomcat_1  |
tomcat_1  | 08-Apr-2017 19:12:39.114 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /usr/local/tomcat/webapps/helloworld3.war has finished in 446 ms
tomcat_1  | 08-Apr-2017 19:12:39.115 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/manager
mysql_1   | 2017-04-08T19:12:39.116833Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
mysql_1   | 2017-04-08T19:12:39.117243Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
tomcat_1  | 08-Apr-2017 19:12:39.139 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/manager has finished in 24 ms
tomcat_1  | 08-Apr-2017 19:12:39.139 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/examples
tomcat_1  | 08-Apr-2017 19:12:39.314 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/examples has finished in 175 ms
tomcat_1  | 08-Apr-2017 19:12:39.314 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/ROOT
tomcat_1  | 08-Apr-2017 19:12:39.327 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/ROOT has finished in 13 ms
tomcat_1  | 08-Apr-2017 19:12:39.327 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/docs
tomcat_1  | 08-Apr-2017 19:12:39.339 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/docs has finished in 12 ms
tomcat_1  | 08-Apr-2017 19:12:39.339 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/host-manager
tomcat_1  | 08-Apr-2017 19:12:39.353 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/host-manager has finished in 14 ms
tomcat_1  | 08-Apr-2017 19:12:39.356 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
tomcat_1  | 08-Apr-2017 19:12:39.362 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
tomcat_1  | 08-Apr-2017 19:12:39.364 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 767 ms
mysql_1   | 2017-04-08T19:12:50.131350Z 1 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:12:50.131446Z 1 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:12:50.131480Z 1 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:12:50.131508Z 1 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:12:50.131572Z 1 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1   | Database initialized
mysql_1   | Initializing certificates
mysql_1   | Generating a 2048 bit RSA private key
mysql_1   | ...............................................................................+++
mysql_1   | .....................+++
mysql_1   | unable to write 'random state'
mysql_1   | writing new private key to 'ca-key.pem'
mysql_1   | -----
mysql_1   | Generating a 2048 bit RSA private key
mysql_1   | ................................+++
mysql_1   | .......................................................+++
mysql_1   | unable to write 'random state'
mysql_1   | writing new private key to 'server-key.pem'
mysql_1   | -----
mysql_1   | Generating a 2048 bit RSA private key
mysql_1   | ..+++
mysql_1   | ........+++
mysql_1   | unable to write 'random state'
mysql_1   | writing new private key to 'client-key.pem'
mysql_1   | -----
mysql_1   | Certificates initialized
mysql_1   | MySQL init process in progress...
mysql_1   | 2017-04-08T19:12:56.845491Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mysql_1   | 2017-04-08T19:12:56.846476Z 0 [Note] mysqld (mysqld 5.7.17) starting as process 93 ...
mysql_1   | 2017-04-08T19:12:56.849613Z 0 [Note] InnoDB: PUNCH HOLE support available
mysql_1   | 2017-04-08T19:12:56.849636Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mysql_1   | 2017-04-08T19:12:56.849642Z 0 [Note] InnoDB: Uses event mutexes
mysql_1   | 2017-04-08T19:12:56.849646Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
mysql_1   | 2017-04-08T19:12:56.849654Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
mysql_1   | 2017-04-08T19:12:56.849660Z 0 [Note] InnoDB: Using Linux native AIO
mysql_1   | 2017-04-08T19:12:56.849911Z 0 [Note] InnoDB: Number of pools: 1
mysql_1   | 2017-04-08T19:12:56.850016Z 0 [Note] InnoDB: Using CPU crc32 instructions
mysql_1   | 2017-04-08T19:12:56.851415Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
mysql_1   | 2017-04-08T19:12:56.859718Z 0 [Note] InnoDB: Completed initialization of buffer pool
mysql_1   | 2017-04-08T19:12:56.861605Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
mysql_1   | 2017-04-08T19:12:56.873522Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
mysql_1   | 2017-04-08T19:12:56.953959Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
mysql_1   | 2017-04-08T19:12:56.954106Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
mysql_1   | 2017-04-08T19:12:57.454621Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
mysql_1   | 2017-04-08T19:12:57.455347Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
mysql_1   | 2017-04-08T19:12:57.455400Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
mysql_1   | 2017-04-08T19:12:57.456556Z 0 [Note] InnoDB: Waiting for purge to start
mysql_1   | 2017-04-08T19:12:57.506760Z 0 [Note] InnoDB: 5.7.17 started; log sequence number 2535854
mysql_1   | 2017-04-08T19:12:57.507200Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
mysql_1   | 2017-04-08T19:12:57.507282Z 0 [Note] Plugin 'FEDERATED' is disabled.
mysql_1   | 2017-04-08T19:12:57.512645Z 0 [Note] InnoDB: Buffer pool(s) load completed at 170408 19:12:57
mysql_1   | 2017-04-08T19:12:57.513865Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
mysql_1   | 2017-04-08T19:12:57.514017Z 0 [Warning] CA certificate ca.pem is self signed.
mysql_1   | 2017-04-08T19:12:57.556639Z 0 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:12:57.556709Z 0 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:12:57.556745Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:12:57.556776Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:12:57.559568Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:12:57.566006Z 0 [Note] Event Scheduler: Loaded 0 events
mysql_1   | 2017-04-08T19:12:57.566173Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a list of tables using the deprecated partition engine. You may use the startup option '--disable-partition-engine-check' to skip this check.
mysql_1   | 2017-04-08T19:12:57.566181Z 0 [Note] Beginning of list of non-natively partitioned tables
mysql_1   | 2017-04-08T19:12:57.589011Z 0 [Note] End of list of non-natively partitioned tables
mysql_1   | 2017-04-08T19:12:57.589226Z 0 [Note] mysqld: ready for connections.
mysql_1   | Version: '5.7.17'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server (GPL)
mysql_1   | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
mysql_1   | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
mysql_1   | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
mysql_1   | 2017-04-08T19:13:03.271270Z 5 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:13:03.271312Z 5 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:13:03.271427Z 5 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:13:03.271458Z 5 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:13:03.271525Z 5 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1   | mysql: [Warning] Using a password on the command line interface can be insecure.
mysql_1   | mysql: [Warning] Using a password on the command line interface can be insecure.
mysql_1   | mysql: [Warning] Using a password on the command line interface can be insecure.
mysql_1   | mysql: [Warning] Using a password on the command line interface can be insecure.
mysql_1   | 2017-04-08T19:13:03.305382Z 9 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:13:03.305413Z 9 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:13:03.305454Z 9 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:13:03.305476Z 9 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:13:03.305678Z 9 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1   |
mysql_1   | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/mysql-setup.sql
mysql_1   | mysql: [Warning] Using a password on the command line interface can be insecure.
mysql_1   |
mysql_1   |
mysql_1   | 2017-04-08T19:13:03.690096Z 0 [Note] Giving 0 client threads a chance to die gracefully
mysql_1   | 2017-04-08T19:13:03.690121Z 0 [Note] Shutting down slave threads
mysql_1   | 2017-04-08T19:13:03.690134Z 0 [Note] Forcefully disconnecting 0 remaining clients
mysql_1   | 2017-04-08T19:13:03.690141Z 0 [Note] Event Scheduler: Purging the queue. 0 events
mysql_1   | 2017-04-08T19:13:03.690554Z 0 [Note] Binlog end
mysql_1   | 2017-04-08T19:13:03.693384Z 0 [Note] Shutting down plugin 'ngram'
mysql_1   | 2017-04-08T19:13:03.693407Z 0 [Note] Shutting down plugin 'BLACKHOLE'
mysql_1   | 2017-04-08T19:13:03.693416Z 0 [Note] Shutting down plugin 'partition'
mysql_1   | 2017-04-08T19:13:03.693423Z 0 [Note] Shutting down plugin 'ARCHIVE'
mysql_1   | 2017-04-08T19:13:03.693430Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
mysql_1   | 2017-04-08T19:13:03.693436Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
mysql_1   | 2017-04-08T19:13:03.693448Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
mysql_1   | 2017-04-08T19:13:03.693453Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
mysql_1   | 2017-04-08T19:13:03.693458Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
mysql_1   | 2017-04-08T19:13:03.693464Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
mysql_1   | 2017-04-08T19:13:03.693469Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
mysql_1   | 2017-04-08T19:13:03.693475Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
mysql_1   | 2017-04-08T19:13:03.693485Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
mysql_1   | 2017-04-08T19:13:03.693494Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
mysql_1   | 2017-04-08T19:13:03.693500Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
mysql_1   | 2017-04-08T19:13:03.693504Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
mysql_1   | 2017-04-08T19:13:03.693516Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
mysql_1   | 2017-04-08T19:13:03.693521Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
mysql_1   | 2017-04-08T19:13:03.693526Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
mysql_1   | 2017-04-08T19:13:03.693539Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
mysql_1   | 2017-04-08T19:13:03.693544Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
mysql_1   | 2017-04-08T19:13:03.693549Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
mysql_1   | 2017-04-08T19:13:03.693561Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
mysql_1   | 2017-04-08T19:13:03.693566Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
mysql_1   | 2017-04-08T19:13:03.693571Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
mysql_1   | 2017-04-08T19:13:03.693582Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
mysql_1   | 2017-04-08T19:13:03.693591Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
mysql_1   | 2017-04-08T19:13:03.693596Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
mysql_1   | 2017-04-08T19:13:03.693601Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
mysql_1   | 2017-04-08T19:13:03.693612Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
mysql_1   | 2017-04-08T19:13:03.693617Z 0 [Note] Shutting down plugin 'INNODB_CMP'
mysql_1   | 2017-04-08T19:13:03.693622Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
mysql_1   | 2017-04-08T19:13:03.693627Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
mysql_1   | 2017-04-08T19:13:03.693632Z 0 [Note] Shutting down plugin 'INNODB_TRX'
mysql_1   | 2017-04-08T19:13:03.693637Z 0 [Note] Shutting down plugin 'InnoDB'
mysql_1   | 2017-04-08T19:13:03.693723Z 0 [Note] InnoDB: FTS optimize thread exiting.
mysql_1   | 2017-04-08T19:13:03.693861Z 0 [Note] InnoDB: Starting shutdown...
mysql_1   | 2017-04-08T19:13:03.794185Z 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
mysql_1   | 2017-04-08T19:13:03.794662Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 170408 19:13:03
mysql_1   | 2017-04-08T19:13:05.876853Z 0 [Note] InnoDB: Shutdown completed; log sequence number 12137130
mysql_1   | 2017-04-08T19:13:05.878741Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
mysql_1   | 2017-04-08T19:13:05.878755Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
mysql_1   | 2017-04-08T19:13:05.878759Z 0 [Note] Shutting down plugin 'MyISAM'
mysql_1   | 2017-04-08T19:13:05.878766Z 0 [Note] Shutting down plugin 'CSV'
mysql_1   | 2017-04-08T19:13:05.878769Z 0 [Note] Shutting down plugin 'MEMORY'
mysql_1   | 2017-04-08T19:13:05.878772Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
mysql_1   | 2017-04-08T19:13:05.878806Z 0 [Note] Shutting down plugin 'sha256_password'
mysql_1   | 2017-04-08T19:13:05.878812Z 0 [Note] Shutting down plugin 'mysql_native_password'
mysql_1   | 2017-04-08T19:13:05.878945Z 0 [Note] Shutting down plugin 'binlog'
mysql_1   | 2017-04-08T19:13:05.879324Z 0 [Note] mysqld: Shutdown complete
mysql_1   |
mysql_1   |
mysql_1   | MySQL init process done. Ready for start up.
mysql_1   |
mysql_1   | 2017-04-08T19:13:06.092003Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mysql_1   | 2017-04-08T19:13:06.093344Z 0 [Note] mysqld (mysqld 5.7.17) starting as process 1 ...
mysql_1   | 2017-04-08T19:13:06.096367Z 0 [Note] InnoDB: PUNCH HOLE support available
mysql_1   | 2017-04-08T19:13:06.096384Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mysql_1   | 2017-04-08T19:13:06.096388Z 0 [Note] InnoDB: Uses event mutexes
mysql_1   | 2017-04-08T19:13:06.096392Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
mysql_1   | 2017-04-08T19:13:06.096395Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
mysql_1   | 2017-04-08T19:13:06.096401Z 0 [Note] InnoDB: Using Linux native AIO
mysql_1   | 2017-04-08T19:13:06.096647Z 0 [Note] InnoDB: Number of pools: 1
mysql_1   | 2017-04-08T19:13:06.096754Z 0 [Note] InnoDB: Using CPU crc32 instructions
mysql_1   | 2017-04-08T19:13:06.098130Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
mysql_1   | 2017-04-08T19:13:06.106920Z 0 [Note] InnoDB: Completed initialization of buffer pool
mysql_1   | 2017-04-08T19:13:06.108924Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
mysql_1   | 2017-04-08T19:13:06.121230Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
mysql_1   | 2017-04-08T19:13:06.177630Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
mysql_1   | 2017-04-08T19:13:06.177681Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
mysql_1   | 2017-04-08T19:13:06.318428Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
mysql_1   | 2017-04-08T19:13:06.319325Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
mysql_1   | 2017-04-08T19:13:06.319333Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
mysql_1   | 2017-04-08T19:13:06.319983Z 0 [Note] InnoDB: Waiting for purge to start
mysql_1   | 2017-04-08T19:13:06.370150Z 0 [Note] InnoDB: 5.7.17 started; log sequence number 12137130
mysql_1   | 2017-04-08T19:13:06.370709Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
mysql_1   | 2017-04-08T19:13:06.370902Z 0 [Note] Plugin 'FEDERATED' is disabled.
mysql_1   | 2017-04-08T19:13:06.379417Z 0 [Note] InnoDB: Buffer pool(s) load completed at 170408 19:13:06
mysql_1   | 2017-04-08T19:13:06.379831Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
mysql_1   | 2017-04-08T19:13:06.379987Z 0 [Warning] CA certificate ca.pem is self signed.
mysql_1   | 2017-04-08T19:13:06.381505Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
mysql_1   | 2017-04-08T19:13:06.381538Z 0 [Note] IPv6 is available.
mysql_1   | 2017-04-08T19:13:06.381546Z 0 [Note]   - '::' resolves to '::';
mysql_1   | 2017-04-08T19:13:06.381592Z 0 [Note] Server socket created on IP: '::'.
mysql_1   | 2017-04-08T19:13:06.423723Z 0 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:13:06.423773Z 0 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:13:06.423830Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:13:06.423858Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:13:06.427878Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:13:06.432194Z 0 [Note] Event Scheduler: Loaded 0 events
mysql_1   | 2017-04-08T19:13:06.432359Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a list of tables using the deprecated partition engine. You may use the startup option '--disable-partition-engine-check' to skip this check.
mysql_1   | 2017-04-08T19:13:06.432365Z 0 [Note] Beginning of list of non-natively partitioned tables
mysql_1   | 2017-04-08T19:13:06.448394Z 0 [Note] End of list of non-natively partitioned tables
mysql_1   | 2017-04-08T19:13:06.448499Z 0 [Note] mysqld: ready for connections.
mysql_1   | Version: '5.7.17'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)

Notice Docker Compose merge the output logs from all the service containers.

To list all the running service containers, execute the following command:

$ docker-compose ps

The following would be a typical output:

Output.4

        Name               Command             State           Ports
-----------------------------------------------------------------------------------
hello_mysql_1    docker-entrypoint.sh mysqld   Up      3306/tcp
hello_tomcat_1   catalina.sh run               Up      0.0.0.0:8080->8080/tcp

Open a browser on the local host and access the URL http://localhost:8080/helloworld3/message. The following would be a typical view:

Docker Tomcat 2
Figure-1

YIPPEE !!! we have successfully demonstrated launching an application stack with multiple Docker containers using the simple orchestration tool Docker Compose.

To stop the business tier and data tier service containers, execute the following command:

$ docker-compose stop

The following would be a typical output:

Output.5

Stopping hello_tomcat_1 ... done
Stopping hello_mysql_1 ... done

To list all the running service containers (none should be running at this point), execute the following command:

$ docker-compose ps

The following would be a typical output:

Output.6

Name   Command   State   Ports
------------------------------

To re-start the business tier and data tier service containers in the background, execute the following command:

$ docker-compose up -d

The following would be a typical output:

Output.7

Creating hello_mysql_1
Creating hello_tomcat_1

To view the combined logs of the service containers running in the background, execute the following command:

$ docker-compose logs

The following would be a typical output:

Output.8

Attaching to hello_tomcat_1, hello_mysql_1
mysql_1   | 2017-04-08T19:44:18.586103Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mysql_1   | 2017-04-08T19:44:18.587492Z 0 [Note] mysqld (mysqld 5.7.17) starting as process 1 ...
mysql_1   | 2017-04-08T19:44:18.590585Z 0 [Note] InnoDB: PUNCH HOLE support available
mysql_1   | 2017-04-08T19:44:18.590612Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mysql_1   | 2017-04-08T19:44:18.590615Z 0 [Note] InnoDB: Uses event mutexes
mysql_1   | 2017-04-08T19:44:18.590619Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
mysql_1   | 2017-04-08T19:44:18.590622Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
mysql_1   | 2017-04-08T19:44:18.590625Z 0 [Note] InnoDB: Using Linux native AIO
mysql_1   | 2017-04-08T19:44:18.590876Z 0 [Note] InnoDB: Number of pools: 1
mysql_1   | 2017-04-08T19:44:18.590970Z 0 [Note] InnoDB: Using CPU crc32 instructions
mysql_1   | 2017-04-08T19:44:18.592462Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
mysql_1   | 2017-04-08T19:44:18.602399Z 0 [Note] InnoDB: Completed initialization of buffer pool
mysql_1   | 2017-04-08T19:44:18.604684Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
mysql_1   | 2017-04-08T19:44:18.616845Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
tomcat_1  | 08-Apr-2017 19:44:19.831 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.5.13
mysql_1   | 2017-04-08T19:44:18.671676Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
tomcat_1  | 08-Apr-2017 19:44:19.833 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Mar 27 2017 14:25:04 UTC
mysql_1   | 2017-04-08T19:44:18.671741Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
tomcat_1  | 08-Apr-2017 19:44:19.833 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.5.13.0
mysql_1   | 2017-04-08T19:44:18.804051Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
tomcat_1  | 08-Apr-2017 19:44:19.833 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
mysql_1   | 2017-04-08T19:44:18.805811Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
tomcat_1  | 08-Apr-2017 19:44:19.833 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            4.4.0-53-generic
mysql_1   | 2017-04-08T19:44:18.805829Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
tomcat_1  | 08-Apr-2017 19:44:19.833 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
mysql_1   | 2017-04-08T19:44:18.806826Z 0 [Note] InnoDB: 5.7.17 started; log sequence number 12139149
tomcat_1  | 08-Apr-2017 19:44:19.833 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /usr/lib/jvm/java-8-openjdk-amd64/jre
mysql_1   | 2017-04-08T19:44:18.807437Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
tomcat_1  | 08-Apr-2017 19:44:19.834 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_121-8u121-b13-1~bpo8+1-b13
mysql_1   | 2017-04-08T19:44:18.807630Z 0 [Note] Plugin 'FEDERATED' is disabled.
tomcat_1  | 08-Apr-2017 19:44:19.834 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
mysql_1   | 2017-04-08T19:44:18.811271Z 0 [Note] InnoDB: Buffer pool(s) load completed at 170408 19:44:18
tomcat_1  | 08-Apr-2017 19:44:19.834 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /usr/local/tomcat
mysql_1   | 2017-04-08T19:44:18.816827Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
tomcat_1  | 08-Apr-2017 19:44:19.834 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /usr/local/tomcat
tomcat_1  | 08-Apr-2017 19:44:19.834 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
mysql_1   | 2017-04-08T19:44:18.817029Z 0 [Warning] CA certificate ca.pem is self signed.
tomcat_1  | 08-Apr-2017 19:44:19.834 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
mysql_1   | 2017-04-08T19:44:18.818676Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
tomcat_1  | 08-Apr-2017 19:44:19.834 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
mysql_1   | 2017-04-08T19:44:18.818702Z 0 [Note] IPv6 is available.
tomcat_1  | 08-Apr-2017 19:44:19.835 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
mysql_1   | 2017-04-08T19:44:18.818711Z 0 [Note]   - '::' resolves to '::';
tomcat_1  | 08-Apr-2017 19:44:19.835 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
mysql_1   | 2017-04-08T19:44:18.818731Z 0 [Note] Server socket created on IP: '::'.
tomcat_1  | 08-Apr-2017 19:44:19.835 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
mysql_1   | 2017-04-08T19:44:18.872396Z 0 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
tomcat_1  | 08-Apr-2017 19:44:19.835 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
mysql_1   | 2017-04-08T19:44:18.872438Z 0 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:44:18.872477Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:44:18.872498Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
mysql_1   | 2017-04-08T19:44:18.875986Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
tomcat_1  | 08-Apr-2017 19:44:19.835 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library 1.2.12 using APR version 1.5.1.
mysql_1   | 2017-04-08T19:44:18.884004Z 0 [Note] Event Scheduler: Loaded 0 events
tomcat_1  | 08-Apr-2017 19:44:19.835 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
mysql_1   | 2017-04-08T19:44:18.884113Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a list of tables using the deprecated partition engine. You may use the startup option '--disable-partition-engine-check' to skip this check.
tomcat_1  | 08-Apr-2017 19:44:19.835 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
mysql_1   | 2017-04-08T19:44:18.884119Z 0 [Note] Beginning of list of non-natively partitioned tables
tomcat_1  | 08-Apr-2017 19:44:19.838 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized (OpenSSL 1.1.0e  16 Feb 2017)
mysql_1   | 2017-04-08T19:44:18.898765Z 0 [Note] End of list of non-natively partitioned tables
tomcat_1  | 08-Apr-2017 19:44:19.900 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
mysql_1   | 2017-04-08T19:44:18.898956Z 0 [Note] mysqld: ready for connections.
tomcat_1  | 08-Apr-2017 19:44:19.913 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
mysql_1   | Version: '5.7.17'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
tomcat_1  | 08-Apr-2017 19:44:19.915 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
tomcat_1  | 08-Apr-2017 19:44:19.916 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
tomcat_1  | 08-Apr-2017 19:44:19.917 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 387 ms
tomcat_1  | 08-Apr-2017 19:44:19.933 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
tomcat_1  | 08-Apr-2017 19:44:19.933 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.13
tomcat_1  | 08-Apr-2017 19:44:19.979 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive /usr/local/tomcat/webapps/helloworld3.war
tomcat_1  | 08-Apr-2017 19:44:20.299 WARNING [localhost-startStop-1] org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory.getObjectInstance Name = hellodb Property removeAbandoned is not used in DBCP2, use one or both of removeAbandonedOnBorrow or removeAbandonedOnMaintenance instead. Both have default value set to false. You have set value of "true" for "removeAbandoned" property, which is being ignored.
tomcat_1  | 08-Apr-2017 19:44:20.336 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
tomcat_1  | INFO  2017-04-08 19:44:20,402 [localhost-startStop-1] com.polarsparc.HelloServlet3  - Servlet  has been initialized
tomcat_1  |
tomcat_1  | 08-Apr-2017 19:44:20.409 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /usr/local/tomcat/webapps/helloworld3.war has finished in 429 ms
tomcat_1  | 08-Apr-2017 19:44:20.409 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/manager
tomcat_1  | 08-Apr-2017 19:44:20.433 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/manager has finished in 24 ms
tomcat_1  | 08-Apr-2017 19:44:20.433 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/examples
tomcat_1  | 08-Apr-2017 19:44:20.606 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/examples has finished in 173 ms
tomcat_1  | 08-Apr-2017 19:44:20.607 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/ROOT
tomcat_1  | 08-Apr-2017 19:44:20.625 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/ROOT has finished in 18 ms
tomcat_1  | 08-Apr-2017 19:44:20.625 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/docs
tomcat_1  | 08-Apr-2017 19:44:20.637 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/docs has finished in 12 ms
tomcat_1  | 08-Apr-2017 19:44:20.637 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/host-manager
tomcat_1  | 08-Apr-2017 19:44:20.652 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/host-manager has finished in 15 ms
tomcat_1  | 08-Apr-2017 19:44:20.654 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
tomcat_1  | 08-Apr-2017 19:44:20.660 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
tomcat_1  | 08-Apr-2017 19:44:20.663 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 746 ms

Once again, open a browser on the local host and access the URL http://localhost:8080/helloworld3/message. The following would be a typical view:

Docker Tomcat 3
Figure-2

As is evident from the logs in Output.8 above as well as the browser view in Figure.2 above, the database is preserved (due to the volumes option) and we see the next count compared to the browser view in Figure.1.

References

Introduction to Docker

Introduction to Dockerfile

Introduction to Multi Docker Containers

Official Docker Documentation