|
1 |
| -# app package |
| 1 | +# Docker Application Packages |
| 2 | + |
| 3 | +An *experimental* utility to help make Compose files more reusable and sharable. |
| 4 | + |
| 5 | + |
| 6 | +## The problem application packages solve |
| 7 | + |
| 8 | +Compose files do a great job of describing a set of related services. Not only are Compose files easy to write, they are generally easy to read as well. However, a couple of problems often emerge: |
| 9 | + |
| 10 | +1. You have several environments where you want to deploy the application, with small configuration differences |
| 11 | +2. You have lots of similar applications |
| 12 | + |
| 13 | +Fundamentally, Compose files are not easy to share between concerns. Docker Application Packages aim to solve these problems and make Compose more useful for development _and_ production. |
| 14 | + |
| 15 | +## Looking at an example |
| 16 | + |
| 17 | +Let's take the following Compose file. It launches an HTTP server which prints the specified text when hit on the configured port. |
| 18 | + |
| 19 | +```yaml |
| 20 | +version: '3.2' |
| 21 | +services: |
| 22 | + hello: |
| 23 | + image: hashicorp/http-echo |
| 24 | + command: ["-text", "hello world"] |
| 25 | + ports: |
| 26 | + - 5678:5678 |
| 27 | +``` |
| 28 | +
|
| 29 | +With `docker-app` installed let's create an Application Package based on this Compose file: |
| 30 | + |
| 31 | +```bash |
| 32 | +$ docker-app init hello |
| 33 | +$ ls |
| 34 | +docker-compose.yml |
| 35 | +hello.dockerapp |
| 36 | +``` |
| 37 | + |
| 38 | +We created a few files in the `.dockerapp` folder. Let's edit the `hello.dockerapp/settings.yml` and add the following default values for our application: |
| 39 | + |
| 40 | +```yaml |
| 41 | +port: 5678 |
| 42 | +text: hello development |
| 43 | +version: latest |
| 44 | +``` |
| 45 | + |
| 46 | +Then modify the Compose file in the `.dockerapp` folder, adding in the variables. |
| 47 | + |
| 48 | +```yaml |
| 49 | +version: '3.2' |
| 50 | +services: |
| 51 | + hello: |
| 52 | + image: hashicorp/http-echo:${version} |
| 53 | + command: ["-text", "${text}"] |
| 54 | + ports: |
| 55 | + - ${port}:5678 |
| 56 | +``` |
| 57 | + |
| 58 | +Finally you can test everything is working, by rendering the Compose file with the provided default values. |
| 59 | + |
| 60 | +``` |
| 61 | +$ docker-app render |
| 62 | +version: "3.2" |
| 63 | +services: |
| 64 | + hello: |
| 65 | + command: |
| 66 | + - -text |
| 67 | + - hello development |
| 68 | + image: hashicorp/http-echo:latest |
| 69 | + ports: |
| 70 | + - mode: ingress |
| 71 | + target: 5678 |
| 72 | + published: 5678 |
| 73 | + protocol: tcp |
| 74 | +``` |
| 75 | +
|
| 76 | +You can then use that Compose file like any other. You could save it to disk or pipe it straight to `docker stack` or `docker-compose` to launch the application. |
| 77 | +
|
| 78 | +``` |
| 79 | +$ docker-app render | docker-compose -f - up |
| 80 | +``` |
| 81 | +
|
| 82 | +This is where it gets interesting. We can override those settings at runtime, using the `--set` option. Let's specify different option and run `render` again: |
| 83 | +
|
| 84 | +``` |
| 85 | +$ docker-app render --set version=0.2.3 --set port=4567 --set text="hello production" |
| 86 | +version: "3.2" |
| 87 | +services: |
| 88 | + hello: |
| 89 | + command: |
| 90 | + - -text |
| 91 | + - hello production |
| 92 | + image: hashicorp/http-echo:0.2.3 |
| 93 | + ports: |
| 94 | + - mode: ingress |
| 95 | + target: 5678 |
| 96 | + published: 4567 |
| 97 | + protocol: tcp |
| 98 | +``` |
| 99 | +
|
| 100 | +If you prefer you can create a standalone configuration file to store those settings. Let's create `prod.yml` with the following contents: |
| 101 | +
|
| 102 | +```yaml |
| 103 | +version: 0.2.3 |
| 104 | +text: hello production |
| 105 | +port: 4567 |
| 106 | +``` |
| 107 | + |
| 108 | +You can then run using that configuration file like so: |
| 109 | + |
| 110 | +``` |
| 111 | +$ docker-app render -f prod.yml |
| 112 | +``` |
| 113 | + |
| 114 | + |
| 115 | +## Integrating with Helm |
| 116 | + |
| 117 | +`docker-app` comes with a few other helpful commands as well, in particular the ability to create Helm Charts from your Docker Applications. This can be useful if you're adopting Kubernetes, and standardising on Helm to manage the lifecycle of your application components, but want to maintain the simplicity of Compose when writing you applications. This also makes it easy to run the same applications locally just using Docker, if you don't want to be running a full Kubernetes cluster. |
| 118 | + |
| 119 | +``` |
| 120 | +$ docker-app helm |
| 121 | +``` |
| 122 | + |
| 123 | +This will create a folder, `<my-applcation-name>.chart`, in the current directory. The folder contains the required `Chart.yaml` file and templates describing the `stack` Kubernetes object based on the Compose file in your application. |
| 124 | + |
| 125 | +_Note that this requires the Compose Kubernetes controller available in Docker for Windows and Docker for Mac, and in Docker Enterprise Edition._ |
| 126 | + |
| 127 | + |
| 128 | +## Next steps |
| 129 | + |
| 130 | +We have lots of ideas for making Compose-based applications easier to share and reuse, and making applications a first-class part of the Docker toolchain. Please let us know what you think about this initial release and about any of the ideas below: |
| 131 | + |
| 132 | +* Saving Docker applications as Docker images, including sharing them on Docker Hub |
| 133 | +* Introducing environments to the settings file |
| 134 | +* Docker images which launch the application when run |
| 135 | +* Built-in commands for running applications |
| 136 | +* Saving required images into the application artifact to support offline installation |
| 137 | +* Automatically validating Compose files against the schema for the specified version |
| 138 | +* Signing applications with notary |
| 139 | + |
| 140 | + |
| 141 | +## Usage |
| 142 | + |
| 143 | +`docker-app` is currently available only as source code for you to build yourself, binaries will be published soon. If the experiment proves successful we'll move this functionality into the main Docker CLI. |
2 | 144 |
|
3 | 145 | ```
|
4 |
| -$ lunchbox |
| 146 | +$ docker-app |
5 | 147 | Docker App Packages
|
6 | 148 |
|
7 | 149 | Usage:
|
8 | 150 | docker-app [command]
|
9 | 151 |
|
10 | 152 | Available Commands:
|
11 |
| - build Compile an app package from locally available data |
12 |
| - deploy Deploy the specified app on the connected cluster |
13 | 153 | helm Render the Compose file for this app as an Helm package
|
14 | 154 | help Help about any command
|
15 | 155 | init Initialize an app package in the current working directory
|
16 | 156 | inspect Retrieve metadata for a given app package
|
17 |
| - load Load an app from docker |
18 |
| - pack Pack this app as a single file |
19 |
| - pull Pull an app from a registry |
20 |
| - push Push the application to a registry |
21 | 157 | render Render the Compose file for this app
|
22 |
| - save Save the application to docker (in preparation for push) |
23 |
| - unpack Unpack the app to expose the content |
| 158 | + version Print version information |
24 | 159 |
|
25 | 160 | Flags:
|
26 | 161 | -h, --help help for docker-app
|
|
0 commit comments