Docker Compose usage

One of the more useful tools, and one I find myself using a lot, is Docker Compose. Compose has a lot of powerful usage, which in turn is great for you. In this section, we will look at two of its usages:

  • Developer environments
  • Scaling environments

Developer environments

You can use Docker Compose to set up your developer environments. How is this any different from setting up a virtual machine for them to use or letting them use their own setup? With Docker Compose, you control the setup, you control what is linked to what, and you know how the environment is set up. So, there is no more "well it works on my system" or need to troubleshoot error messages that are appearing on one system setup but not another.

Scaling environments

Docker Compose also allows you to scale containers that are located in the docker-compose.yml file. For example, let's say our Compose file looks as follows:

varnish:
  image: jacksoncage/varnish
  ports:
    - "82:80"
  links:
    - web
environment:
    VARNISH_BACKEND_PORT: 80
    VARNISH_BACKEND_IP: web
    VARNISH_PORT: 80
web:
   image: scottpgallagher/php5-mysql-apache2
   volumes:
     - .:/var/www/html/

With the Compose setup, you can easily scale the containers from your docker-compose.yml file. For instance, if you need more web containers to help with the backend load, you can do so with Docker Compose. Be sure that you are in the folder where your docker-compose.yml file is located:

$ docker-compose scale web=3

This will add three extra web containers and do all the linking as well as the traffic forwarding from the varnish server that is necessary. This can be immensely helpful if you are looking at figuring out how many instances you might need to help scale for load or service usage.

Scaling environments
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset