github.com/polydawn/docket@v0.5.4-0.20140630233848-90b70fb433da/readme.md (about) 1 # Hroot 2 3 Hroot provides transports and straightforward configuration files for [Docker](https://www.docker.io/).<br/> 4 Strongly version your containers, then distribute them offline or over SSH & HTTP with git! 5 6 Docker's image storage is treated like a cache, while Hroot manages your images using git as a persistent storage backend. 7 Your containers now have effortless history, strong hashes to verify integrity, git commit messages, and secure transport. 8 9 Further, ditch those long config flags and express them in a file instead. 10 Hroot looks for a `hroot.toml` file in the current directory and sets up binds, mounts, etc. 11 Add that file to your project's version control and get your entire team working on the same system. 12 13 ## Quickstart 14 15 Grab the latest [release](https://github.com/polydawn/hroot/releases) and throw it on your path. Alternately, [build Hroot from source](#building-from-source). 16 17 ```bash 18 # Clone down some example config files 19 git clone https://github.com/polydawn/boxen.git && cd boxen 20 21 # Download ubuntu from public index, save into git 22 cd ubuntu-index && hroot build 23 24 # Build your own ubuntu image (updates apt-get) 25 cd ../ubuntu && hroot build 26 27 # Load repeatable ubuntu from git and start an interactive shell 28 hroot run bash 29 ``` 30 31 You just built a git repo tracking ubuntu. 32 33 A new (bare) repository called `graph` has appeared in the `boxen` folder.<br/> 34 Push that anywhere and have your team clone it down! 35 36 ## How do I use it? 37 38 Hroot provides two commands to help you maintain & use images: `build` and `run`. 39 40 Using `build` will take an image from somewhere, execute a build step, and save the result.<br/> 41 Using `run` just runs an (already-built) image. 42 43 ### Getting started 44 45 First you'll need Docker, which you can get via their [installation instructions](http://docs.docker.io/en/latest/installation/).<br/> 46 Next, [download Hroot](https://github.com/polydawn/hroot/releases) and place it on your path: 47 48 ```bash 49 # Run this from your download directory 50 sudo cp ./hroot /usr/bin/hroot 51 52 # Test that it's working 53 hroot version 54 ``` 55 56 Running containers with Hroot requires root, so you'll need to use sudo or launch a root shell for most commands. You'll also need a running Docker server - if you followed the linked instructions, one should already be running for you. Hroot tries to use the default server first, and starts one for you if it can't find one. 57 58 ### First steps 59 60 To use Hroot, you need a config file in the current directory called `hroot.toml`.<br/> 61 This file tracks all your image names and settings. 62 63 Our [Boxen](https://github.com/polydawn/boxen) repository has several examples, which we'll use for this tutorial.<br/> 64 Clone it down if you haven't already: 65 66 ```bash 67 # Clone down some prepared examples 68 git clone https://github.com/polydawn/boxen.git && cd boxen 69 ``` 70 71 In the boxen folder, there's the first [config file](https://github.com/polydawn/boxen/blob/master/hroot.toml). 72 You'll notice there's only one section - `settings`. 73 Here we set up a bunch of settings we want for pretty much every image: DNS servers, folder mounts, etc. 74 75 Because Hroot is smart, these settings apply to every image configured in Boxen. 76 Hroot scans up parent folders, looking for `hroot.toml` files, and stops when it can't find one. 77 Today, we'll be using ubuntu: 78 79 ```bash 80 # Pop into the index ubuntu folder 81 cd ubuntu-index 82 ``` 83 84 You'll notice this next [config file](https://github.com/polydawn/boxen/blob/master/ubuntu-index/hroot.toml) is different - it has *image* and *target* sections, with copious comments.<br/> 85 We'll explain each in turn: 86 87 ### Image names 88 89 The image section can have three entries: *name*, *upstream*, and *index*. 90 91 <table> 92 <tr> 93 <th>Entry</th> 94 <th>Purpose</th> 95 </tr><tr> 96 <tr> 97 <td>Name</td> 98 <td> 99 <p>The name of the image, and the name of the branch that ends up in git.</p> 100 <p>Example: <code>polydawn.net/ubuntu/14.04</code></p> 101 </td> 102 </tr> 103 <tr><tr> 104 <td>Upstream</td> 105 <td> 106 <p>This image's parent - where did it get built from? This is used by the build command.</p> 107 108 <p>A configuration file has either an Upstream or an Index key, but not both.</p> 109 110 <p>Example: <code>index.docker.io/ubuntu/14.04</code> 111 </td> 112 </tr><tr> 113 <tr> 114 <td>Index</td> 115 <td> 116 <p><a href="https://index.docker.io">Docker index</a> names are not compatible with reasonable branch names.</p> 117 118 <p>A prime example is "ubuntu", which would be confusing without specifying the difference between an unmodified ubuntu and one you've saved in the graph.</p> 119 120 <p>For this reason, we store the upstream image's index alias separately, and <i>only</i> use that when pulling from the index.</p> 121 122 <p>Example: <code>ubuntu:14.04</code></p> 123 </td> 124 </tr> 125 </table> 126 127 ### Targets 128 129 Targets tell Hroot what to do. 130 They can be called anything, but two are special: `build` and `run`, which are the defaults used when you tell Hroot to... build & run! 131 132 Unlike the settings section, putting settings in a *target* only applies to that target. 133 It does not affect other folders.<br/> 134 You can put any setting in a target, but the most common usage is to set a different **command**. 135 136 You'll notice that in the current folder, trying `hroot run` will just echo out an example message, while `hroot run bash` will launch a bash shell. 137 138 Of course, neither will work right now - Hroot can't find your image! 139 We need to get ourselves an image. 140 141 ### Bootstrapping from the index 142 143 Most of the time, you'll want to fork & version an image from the public docker index. 144 We support plain tarballs as well (more on that later), but the index can be convenient. 145 This is what the index [conf file](https://github.com/polydawn/boxen/blob/master/ubuntu-index/hroot.toml) is ready to do. 146 147 Try the following: 148 149 ```bash 150 # Download ubuntu from public index, save into git 151 hroot build 152 ``` 153 154 This command accomplished a few things: 155 156 * Hroot chose the public index as the *source*, and looked there for an image called `ubuntu:14.04` 157 * A small [build script](https://github.com/polydawn/boxen/blob/master/ubuntu-index/build.sh) cleaned out apt-get state from the index image that we don't want to save in history. 158 * Once downloaded, Hroot saved that image to the graph *destination*. 159 * Odds are you didn't have a graph repository, so Hroot created one for you. 160 161 You now have a (bare) git repository called `graph` in the `boxen` folder!<br/> 162 If you check out the log, you'll have a single commit with the image's branch name: 163 164 ``` 165 $ ( cd ../graph ; git log --graph --decorate ) 166 167 * commit 7105d5622bf8118af1c13001f2b36d51a93f020e (index.docker.io/ubuntu/14.04) 168 Author: Your Name <you@example.com> 169 170 index.docker.io/ubuntu/14.04 imported from an external source 171 ``` 172 173 You can push this repository anywhere & share it with the world. 174 Whoever receives it can validate the hash and have a guarantee it's the same image. 175 176 ### Sources & destinations: 177 178 Our example used the index as a source and a local graph as the destination. 179 Hroot supports a few others: 180 181 <table> 182 <tr> 183 <tr> 184 <th>Type</th> 185 <th>Purpose</th> 186 </tr><tr> 187 <tr> 188 <td>Graph</td> 189 <td>A git repository used to version images. <i>(default)</i></td> 190 </tr><tr> 191 <tr> 192 <td>File</td> 193 <td>A tarball created from docker export.</td> 194 </tr><tr> 195 <tr> 196 <td>Docker</td> 197 <td>The local docker daemon's cache.</td> 198 </tr><tr> 199 <tr> 200 <td>Index</td> 201 <td>The <a href="https://index.docker.io">public index</a>.</td> 202 </tr> 203 </table> 204 205 This makes it easy to load & save images in a variety of ways. 206 Use the appropriate strategy for your situation.<br/> 207 208 You can set these with the `-s` and `-d` flags, otherwise Hroot will choose smart defaults. 209 210 ### Building an image 211 212 We're now ready to fork the image we downloaded and walk our own (strongly-versioned) path. 213 214 ```bash 215 # Navigate to the main ubuntu folder 216 cd ../ubuntu 217 218 # Upgrade apt-get packages & save the new ubuntu image 219 hroot build 220 ``` 221 222 This will plug away for awhile (you're updating all the ubuntu packages!) and accomplish a few things: 223 224 * Hroot imported the image from the graph. 225 * The Docker daemon now knows about `index.docker.io/ubuntu`, not just `ubuntu`. 226 * The [build.sh](https://github.com/polydawn/boxen/blob/master/ubuntu/build.sh) file ran a couple scripts around apt-get, upgrading packages. 227 * After building, Hroot saved our new image to the graph. 228 * We now have a new branch name, starting with `example.com/ubuntu`. 229 230 Your git log has a new commit listed: 231 232 ``` 233 $ ( cd ../graph ; git log --graph --decorate ) 234 235 * commit 2a9c8a28220717790de7336d07f86e9857074509 (HEAD, example.com/ubuntu/14.04) 236 | Author: Your Name <you@example.com> 237 | 238 | example.com/ubuntu/14.04 updated from index.docker.io/ubuntu/14.04 239 | 240 * commit 7105d5622bf8118af1c13001f2b36d51a93f020e (index.docker.io/ubuntu/14.04) 241 Author: Your Name <you@example.com> 242 243 index.docker.io/ubuntu/14.04 imported from an external source 244 ``` 245 246 Notice how you now have two branches, named after their respective images. 247 This git repository will track which image was built from where, using merges - an audit log, built into the log graph. 248 249 Now you can play around with hroot images. Launch a bash shell and experiment! 250 251 ```bash 252 # Load repeatable ubuntu from git and start an interactive shell 253 hroot run bash 254 ``` 255 256 ### What's next? 257 258 From here, we strongly recommend playing around more with the example [Boxen](https://github.com/polydawn/boxen) folders. 259 There's several images pre-configured there, for example a zero-config nginx server. 260 Additions to that repository are welcome! 261 262 When you're ready to use Hroot with your own team, simply write your own `hroot.toml` file and place it in a new folder. 263 Build yourself an image (perhaps copying one of our `build.sh` scripts?) and share your machine with the world! 264 265 266 ## Building from source 267 268 To build Hroot, you will need Go 1.2 or newer. 269 Following the [golang instructions](http://golang.org/doc/install#bsd_linux) for 64-bit linux: 270 271 ```bash 272 curl https://go.googlecode.com/files/go1.2.linux-amd64.tar.gz -o golang.tar.gz 273 sudo tar -C /usr/local -xzf golang.tar.gz 274 export PATH=$PATH:/usr/local/go/bin # Add this to /etc/profile or similar 275 ``` 276 277 Clone down Hroot & throw it on your path: 278 ```bash 279 git clone https://github.com/polydawn/hroot && cd hroot 280 git submodule update --init 281 282 ./goad build 283 sudo cp hroot/hroot /usr/bin/hroot 284 ``` 285 286 Now you're ready to rock & roll. 287 Lots of examples are available over at [Boxen](https://github.com/polydawn/boxen)! 288 289 290 ## Installing Docker 291 292 Hroot uses [Docker](https://www.docker.io/), an excellent container helper based on LXC. 293 This gives Hroot all that containerization mojo. We're using Docker 0.11.1 right now. 294 295 Docker offers a variety of [installation instructions](http://docs.docker.io/en/latest/installation/) on their site.