Java Magazine, Jan/Feb 2016
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2016 72 containers The first article in this two part series explained the key concepts of Docker It explained the first steps for getting started with Docker using Toolbox how to build your first Docker image how to package a Java application as a Docker image and how to run the image as a container Finally a simple Java EE application was deployed on a WildFly application server This article explains how to deploy an application with multiple containers on multiple hosts Specifically I show how a Java EE application deployed on WildFly can perform CRUD operations using a database here Couchbase Finally I demonstrate Docker Compose for creating multicontainer applications and I explain Docker Swarm for creating multihost application environments Docker Compose Docker Compose is a tool for defining and running multicontainer Docker applications It is installed along with Docker Toolbox as explained in Part 1 of this series An application using Docker containers typically consists of multiple containers for example one for an application server another for a database possibly another for a messaging server and so on Each container typically starts with diferent configuration options such as port forwarding environment variables volume mapping and so on With Docker Compose there is no need to write shell scripts to start your containers All containers are defined in a YAML configuration file using services Each service consists Using Multiple Docker Containers Assemble a cluster of Docker containers and run a Java EE app without a lot of housekeeping ARUN GUPTA of one or more containers A Docker Compose script is used to start stop and restart the application plus all the services in that application and all the containers within each service This approach is often helpful when starting a single container inside a larger service because all the options can be specified beforehand in a file The command to start a Couchbase server that forwards port 8091 administration port port 8093 query port and some other ports in the container to similar ports on the host as well as map a Couchbase log directory in the container to a directory on the host would look like this docker run d v couchbase opt couchbase var p 8091 8091 p 8092 8092 p 8093 8093 p 11210 11210 couchbase server Enter the command above as a single line Ed Instead of remembering all the options for starting this container you can define this command in a Docker Compose file By default this file is named docker compose yml in the current directory The equivalent file for our command looks like this mycouchbase image couchbase server volumes couchbase opt couchbase var ports 8091 8091
You must have JavaScript enabled to view digital editions.