wauterw
By:
wauterw

How to manage multiple docker containers

February 3, 2015 23.2k views

I wanted to install multiple independent Wordpress instances on a single server. I'm planning on doing this using multiple docker containers. I can do this following the tutorials.

My question is related to the management: after a while it gets messy to see how many contains are running, which Wordpress instance is up or not, .... Is there any way to get a proper (web alike) overview where you could get a 'management' overview of what's going on?

2 Answers

There are a number of web interfaces for Docker out there like Rancher.io and Shipyard

Another approach would be to use the native process manager for your host OS. On Ubuntu 14.04, that would be Upstart while on CoreOS it is systemd. This will allow you to start, stop, and check the status of your containers using the native service command

As an example, I created a WordPress container using the tutum/wordpress image and named it "example.com"

docker run -p 80:80 --name "example.com" tutum/wordpress

A simple Upstart script to manage a Docker container would look like:

description "Wordpress - example.com"
author "Doker Guru"
start on filesystem and started docker
stop on runlevel [!2345]
respawn
exec /usr/bin/docker start -a example.com
pre-stop exec /usr/bin/docker stop -a example.com

and install it to /etc/init/example.conf The container will now start on boot, respawn if it dies, and you can use commands like:

$ sudo service example status
example stop/waiting
$ sudo service example start
example start/running, process 2900
$ sudo service example stop
example stop/waiting

Once you have multiple containers running multiple services running, this can make your life much easier.

Thanks for the useful answer. Would you then for each container use a different port number for the external world, like:

  • docker run -p 8001:80 --name "example1.com" tutum/wordpress
  • docker run -p 8002:80 --name "example2.com" tutum/wordpress

so that my webpages are accessible through:

Or can it also work as follows

  • docker run -p 80:80 --name "example1.com" tutum/wordpress
  • docker run -p 80:80 --name "example2.com" tutum/wordpress
  • You won't be able to directly bind two containers to the same port. In order to accomplish that you'd need to set up a reverse proxy in front to direct requests. Nginx is a great option for that. A real basic example of that would be to run each container on a separate port on localhost.

    docker run -p 127.0.0.1:8001:80 --name "example1.com" tutum/wordpress
    docker run -p 127.0.0.1:8002:80 --name "example2.com" tutum/wordpress
    

    Then your Nginx config would direct requests to the proper container:

    upstream app_server_one {
        server 127.0.0.1:8001 fail_timeout=0;
    }
    
    upstream app_server_two {
        server 127.0.0.1:8002 fail_timeout=0;
    }
    
    server {
        listen 80 default_server;
        server_name: example1.com;
    
       # [snip...]
    
        location / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_pass http://app_server_one;
        }
    }
    
    server {
        listen 80 default_server;
        server_name:example2.com;
    
       # [snip...]
    
        location / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_pass http://app_server_two;
        }
    }
    

    Of course, you can also set this up as a container of its own.

    by O.S Tezer
    In this DigitalOcean article, our goal is to learn about creating a docker container from a base image and building it to run Nginx (layer by layer). Later, following the steps from the beginning, we create a Dockerfile to automate the process using a custom input file for configurations. In the end, using this Nginx docker image, it becomes possible to create self-contained sandboxes running Nginx, which can be used to serve "dockerised" applications.
Have another answer? Share your knowledge.