|
1 |
| -# Docker Application to CNAB |
| 1 | +# Example: From Docker App to CNAB |
2 | 2 |
|
3 |
| -### Requirements |
| 3 | +Docker Apps are Docker’s implementation of the industry standard Cloud Native Application Bundle (CNAB). [CNAB](https://cnab.io/) is an industry specification put in place to facilitate the bundling, sharing, installing and managing of cloud-native apps that are not only made up of containers but also from such things as hosted databases, functions, etc. |
4 | 4 |
|
5 |
| -* [Docker Desktop](https://www.docker.com/products/docker-desktop) with Kubernetes enabled or any other Kubernetes cluster |
6 |
| -* Source code from this directory |
| 5 | +Docker App is designed to abstract as many CNAB specifics as possible, to provide users with a tool that is easy to use while alleviating the need to bother with the CNAB specification. |
7 | 6 |
|
8 |
| -### Examples |
| 7 | +This example will demonstrate that Docker App is actually leveraging CNAB. To learn more about CNAB, you can refer to the [CNAB specification](https://github.com/cnabio/cnab-spec). |
9 | 8 |
|
10 |
| -Show the details of the application with `inspect` |
11 | 9 |
|
12 |
| -```console |
13 |
| -$ docker app inspect |
14 |
| -hello 0.2.0 |
| 10 | +## App Definition |
15 | 11 |
|
16 |
| -Maintained by: garethr <someone@example.com> |
| 12 | +The App definition for this example is ready to use and can be found in the [hello.dockerapp](hello.dockerapp) directory in this folder. |
17 | 13 |
|
18 |
| -Sample app for DockerCon EU 2018 |
19 | 14 |
|
20 |
| -Service (1) Replicas Ports Image |
21 |
| ------------ -------- ----- ----- |
22 |
| -hello 1 8765 hashicorp/http-echo:0.2.3 |
| 15 | +## App Image |
23 | 16 |
|
24 |
| -Parameters (2) Value |
25 |
| --------------- ----- |
26 |
| -port 8765 |
27 |
| -text Hello DockerCon! |
| 17 | +Now we are going to build an App image from this App definition. |
| 18 | + |
| 19 | +```shell |
| 20 | +$ docker app build . -f hello.dockerapp -t myrepo/cnab-example:1.0.0 |
| 21 | +[+] Building 0.6s (6/6) FINISHED |
| 22 | +(...) (Build output) |
| 23 | +sha256:ee61121d6bff0266404cc0077599c1ef7130289fec721 |
| 24 | +``` |
| 25 | + |
| 26 | +*Note that a `bundle.json` file has been created in the `~/.docker/app/bundles/docker.io/myrepo/cnab-example/_tags/1.0.0` directory.* |
| 27 | + |
| 28 | +Open the open the `bundle.json` file in your favorite text editor and you'll see this is a [CNAB bundle](https://github.com/cnabio/cnab-spec). |
| 29 | + |
| 30 | +Copy the `bundle.json`file to your working directory, next to the `hello.dockerapp` App definition. |
| 31 | + |
| 32 | +```shell |
| 33 | +$ tree |
| 34 | +. |
| 35 | +├── bundle.json |
| 36 | +└── hello.dockerapp |
| 37 | + ├── docker-compose.yml |
| 38 | + ├── metadata.yml |
| 39 | + └── parameters.yml |
28 | 40 | ```
|
29 | 41 |
|
30 |
| -Install the application: |
| 42 | +## Running App |
31 | 43 |
|
32 |
| -```console |
33 |
| -$ docker app install |
| 44 | +### Run the App from an App image |
| 45 | + |
| 46 | +You can run this App using the `docker app run`command. |
| 47 | + |
| 48 | +```shell |
| 49 | +$ docker app run myrepo/cnab-example:1.0.0 --name mycnabexample |
| 50 | +Creating network mycnabexample_default |
| 51 | +Creating service mycnabexample_hello |
| 52 | +App "mycnabexample" running on context "default" |
34 | 53 | ```
|
35 | 54 |
|
36 |
| -Update the installation, demonstrating setting parameters: |
| 55 | +Get the list of running Apps using the `docker app ls` command. |
37 | 56 |
|
38 |
| -```console |
39 |
| -$ docker app update --set port=9876 --set text="hello DockerCon EU" hello |
| 57 | +```shell |
| 58 | +$ docker app ls |
| 59 | +RUNNING APP APP NAME LAST ACTION RESULT CREATED MODIFIED REFERENCE |
| 60 | +mycnabexample hello (0.2.0) install success 15 minutes ago 15 minutes ago docker.io/myrepo/cnab-example:1.0.0 |
40 | 61 | ```
|
41 | 62 |
|
42 |
| -Uninstall the application installation: |
| 63 | +Then remove the current running App. |
43 | 64 |
|
44 |
| -```console |
45 |
| -$ docker app uninstall hello |
| 65 | +```shell |
| 66 | +$ docker app rm mycnabexample |
| 67 | +Removing service mycnabexample_hello |
| 68 | +Removing network mycnabexample_default |
46 | 69 | ```
|
47 | 70 |
|
48 |
| -Demonstrate building a `bundle.json` for CNAB. |
49 |
| - |
50 |
| -```console |
51 |
| -$ docker app bundle |
52 |
| -Invocation image "hello:0.2.0-invoc" successfully built |
53 |
| -$ cat bundle.json |
54 |
| -{ |
55 |
| - "name": "hello", |
56 |
| - "version": "0.2.0", |
57 |
| - "description": "Sample app for DockerCon EU 2018", |
58 |
| - ... |
59 |
| -} |
| 71 | +### Run the App from a CNAB bundle |
| 72 | + |
| 73 | +To demonstrate that Docker App is an implementation of [CNAB](https://cnab.io/), it is also possible to directly run the `bundle.json` file (or any other CNAB bundle) using the `--cnab-bundle-json` experimental flag. |
| 74 | + |
| 75 | +*Note: To use this flag, you have to enable the experimental mode for the Docker CLI first.* |
| 76 | + |
| 77 | +Open the `~/.docker/config.json` file in a text editor and change the `"experimental"` field to `"enabled"`. |
| 78 | + |
| 79 | +Run your app passing a `bundle.json` file. |
| 80 | + |
| 81 | +```shell |
| 82 | +$ docker app run myrepo/cnab-example:1.0.0 --name mycnabexample --cnab-bundle-json bundle.json |
| 83 | +Creating network mycnabexample_default |
| 84 | +Creating service mycnabexample_hello |
| 85 | +App "mycnabexample" running on context "default" |
| 86 | +``` |
| 87 | + |
| 88 | +Get the list of running Apps using the `docker app ls` command. |
| 89 | + |
| 90 | +```shell |
| 91 | +$ docker app ls |
| 92 | +RUNNING APP APP NAME LAST ACTION RESULT CREATED MODIFIED REFERENCE |
| 93 | +mycnabexample hello (0.2.0) install success 15 minutes ago 15 minutes ago docker.io/myrepo/cnab-example:1.0.0 |
60 | 94 | ```
|
| 95 | + |
| 96 | +Inspect your running app using the `docker app inspect`command. |
| 97 | + |
| 98 | +```shell |
| 99 | +$ docker app inspect mycnabexample --pretty |
| 100 | +Running App: |
| 101 | + Name: mycnabexample |
| 102 | + Created: 1 minute ago |
| 103 | + Modified: 1 minute ago |
| 104 | + Revision: 01DT28SRQZF12FN5YFQ36XCBYS |
| 105 | + Last Action: install |
| 106 | + Result: success |
| 107 | + Ochestrator: swarm |
| 108 | + |
| 109 | +App: |
| 110 | + Name: hello |
| 111 | + Version: 0.2.0 |
| 112 | + |
| 113 | +Parameters: |
| 114 | + port: "8765" |
| 115 | + text: Hello! |
| 116 | + |
| 117 | +ID NAME MODE REPLICAS IMAGE PORTS |
| 118 | +c21wxj9ts08y mycnabexample_hello replicated 1/1 hashicorp/http-echo *:8765->5678/tcp |
| 119 | +``` |
| 120 | + |
| 121 | +Finally, remove the current running App. |
| 122 | + |
| 123 | +```shell |
| 124 | +$ docker app rm mycnabexample |
| 125 | +Removing service mycnabexample_hello |
| 126 | +Removing network mycnabexample_default |
| 127 | +``` |
0 commit comments