Docker compose

Docker compose provides a nice way to link multiple containers that are running on a machine.

Take the below example,

We have an Angular JS web application and the back end is a Rest App. Both are running on different port number. Angular App is running on 80 and REST is on 8081. So we have to hard code the domain and other information in web application config file to consume the Rest services or else we have to pass an env variable in the start up script of web application.

So if you want to update REST service URL, you would have to update the code or start up script. But if we use Docker compose, then it will be pretty simple to do.

Refer the below docker compose file.


rest:
   image: rest_image:1.0
   log_driver: "json-file"
   ports:
     - 8081:8081
   log_opt:
      max-size: "10m"
      max-file: "5"    
web:
    image: web_image:1.0
    environment:
     - REST_URL=http://rest:8081
    log_driver: "json-file"
    ports:
      - 80:80
    log_opt:
       max-size: "10m"
       max-file: "5"
    links:
         - rest:rest

web_layer has an env variable which holds the Rest service url location. Assume that you have two env’s. Dev and QA and want to point QA env’s Rest service from Dev env Web app. Then it can be done nicely in docker compose script as below.


rest:
   image: rest_image:1.0
   log_driver: "json-file"
   ports:
     - 8081:8081
log_opt:
     max-size: "10m"
     max-file: "5"

web:
    image: web_image:1.0
    environment:
    - REST_URL=http://qa.companyinfo.com:8081
    log_driver: "json-file"
    ports:
     - 80:80
    log_opt:
      max-size: "10m"
      max-file: "5"

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s