github.com/docker/app@v0.9.1-beta3.0.20210611140623-a48f773ab002/examples/cnab-simple/README.md (about)

     1  # Example: From Docker App to CNAB
     2  
     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  
     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. 
     6  
     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).
     8  
     9  
    10  ## App Definition
    11  
    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.
    13  
    14  
    15  ## App Image
    16  
    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
    40  ```
    41  
    42  ## Running App
    43  
    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"
    53  ```
    54  
    55  Get the list of running Apps using the `docker app ls` command.
    56  
    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
    61  ```
    62  
    63  Then remove the current running App.
    64  
    65  ```shell
    66  $ docker app rm mycnabexample
    67  Removing service mycnabexample_hello
    68  Removing network mycnabexample_default
    69  ```
    70  
    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
    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  ```