github.com/cloudcredo/cloudrocker@v0.0.0-20160108110610-1320f8cc2dfd/README.md (about) 1 #Cloud Rocker 2 3 Cloud Rocker is the convergence of [Cloud Foundry](http://cloudfoundry.org/index.html) and [Docker](https://www.docker.com/) aiming to bring the Cloud Foundry experience to a developer's machine. 4 5 ##Tutorial 6 7 This is a brief tutorial to ease you through your first rocking experience. 8 9 ###Set up your Docker environment 10 11 Select either option 1 or option 2, then move to [Test your Docker environment](https://github.com/CloudCredo/cloudrocker#test-your-docker-environment). 12 13 ####Option 1 : Easy - Mac/Windows/Linux - using Vagrant 14 15 ``` 16 vagrant up --provider virtualbox 17 vagrant ssh 18 ``` 19 Please use the Vagrantfile in the root of this repository. All later commands are entered as the vagrant user's shell in the vagrant VM. 20 21 Modify the [Vagrantfile](https://github.com/CloudCredo/cloudrocker/blob/master/Vagrantfile#L12) to mount your local workspace to make development easy. 22 23 ####Option 2 : Advanced users - Linux only - using a local Docker daemon 24 25 ``` 26 $ go get github.com/cloudcredo/cloudrocker/rock 27 ``` 28 The user for 'rock' commands must have permissions to access the Docker daemon. 29 30 ###Test your Docker environment 31 32 ```$ rock docker``` 33 34 You should see output similar to this: 35 ``` 36 Client API version: 1.15 37 Go version (client): go1.3 38 OS/Arch (client): linux/amd64 39 Server version: 1.3.0 40 Server API version: 1.15 41 Go version (server): go1.3.3 42 Git commit (server): c78088f 43 ``` 44 45 ###Rock your local machine 46 47 Download the base Cloud Foundry container image. 48 49 ```$ rock this``` 50 51 ###Add a buildpack 52 53 ```$ rock add-buildpack https://github.com/cloudfoundry/java-buildpack``` 54 55 ###Deploy your application 56 57 Change PWD to the sample Java application. 58 59 ```$ cd /vagrant/sample-apps/java/``` 60 61 Start the application. 62 63 ```$ rock up``` 64 65 ``` 66 Starting the CloudRocker container... 67 Running Buildpacks... 68 -----> Java Buildpack Version: 120c640 69 *--Buildpack output omitted--* 70 Started the CloudRocker container. 71 Deleting the CloudRocker container... 72 cloudrocker-staging 73 Deleted container. 74 Starting the CloudRocker container... 75 5b69950f351d2c843fe2ffd531edd87c09f19a368241ae37a6d2e025000dd6c8 76 Started the CloudRocker container. 77 Connect to your running application at http://localhost:8080/ 78 ``` 79 80 You should now be able to browse the output on the vagrant machine. 81 82 ```$ curl localhost:8080``` 83 84 You should also be able to browse the output on your host machine. 85 86 [The rocking site.](http://localhost:8080/) 87 88 Please note the unsubtle [CloudCredo](http://www.cloudcredo.com/) advertising. 89 90 ###Shut the application down 91 92 ```$ rock off``` 93 94 ##Buildpacks 95 96 A great list of Cloud Foundry buildpacks is [available on the Cloud Foundry community wiki](https://github.com/cloudfoundry-community/cf-docs-contrib/wiki/Buildpacks). 97 98 List buildpacks 99 100 ```$ rock buildpacks``` 101 102 ``` 103 cf-buildpack-php 104 go-buildpack 105 java-buildpack 106 nodejs-buildpack 107 python-buildpack 108 ruby-buildpack 109 ``` 110 111 Add a buildpack 112 113 ```$ rock add-buildpack https://github.com/cloudfoundry/php-buildpack``` 114 115 Remove a buildpack 116 117 ```$ rock delete-buildpack php-buildpack``` 118 119 Sample applications to use with the buildpacks are in [sample-apps](https://github.com/CloudCredo/cloudrocker/tree/master/sample-apps). 120 121 ##Docker Images 122 123 ###Building a Docker image from your application code 124 125 Ensure you have a corresponding buildpack installed for your application type. 126 127 ```$ rock buildpacks``` 128 129 Ensure your PWD is your application directory. 130 131 ```$ cd <app_dir>``` 132 133 Build a Docker image. 134 135 ```$ rock build``` 136 137 or with a tag 138 139 ```$ rock build user/image:tag``` 140 eg 141 ```$ rock build hatofmonkeys/rocker-test:latest``` 142 143 144 ``` 145 <output truncated> 146 Step 10 : CMD ["/bin/bash", "/app/cloudrocker-start-1c4352a23e52040ddb1857d7675fe3cc.sh", "/app", "bundle", "exec", "rackup", "config. 147 ru", "-p", "$PORT"] 148 ---> Running in fd810cea3db4 149 ---> 4a88ad7d67ae 150 Removing intermediate container fd810cea3db4 151 Successfully built 4a88ad7d67ae 152 Created image. 153 ``` 154 155 In the example above the created image ID is 4a88ad7d67ae. 156 157 ```$ docker images``` 158 159 ``` 160 REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE 161 hatofmonkeys/rocker-test latest 4a88ad7d67ae 13 minutes ago 609 MB 162 ``` 163 164 This image can be run like any other Docker image. 165 166 ``` 167 $ docker run -P -d hatofmonkeys/rocker-test:latest 168 0e4825d049ba5390699625be145a8d029a5e2899e52c8c5f967d35e08412f3ba 169 $ docker ps 170 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 171 0e4825d049ba hatofmonkeys/rocker-test:latest /bin/bash /app/cloud 4 minutes ago Up 4 minutes 0.0.0.0:49154->8080/tcp sick_lumiere 172 $ curl localhost:49154 173 Hello world! 174 ``` 175 176 The image can be uploaded to a Docker registry, or deployed and run in a system such as [Kubernetes](https://github.com/GoogleCloudPlatform/kubernetes), [Decker](https://github.com/hatofmonkeys/decker-release), or [Diego](http://thenewstack.io/docker-on-diego-cloud-foundrys-new-elastic-runtime/). 177 178 ##External Services 179 180 Services can be connected to your application by adding a *vcap_services.json* file to the root directory of your application. This is demonstrated in the [ruby-with-services sample application](https://github.com/CloudCredo/cloudrocker/tree/master/sample-apps/ruby-with-services). 181 182 #####Note - the following steps are only appropriate to users of the Vagrant image (tutorial option 1 above). 183 184 Change PWD to the sample ruby-with-services sample application. 185 186 ```$ cd /vagrant/sample-apps/ruby-with-services``` 187 188 If necessary, install a Ruby buildpack. 189 190 ```$ rock add-buildpack https://github.com/cloudfoundry/cf-buildpack-ruby``` 191 192 Start the application. 193 194 ```$ rock up``` 195 196 Set a value for a key. 197 198 [http://localhost:8080/set/hello/to/world](http://localhost:8080/set/hello/to/world) 199 200 Get the value. 201 202 [http://localhost:8080/get/hello](http://localhost:8080/get/hello) 203 204 ##Working with [Lattice](http://lattice.cf) 205 206 In the root directory of your application, the workflow is three simple commands to build and deploy your own containers to Lattice. 207 208 *replace hatofmonkeys/rocker-test:latest with your own user/image:tag* 209 210 ```$ rock build hatofmonkeys/rocker-test:latest``` 211 212 ```$ docker push hatofmonkeys/rocker-test:latest``` 213 214 ```$ ltc create rocker-test hatofmonkeys/rocker-test:latest``` 215 216 *note this may appear to timeout on slow connections. Watch ```ltc status rocker-test``` until the application is running* 217 218 ##Debugging your app, your buildpack, your staging process 219 220 Build/staging artefacts are placed in $CLOUDROCKER_HOME. By default this is $HOME/cloudrocker, eg. /home/vagrant/cloudrocker. This is a treasure trove of interesting information when debugging staging failures. 221 222 ##Potential Uses 223 224 ####For application development 225 226 Cloud Rocker gives a fast-feedback, production-like Cloud Foundry environment on a developer's machine. Make a change, *rock up*, rinse, repeat. When you're finished, just *rock off*. 227 228 ####For buildpack development 229 230 Cloud Rocker gives a fast-feedback environment for iterating on buildpacks. Buildpacks are stored in $CLOUDROCKER_HOME(default ~/cloudrocker)/buildpacks and can be edited directly. 231 232 ####For continuous integration 233 234 Deploying Cloud Rocker to your CI server means you can quickly get feedback about your Cloud Foundry applications. 235 236 ####For deploying applications to non-Cloud-Foundry environments 237 238 If you aren't fortunate enough to work in an organisation with access to a proper PaaS such as Cloud Foundry - you can still use Cloud Foundry's buildpacks, via Cloud Rocker, to build applications. You will need to host the containers in an IaaS+ offering, such as [Kubernetes](https://github.com/GoogleCloudPlatform/kubernetes) or [Shipyard](https://github.com/shipyard/shipyard). IaaS+ systems leave the responsibility with the user to *rock* themselves. 239 240 ##Developing Cloud Rocker 241 242 Development is against the 'develop' branch, promoted to 'master' by [Concourse](http://concourse.ci/). 243 244 There is a public tracker for this project [here](https://www.pivotaltracker.com/projects/1119430). 245 246 ##FAQ 247 248 #####Why have you built Cloud Rocker? 249 250 Cloud Foundry, at a high level, has two responsibilities for applications: *staging* - so they are ready to be run, and then - *running* them. [Decker](http://www.cloudcredo.com/decker-docker-cloud-foundry/) brought Cloud Foundry's *running* experience to container developers. Cloud Rocker brings the Cloud Foundry *staging* experience to application developers. By separating these responsibilities we can discuss the right way to build containers, and the right way to run them. 251 252 As a [Cloud Foundry Community Advisory Board](http://cloudfoundry.org/about/index.html) member - anything I can do to illustrate the great experience Cloud Foundry brings to developers is worthwhile. I think everybody benefits from fast-feedback and small batch sizes. Get code into a production-like environment as soon as possible. Let's iterate faster. 253 254 #####How is Cloud Rocker different to Slugbuilder, Building, Buildstep, etc? 255 256 Cloud Rocker uses the Cloud Foundry components as far as possible to provide a production-like Cloud Foundry environment to developers. 257 258 #####How is this different to [Decker](http://www.cloudcredo.com/decker-docker-cloud-foundry/)? 259 260 [Decker](http://www.cloudcredo.com/decker-docker-cloud-foundry/) is about running containers in a remote Cloud Foundry. Cloud Rocker is about running Cloud Foundry applications in local containers. 261 262 #####How is this different to [BOSH-Lite](https://github.com/cloudfoundry/bosh-lite)? 263 264 [BOSH-Lite](https://github.com/cloudfoundry/bosh-lite) is a fantastic development environment for BOSH developers. Cloud Rocker is for application developers. 265 266 #####How is this different to Micro Cloud Foundry? 267 268 MCF has been defunct since Cloud Foundry v1, and even back then it ate a considerable amount of resources. Cloud Rocker runs on any machine capable of running Docker, only consuming the resources necessary to stage and run the application. 269 270 #####Just how 'production-like' is this? 271 272 Cloud Rocker attempts to use the same components as Cloud Foundry's 'Diego'. 273 274 The base filesystem is exactly the same as a Cloud Foundry container. 275 276 Environment variables are currently handled in a different manner to CF. File locations and user mapping are also slightly different, which may cause subtle issues. Cloud Rocker is under development to bridge this gap. 277 278 #####How do I enter the running container to 'poke around' in the shell? 279 280 We will be automating this process, for now use [nsenter](https://github.com/jpetazzo/nsenter). 281 282 #####Why can't I use my boot2docker setup on win/mac, not vagrant? 283 284 Feel free to try Cloud Rocker with boot2docker, and good luck with the volume mounts. 285 286 #####Can I use a non-default base container image? 287 288 By default the Cloud Foundry *cflinuxfs version 2-1.11.0* image is used. You can choose to download a different base container image using the $ROCKER_ROOTFS_URL environment variable. e.g. 289 ```ROCKER_ROOTFS_URL=https://s3.amazonaws.com/blob.cfblob.com/978883d5-2e4d-495b-8aec-fc7c7e2988ad rock this``` 290 291 #####What about 'Error response from daemon: Conflict, The name cloudrocker-runtime is already assigned to 7a519360a3d3. You have to delete (or rename) that container to be able to assign cloudrocker-runtime to a container again.'? 292 293 This is what happens when good Cloud Rockers turn bad. Simply run: 294 295 ```$ docker rm cloudrocker-runtime``` 296 297 We will automate this when we have a better understanding of all the scenarios in which it occurs. 298 299 #####Did you only create this project so you could have fun making endless *double entendres* in the README? 300 301 No. I enjoyed the portmanteau too. 302 303 ##A message from our sponsors. 304 305 If you've read this far you've demonstrated a remarkable level of tenacity. [CloudCredo](http://www.cloudcredo.com/) are recruiting, and would [like to hear from you](http://www.cloudcredo.com/contact-us/).