github.com/olljanat/moby@v1.13.1/docs/extend/EBS_volume.md (about) 1 --- 2 description: Volume plugin for Amazon EBS 3 keywords: "API, Usage, plugins, documentation, developer, amazon, ebs, rexray, volume" 4 title: Volume plugin for Amazon EBS 5 --- 6 7 <!-- This file is maintained within the docker/docker Github 8 repository at https://github.com/docker/docker/. Make all 9 pull requests against that repo. If you see this file in 10 another repository, consider it read-only there, as it will 11 periodically be overwritten by the definitive file. Pull 12 requests which include edits to this file in other repositories 13 will be rejected. 14 --> 15 16 # A proof-of-concept Rexray plugin 17 18 In this example, a simple Rexray plugin will be created for the purposes of using 19 it on an Amazon EC2 instance with EBS. It is not meant to be a complete Rexray plugin. 20 21 The example source is available at [https://github.com/tiborvass/rexray-plugin](https://github.com/tiborvass/rexray-plugin). 22 23 To learn more about Rexray: [https://github.com/codedellemc/rexray](https://github.com/codedellemc/rexray) 24 25 ## 1. Make a Docker image 26 27 The following is the Dockerfile used to containerize rexray. 28 29 ```Dockerfile 30 FROM debian:jessie 31 RUN apt-get update && apt-get install -y --no-install-recommends wget ca-certificates 32 RUN wget https://dl.bintray.com/emccode/rexray/stable/0.6.4/rexray-Linux-x86_64-0.6.4.tar.gz -O rexray.tar.gz && tar -xvzf rexray.tar.gz -C /usr/bin && rm rexray.tar.gz 33 RUN mkdir -p /run/docker/plugins /var/lib/libstorage/volumes 34 ENTRYPOINT ["rexray"] 35 CMD ["--help"] 36 ``` 37 38 To build it you can run `image=$(cat Dockerfile | docker build -q -)` and `$image` 39 will reference the containerized rexray image. 40 41 ## 2. Extract rootfs 42 43 ```sh 44 $ TMPDIR=/tmp/rexray # for the purpose of this example 45 $ # create container without running it, to extract the rootfs from image 46 $ docker create --name rexray "$image" 47 $ # save the rootfs to a tar archive 48 $ docker export -o $TMPDIR/rexray.tar rexray 49 $ # extract rootfs from tar archive to a rootfs folder 50 $ ( mkdir -p $TMPDIR/rootfs; cd $TMPDIR/rootfs; tar xf ../rexray.tar ) 51 ``` 52 53 ## 3. Add plugin configuration 54 55 We have to put the following JSON to `$TMPDIR/config.json`: 56 57 ```json 58 { 59 "Args": { 60 "Description": "", 61 "Name": "", 62 "Settable": null, 63 "Value": null 64 }, 65 "Description": "A proof-of-concept EBS plugin (using rexray) for Docker", 66 "Documentation": "https://github.com/tiborvass/rexray-plugin", 67 "Entrypoint": [ 68 "/usr/bin/rexray", "service", "start", "-f" 69 ], 70 "Env": [ 71 { 72 "Description": "", 73 "Name": "REXRAY_SERVICE", 74 "Settable": [ 75 "value" 76 ], 77 "Value": "ebs" 78 }, 79 { 80 "Description": "", 81 "Name": "EBS_ACCESSKEY", 82 "Settable": [ 83 "value" 84 ], 85 "Value": "" 86 }, 87 { 88 "Description": "", 89 "Name": "EBS_SECRETKEY", 90 "Settable": [ 91 "value" 92 ], 93 "Value": "" 94 } 95 ], 96 "Interface": { 97 "Socket": "rexray.sock", 98 "Types": [ 99 "docker.volumedriver/1.0" 100 ] 101 }, 102 "Linux": { 103 "AllowAllDevices": true, 104 "Capabilities": ["CAP_SYS_ADMIN"], 105 "Devices": null 106 }, 107 "Mounts": [ 108 { 109 "Source": "/dev", 110 "Destination": "/dev", 111 "Type": "bind", 112 "Options": ["rbind"] 113 } 114 ], 115 "Network": { 116 "Type": "host" 117 }, 118 "PropagatedMount": "/var/lib/libstorage/volumes", 119 "User": {}, 120 "WorkDir": "" 121 } 122 ``` 123 124 Please note a couple of points: 125 - `PropagatedMount` is needed so that the docker daemon can see mounts done by the 126 rexray plugin from within the container, otherwise the docker daemon is not able 127 to mount a docker volume. 128 - The rexray plugin needs dynamic access to host devices. For that reason, we 129 have to give it access to all devices under `/dev` and set `AllowAllDevices` to 130 true for proper access. 131 - The user of this simple plugin can change only 3 settings: `REXRAY_SERVICE`, 132 `EBS_ACCESSKEY` and `EBS_SECRETKEY`. This is because of the reduced scope of this 133 plugin. Ideally other rexray parameters could also be set. 134 135 ## 4. Create plugin 136 137 `docker plugin create tiborvass/rexray-plugin "$TMPDIR"` will create the plugin. 138 139 ```sh 140 $ docker plugin ls 141 ID NAME DESCRIPTION ENABLED 142 2475a4bd0ca5 tiborvass/rexray-plugin:latest A rexray volume plugin for Docker false 143 ``` 144 145 ## 5. Test plugin 146 147 ```sh 148 $ docker plugin set tiborvass/rexray-plugin EBS_ACCESSKEY=$AWS_ACCESSKEY EBS_SECRETKEY=$AWS_SECRETKEY` 149 $ docker plugin enable tiborvass/rexray-plugin 150 $ docker volume create -d tiborvass/rexray-plugin my-ebs-volume 151 $ docker volume ls 152 DRIVER VOLUME NAME 153 tiborvass/rexray-plugin:latest my-ebs-volume 154 $ docker run --rm -v my-ebs-volume:/volume busybox sh -c 'echo bye > /volume/hi' 155 $ docker run --rm -v my-ebs-volume:/volume busybox cat /volume/hi 156 bye 157 ``` 158 159 ## 6. Push plugin 160 161 First, ensure you are logged in with `docker login`. Then you can run: 162 `docker plugin push tiborvass/rexray-plugin` to push it like a regular docker 163 image to a registry, to make it available for others to install via 164 `docker plugin install tiborvass/rexray-plugin EBS_ACCESSKEY=$AWS_ACCESSKEY EBS_SECRETKEY=$AWS_SECRETKEY`.