Java Magazine, Jan/Feb 2016
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2016 73 containers 8092 8092 8093 8093 11210 11210 This file has one service mycouchbase which uses the prebuilt image couchbase server defined by the image key Volume mapping is done using the volumes key and port forwarding is done using the ports key The key name values are analogous to their docker run counterpart as shown on the previous page The complete syntax for the Compose file is explained at the Docker site Now you can start the Couchbase database container by running the following command docker compose up d This command starts the service mycouchbase in the background because of the d switch and the Couchbase container in this service A list of common commands that can be used with Compose is shown in Table 1 You can display the complete list of commands using the command docker compose help Docker Compose becomes more relevant and interesting when multiple services need to be started for an application which is generally the case As an example if your application consists of one WildFly service and one Couchbase service then the Compose file would look like this mycouchbase container_ name db image couchbase server volumes couchbase opt couchbase var ports 8091 8091 8092 8092 8093 8093 11210 11210 mywildfly image arungupta wildfly admin environment COUCHBASE_ URI db ports 8080 8080 9990 9990 This application uses two services mycouchbase and mywildfly The mycouchbase service starts the Couchbase server It has an additional attribute container_ name that specifies a custom container name instead of a generated default name The mywildfly service starts the WildFly application server The default WildFly image exposes only port 8080 for the application to be accessed The custom image arungupta wildfly admin starts WildFly such that the management interface is bound to all network interfaces It also exposes port 9990 which can then be used for deploying applications In addition it also has an environment variable COUCHBASE_ URI that is then used in applications deployed on WildFly to access the database Ill provide more detail about this a little later when the application environment is started COMMAND PURPOSE up CREATE AND START CONTAINERS stop STOP SERVICES rm REMOVE STOPPED CONTAINERS ps LIST CONTAINERS logs VIEW OUTPUT FROM CONTAINERS scale SET THE NUMBER OF CONTAINERS FOR A SERVICE Table 1 Common commands used in Compose
You must have JavaScript enabled to view digital editions.