Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

InfraKit Instance Plugin - Docker

InfraKit plugins for creating and managing Docker containers.

Instance plugin

The InfraKit instance plugin creates and monitors Docker containers.

Example

Based on the default Group plugin:

$ build/infrakit-group-default
INFO[0000] Starting discovery
INFO[0000] Starting plugin
INFO[0000] Starting
INFO[0000] Listening on: unix:///run/infrakit/plugins/group.sock
INFO[0000] listener protocol= unix addr= /run/infrakit/plugins/group.sock err= <nil>

and the Vanilla Flavor plugin:

$ build/infrakit-flavor-vanilla
INFO[0000] Starting plugin
INFO[0000] Listening on: unix:///run/infrakit/plugins/flavor-vanilla.sock
INFO[0000] listener protocol= unix addr= /run/infrakit/plugins/flavor-vanilla.sock err= <nil>

We will use a basic configuration that creates a single instance:

$ cat << EOF > aws-vanilla.json
{
  "ID": "docker-example",
  "Properties": {
    "Allocation": {
      "Size": 1
    },
    "Instance": {
      "Plugin": "instance-docker",
      "Properties": {
        "Config": {
          "Image": "alpine:3.5"
        },
        "HostConfig": {
          "AutoRemove": true
        },
        "Tags": {
          "Name": "infrakit-example"
        }
      }
    },
    "Flavor": {
      "Plugin": "flavor-vanilla",
      "Properties": {
        "Init": [
          "sh -c \"echo 'Hello, World!' > /hello\""
        ]
      }
    }
  }
}
EOF

For the structure of Config HostConfig, see the plugin properties definition below.

Finally, instruct the Group plugin to start watching the group:

$ build/infrakit group watch docker-vanilla.json
watching docker-example

In the console running the Group plugin, we will see input like the following:

INFO[1208] Watching group 'docker-example'
INFO[1219] Adding 1 instances to group to reach desired 1
INFO[1219] Created instance i-ba0412a2 with tags map[infrakit.config_sha:dUBtWGmkptbGg29ecBgv1VJYzys= infrakit.group:aws-example]

Additionally, the CLI will report the newly-created instance:

$ build/infrakit group inspect docker-example
ID                             	LOGICAL                        	TAGS
90e6f3de4918                   	elusive_leaky                  	Name=infrakit-example,infrakit.config_sha=dUBtWGmkptbGg29ecBgv1VJYzys=,infrakit.group=docker-example

Retrieve the name of the container and connect to it with an exec

$ docker exec -ti elusive_leaky cat /hello
Hello, World!

Plugin properties

The plugin expects properties in the following format:

{
  "Tags": {
  },
  "Config": {
  },
  "HostConfig": {
  },
  "NetworkAttachments": [
  ]
}

The Tags property is a string-string mapping of labels to apply to all Docker containers that are created. Config follows the structure of the type by the same name in the Docker go SDK. HostConfig follows the structure of the type by the same name in the Docker go SDK. NetworkAttachments is an array of NetworkResource.

LogicalID

To take advantage of the Docker networking DNS, the InfraKit logicalID is mapped to the Docker container hostname (and not its IP). The plugin is compatible with both allocation methods, logical IDs (cattles) or group size (pets).