Skip to main content

Use Docker in the ThinkAgile CP Cloud Controller

You can run the Docker platform in the ThinkAgile CP Cloud Controller.

Complete the following steps to use Docker in the ThinkAgile CP Cloud Controller:

  1. Create three instances from the CentOS 7 - Docker CS Engine 1.12 template, which you can download from the Lenovo Cloud Marketplace:

    swarm-manager, swarm-worker-1, and swarm-worker-2

    For information about creating an instance from a template, see the following topic:

    Create an instance from a template

  2. Update the host names on the instances:

    hostnamectl set-hostname swarm-manager --static && reboot

    (change the host name to swarm-worker-1 and swarm-worker-2 for the other instances)

  3. On the swarm-manager instance, run the following command::

    docker swarm init

    The swarm should successfully initialize, and the IP and token should be listed.

    Then run:

    docker node ls

    The swarm manager should be listed.

  4. On each swarm worker instance, run the following command:

    docker swarm join --token <token from previous step> <ip from previous step>:2377

  5. On the swarm-manager instance, run the following command:

    docker node ls

    It should now list the worker nodes and the swarm manager.

  6. On the swarm-manager instance, run the following command:
    docker run -d --restart always --name visualizer -p 8080:8080 
    -e HOST=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
    -v /var/run/docker.sock:/var/run/docker.sock manomarks/visualizer
  7. Navigate in a web browser to <swarm manager ip>:8080. It should load and show the manager and both workers.
  8. On the swarm-manager instance, create a volume with an application by running the following commands:
    docker volume create --driver tacp --name my-website

    docker run -it --rm --name tacp-configure -v my-website:/data --volume-driver tacp busybox sh

    Inside the container (where previous command lands you) run the following command:

    vi /data/index.html

    Then type i to edit the file

  9. Paste the following code:
    <html>
    <head>
    <title>Hello world!</title>
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
    <style>body {background-color: white;text-align: center;padding: 50px;font-family:
    Open Sans,Helvetica Neue,Helvetica,Arial,sans-serif;}
    #logo {margin-bottom: 40px;}
    </style>
    </head>
    <body>
    <img id=logo src=http://www.iatechexpo.com/images/logo_cloudistics.png />
    <h1>Docker 1.12 powered by the ThinkAgile CP Platform</h1>
    </body>
    </html>
  10. Exit the container (type exit).
  11. On the swarm-manager instance, create a second volume with an application:
    docker volume create --driver tacp --name my-website2

    docker run -it --rm --name tacp-configure -v my-website2:/data --volume-driver tacp busybox sh

    Inside the container (where previous command lands you) run the following command:

    vi /data/index.html

    Then type i to edit the file

  12. Paste the code from the previous step into the file.
  13. Create and remove a third volume on the swarm-manager instance:
    docker volume create --driver tacp --name my-website

    docker volume rm my-website3
  14. On the swarm-manager instance, launch the web application service for the first volume:
    docker service create --name my-app --mount type=volume,target=/usr/share/nginx/html,source=my-website,volume-driver=tacp 
    --publish 8081:80
    --constraint 'node.role == worker' nginx:latest nginx -g 'daemon off;'

    In the visualizer, the container should be scheduled on the cluster.

  15. In a browser, navigate to <swarm-worker ip>:8081 to view the container
  16. On the swarm-manager instance, launch the web application service for the second volume:
    docker service create --name my-app2 --mount type=volume,target=/usr/share/nginx/html,source=my-website2,volume-driver=tacp 
    --publish 8082:80
    --constraint 'node.role == worker' nginx:latest nginx -g 'daemon off;'

    In the visualizer, the container should be scheduled on the cluster.

  17. In a browser, navigate to <swarm-worker ip>:8082 to view the container.
  18. On the manager node, run the following command:

    docker node ls

    then enter:

    docker node update --availability drain swarm-worker-1

    In the visualizer, the node should show it is draining, and the container should move to swarm-worker-2

  19. On the manager node, run the following command:

    docker node update --availability active swarm-worker-1

    In the visualizer the node should show it is reactivated

  20. On the manager node, run the following command:

    docker node ls, then docker node update --availability drain swarm-worker-2

    In the visualizer, the node should show it is draining, and the containers should move to swarm-worker-1

  21. On the manager node, run the following command:

    docker node update --availability active swarm-worker-2

    In the visualizer, the node should show it is reactivated.

  22. Shut down a worker node to validate the failover process:

    shut down swarm-worker-1

    (the worker node with the containers)

    In the visualizer, Docker should reschedule the containers.