|
| 1 | +InfraKit Instance Plugin - Docker |
| 2 | +================================= |
| 3 | + |
| 4 | +[InfraKit](https://github.com/docker/infrakit) plugins for creating and managing Docker containers. |
| 5 | + |
| 6 | +## Instance plugin |
| 7 | + |
| 8 | +The InfraKit instance plugin creates and monitors Docker containers. |
| 9 | + |
| 10 | +### Example |
| 11 | + |
| 12 | +Based on the [default](https://github.com/docker/infrakit/tree/master/cmd/group) Group |
| 13 | +plugin: |
| 14 | +```console |
| 15 | +$ build/infrakit-group-default |
| 16 | +INFO[0000] Starting discovery |
| 17 | +INFO[0000] Starting plugin |
| 18 | +INFO[0000] Starting |
| 19 | +INFO[0000] Listening on: unix:///run/infrakit/plugins/group.sock |
| 20 | +INFO[0000] listener protocol= unix addr= /run/infrakit/plugins/group.sock err= <nil> |
| 21 | +``` |
| 22 | + |
| 23 | +and the [Vanilla](https://github.com/docker/infrakit/tree/master/pkg/example/flavor/vanilla) Flavor plugin: |
| 24 | +```console |
| 25 | +$ build/infrakit-flavor-vanilla |
| 26 | +INFO[0000] Starting plugin |
| 27 | +INFO[0000] Listening on: unix:///run/infrakit/plugins/flavor-vanilla.sock |
| 28 | +INFO[0000] listener protocol= unix addr= /run/infrakit/plugins/flavor-vanilla.sock err= <nil> |
| 29 | +``` |
| 30 | + |
| 31 | +We will use a basic configuration that creates a single instance: |
| 32 | +```console |
| 33 | +$ cat << EOF > aws-vanilla.json |
| 34 | +{ |
| 35 | + "ID": "docker-example", |
| 36 | + "Properties": { |
| 37 | + "Allocation": { |
| 38 | + "Size": 1 |
| 39 | + }, |
| 40 | + "Instance": { |
| 41 | + "Plugin": "instance-docker", |
| 42 | + "Properties": { |
| 43 | + "Config": { |
| 44 | + "Image": "alpine:3.5" |
| 45 | + }, |
| 46 | + "HostConfig": { |
| 47 | + "AutoRemove": true |
| 48 | + }, |
| 49 | + "Tags": { |
| 50 | + "Name": "infrakit-example" |
| 51 | + } |
| 52 | + } |
| 53 | + }, |
| 54 | + "Flavor": { |
| 55 | + "Plugin": "flavor-vanilla", |
| 56 | + "Properties": { |
| 57 | + "Init": [ |
| 58 | + "sh -c \"echo 'Hello, World!' > /hello\"" |
| 59 | + ] |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | +} |
| 64 | +EOF |
| 65 | +``` |
| 66 | + |
| 67 | +For the structure of `Config` `HostConfig`, see the plugin properties definition below. |
| 68 | + |
| 69 | +Finally, instruct the Group plugin to start watching the group: |
| 70 | +```console |
| 71 | +$ build/infrakit group watch docker-vanilla.json |
| 72 | +watching docker-example |
| 73 | +``` |
| 74 | + |
| 75 | +In the console running the Group plugin, we will see input like the following: |
| 76 | +``` |
| 77 | +INFO[1208] Watching group 'docker-example' |
| 78 | +INFO[1219] Adding 1 instances to group to reach desired 1 |
| 79 | +INFO[1219] Created instance i-ba0412a2 with tags map[infrakit.config_sha:dUBtWGmkptbGg29ecBgv1VJYzys= infrakit.group:aws-example] |
| 80 | +``` |
| 81 | + |
| 82 | +Additionally, the CLI will report the newly-created instance: |
| 83 | +```console |
| 84 | +$ build/infrakit group inspect docker-example |
| 85 | +ID LOGICAL TAGS |
| 86 | +90e6f3de4918 elusive_leaky Name=infrakit-example,infrakit.config_sha=dUBtWGmkptbGg29ecBgv1VJYzys=,infrakit.group=docker-example |
| 87 | +``` |
| 88 | + |
| 89 | +Retrieve the name of the container and connect to it with an exec |
| 90 | + |
| 91 | +```console |
| 92 | +$ docker exec -ti elusive_leaky cat /hello |
| 93 | +Hello, World! |
| 94 | +``` |
| 95 | + |
| 96 | +### Plugin properties |
| 97 | + |
| 98 | +The plugin expects properties in the following format: |
| 99 | +```json |
| 100 | +{ |
| 101 | + "Tags": { |
| 102 | + }, |
| 103 | + "Config": { |
| 104 | + }, |
| 105 | + "HostConfig": { |
| 106 | + }, |
| 107 | + "NetworkAttachments": [ |
| 108 | + ] |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +The `Tags` property is a string-string mapping of labels to apply to all Docker containers that are created. |
| 113 | +`Config` follows the structure of the type by the same name in the |
| 114 | +[Docker go SDK](https://github.com/docker/docker/blob/master/api/types/container/config.go). |
| 115 | +`HostConfig` follows the structure of the type by the same name in the |
| 116 | +[Docker go SDK](https://github.com/docker/docker/blob/master/api/types/container/host_config.go). |
| 117 | +`NetworkAttachments` is an array of [NetworkResource](https://github.com/docker/docker/blob/master/api/types/types.go). |
| 118 | + |
| 119 | +### LogicalID |
| 120 | + |
| 121 | +To take advantage of the Docker networking DNS, the InfraKit logicalID is mapped to the Docker container hostname (and not its IP). |
| 122 | +The plugin is compatible with both allocation methods, logical IDs (cattles) or group size (pets). |
0 commit comments