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