<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alexander Akhmetov on Medium]]></title>
        <description><![CDATA[Stories by Alexander Akhmetov on Medium]]></description>
        <link>https://medium.com/@alex.akhmetov?source=rss-f8ad97394dc5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1C8qXt_238-tpFSBkLd_Rw.jpeg</url>
            <title>Stories by Alexander Akhmetov on Medium</title>
            <link>https://medium.com/@alex.akhmetov?source=rss-f8ad97394dc5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 09:00:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alex.akhmetov/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Docker Application Packages in a Nutshell]]></title>
            <link>https://medium.com/elements/docker-application-packages-83c141d8cb0f?source=rss-f8ad97394dc5------2</link>
            <guid isPermaLink="false">https://medium.com/p/83c141d8cb0f</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containerization]]></category>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[yaml]]></category>
            <category><![CDATA[dockercon]]></category>
            <dc:creator><![CDATA[Alexander Akhmetov]]></dc:creator>
            <pubDate>Tue, 22 Jan 2019 09:45:44 GMT</pubDate>
            <atom:updated>2019-05-29T10:15:52.140Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NyExPzjOGaVpRBEcBkpkjQ.jpeg" /><figcaption>Photo by <a href="https://www.pexels.com/@tomfisk">Tom Fisk</a> on <a href="https://www.pexels.com/photo/aerial-view-of-cargo-ship-1554646/">Pexels</a></figcaption></figure><p>A few months ago, at DockerCon US 2018, an experimental tool was announced: <a href="https://blog.docker.com/2018/12/docker-app-and-cnab/"><strong>docker-app</strong></a>. This tool, as Docker describes it, is built to make docker-compose files reusable and shareable.</p><p>In this article, we will create a Docker application package with a back-end service and a database and share it on Docker Hub. Also, we will see how it works internally. As an example, I use the <a href="https://github.com/elementsinteractive/flask-graphql-neo4j">flask-graphql-neo4j application</a> <a href="https://medium.com/elements/diving-into-graphql-and-neo4j-with-python-244ec39ddd94">created by my colleagues Charles and Yahia</a>.</p><h3>docker-compose</h3><p>First, let’s have a look at a simple docker-compose file.</p><blockquote>Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services.</blockquote><p>There is a configuration file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8988ac9f3a79b3ef5678008aaf3c3cf8/href">https://medium.com/media/8988ac9f3a79b3ef5678008aaf3c3cf8/href</a></iframe><p>The file describes two services: an application and a database. To start these services on another computer, you must have a copy of the file on it.</p><p>If you need different parameters for different environments or customize some service, you have to <a href="https://docs.docker.com/compose/extends/">extend</a> the configuration file and maintain multiple compose files. Alternatively, you could use <a href="https://www.ansible.com/">Ansible</a>, but that would deserve an article of its own.</p><p>Another problem is when we have a few containers in one application, we can’t just run <strong>docker pull</strong> or <strong>docker push</strong> anymore. <em>docker-compose.yml </em>describes relations between containers, stores configuration and you have to have a copy of the file to start the service. However, this can be done much easier and that is where the <strong>docker-app</strong> comes to help us.</p><h3>docker-app</h3><p>This example uses Docker Swarm and assumes that you have <a href="https://docs.docker.com/engine/reference/commandline/swarm_init/">installed</a> and configured it.</p><p><strong>docker-app (</strong>i<a href="https://github.com/docker/app#installation">nstallation instructions</a>) can build an image from a docker-compose file, push it into a registry and then you can share it as a single image URL.</p><p>Also, it allows to define variables and metadata for the application and works with Docker Swarm or Kubernetes. It even can <a href="https://github.com/docker/app/blob/9b25b4fef2c6b826f09c07716a018456831c8168/README.md#integrating-with-helm">create helm charts</a> for your Kubernetes cluster!</p><p>docker-app goals:</p><ul><li>Make Compose-based applications shareable on Docker Hub and <a href="https://docs.docker.com/ee/dtr/">Docker Trusted Registry</a></li><li>Support a stronger separation of concerns between the application description and per-environment settings</li></ul><p>Let’s create our docker application package:</p><pre><strong>$</strong> docker-app init <em>flask-graphql-neo4j-app</em></pre><p>The command above creates a directory <strong>flask-graphql-neo4j-app</strong> with three files inside:</p><pre><strong>$ tree flask-graphql-neo4j-app.dockerapp</strong><em><br>  <br>  </em>flask-graphql-neo4j-app.dockerapp<br>  ├── docker-compose.yml<br>  ├── metadata.yml<br>  └── settings.yml</pre><p>The first one is a regular docker-compose file, let’s write our configuration there:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/34a17ebeed40788462fdd9c14a4f00cb/href">https://medium.com/media/34a17ebeed40788462fdd9c14a4f00cb/href</a></iframe><p>As you can see, this docker-compose file has variables: ${app.host}, ${app.port}, etc. They look almost like environment variables which you can use in any docker-compose file, but docker-app<strong> </strong>gets values for them from the <em>settings.yml </em>file.</p><p>Since docker-app deploys your application to Docker Swarm or Kubernetes, you can use the <a href="https://docs.docker.com/compose/compose-file/#deploy">deploy</a> attribute in the compose file to set limits for your containers.</p><p>A default value for each variable must be defined in the <em>settings.yml (</em>later we will have a look how to override them<em>)</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/002271296ad8ba261160c5b932da8714/href">https://medium.com/media/002271296ad8ba261160c5b932da8714/href</a></iframe><p>The <em>medatata.yml</em> file contains primary information about, the application:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2bfc406644006348e0962cf4d7a6fe0/href">https://medium.com/media/f2bfc406644006348e0962cf4d7a6fe0/href</a></iframe><h4>Validation</h4><p>So, we have a <strong>flask-graphql-neo4j-app.dockerapp<em> </em></strong>directory with three files inside. It’s our application package description, and we can check if it has any errors and inspect what’s inside:</p><pre><strong>$</strong> <strong>docker-app validate; echo $?</strong><br>  0</pre><pre><strong>$</strong> <strong>docker-app inspect</strong></pre><pre>flask-graphql-neo4j-app 0.1.0</pre><pre>Maintained by: Alexander Akhmetov &lt;aleksandr.akhmetov@elements.nl&gt;</pre><pre>Services (2) Replicas Ports Image<br>------------ -------- ----- -----<br>app          3        8080  elementsinteractive/flask-graphql-neo4j:latest<br>neo4j        1              neo4j:3.5.0</pre><pre>Volume (1)<br>----------<br>neo4j-data</pre><pre>Settings (13)       Value<br>-------------       -----<br>app.deploy.replicas 3<br>app.host            0.0.0.0<br>app.limits.cpu      0.25<br>app.limits.memory   50M<br>app.maintainers.0   map[name:Alexander Akhmetov email:aleksandr.akhmetov@elements.nl]<br>app.name            flask-graphql-neo4j-app<br>app.namespace       elementsinteractive<br>app.port            8080<br>app.version         0.1.0<br>neo4j.auth          none<br>neo4j.limits.cpu    0.25<br>neo4j.limits.memory 50M<br>neo4j.port          7687<br>------------------------------------------------------------</pre><h4>Deployment</h4><p>Now let’s start the application and make some requests to it:</p><pre><strong>$</strong> <strong>docker-app deploy</strong></pre><pre>  Creating network flask-graphql-neo4j-app_default<br>  Creating service flask-graphql-neo4j-app_app<br>  Creating service flask-graphql-neo4j-app_neo4j</pre><p><strong>deploy </strong>command creates all necessary resources for the app: network, services, volumes, etc.</p><blockquote><strong>orchestrator</strong> parameter of the <strong>docker-app</strong> <strong>deploy </strong>command<strong> </strong>allows you to choose between Kubernetes and Swarm for the deployment process</blockquote><p>The application is running!</p><p>You can see this with <strong>docker stack</strong> <strong>ls</strong> and <strong>docker service ls</strong> commands:</p><pre><strong>$</strong> <strong>docker stack ls</strong></pre><pre>  NAME                      SERVICES            ORCHESTRATOR<br>  flask-graphql-neo4j-app   2                   Swarm</pre><p>We just created one service with four containers inside: three back-end containers and one DB container according to <em>docker-compose.yml (</em>you can check this with <strong>docker service ls</strong><em>)</em>, and we can make an HTTP request to the application to be sure that it works fine:</p><pre><strong>$</strong> <strong>curl -X POST</strong> http://127.0.0.1:8080/graphql <strong>\</strong><br>       <strong>-H</strong> &quot;Content-Type: application/json&quot; <strong>\</strong><br>       <strong>--data</strong> &#39;<em>{ &quot;query&quot;: &quot;mutation {c1:create_customer(name: \&quot;aleksandr\&quot; email: \&quot;aleksandr.akhmetov@elements.nl\&quot;) {customer{name} success}}&quot;}</em>&#39; <strong>|</strong> <strong>python -m json.tool</strong></pre><pre><br>{<br>    &quot;data&quot;: {<br>        &quot;c1&quot;: {<br>            &quot;customer&quot;: {<br>                &quot;name&quot;: &quot;aleksandr&quot;<br>            },<br>            &quot;success&quot;: true<br>        }<br>    }<br>}</pre><h4>Settings</h4><p><strong>docker-app</strong> allows us to override default settings. Just create a new yml file and put new values inside, for example, <em>production.yml</em>:</p><pre><strong>$</strong> <strong>cat &gt; production.yml</strong><br>  app:<br>    port: 9090</pre><pre><strong>$</strong> <strong>docker-app -f production.yml inspect | grep app.port</strong><br>  app.port            9090</pre><pre><strong>$</strong> <strong>docker-app inspect | grep app.port</strong><br>  app.port            8080</pre><p>You don’t need to copy all data from the<em> settings.yml</em>, just override necessary variables.</p><h4>Sharing</h4><p>It’s time to push the application to the Docker Hub. Run <strong>docker-app push </strong>command, which uses namespace, name and version parameters from the manifest file to build and push an image.</p><p>In our case it’s elementsinteractive/flask-graphql-neo4j-app:0.1.0:</p><pre><strong>$ docker-app push</strong></pre><pre>sha256:c4c602cd06c34c6b440897d49abc489d015e96b3cca05e68139dd5557f57456e</pre><p>You can use docker-app without Kubernetes or Swarm too. Just run <strong>docker-app render </strong>command and it will return a rendered content for a <em>docker-compose.yml</em>:</p><pre><strong>$</strong> docker-app render | docker-compose -f - up</pre><h3>How does it work?</h3><p>OK, we’ve just created and pushed to the registry a new Docker application package. We have only one image, but it starts many containers and even with some default parameters. To investigate how it is possible, let’s go a little bit deeper.</p><h4>Image layers</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QRDnE3QIFoEeGfRQZh9iaA.png" /><figcaption><strong>ubuntu:18.04 </strong>layers inspected by <a href="https://github.com/wagoodman/dive">dive</a></figcaption></figure><p>A Docker image has a bunch of layers. For each command in the <em>Dockerfile</em>, Docker generates a layer with all new files. So, each layer is a set of differences from the previous one. Then <strong>docker push</strong> command uploads them to a registry if it does not have them yet. You can read more about layers in the <a href="https://docs.docker.com/storage/storagedriver/">documentation</a>.</p><p>Let’s download our new image and see what’s inside.</p><pre><strong>$ docker pull elementsinteractive/flask-graphql-neo4j-app.dockerapp:0.1.0</strong></pre><pre>0.1.0: Pulling from elementsinteractive/flask-graphql-neo4j-app.dockerapp<br>386325240c45: Pulling fs layer<br><strong>operating system is not supported</strong></pre><p>Oops, something is wrong! If you enable experimental features (put &quot;experimental&quot;: &quot;enabled&quot; to <em>~/.docker/config.json</em>) you can list all supported operating systems and architectures for the image:</p><pre><strong>$ docker manifest inspect -v elementsinteractive/flask-graphql-neo4j-app.dockerapp:0.1.0</strong></pre><pre>{<br>    ...<br>    &quot;Descriptor&quot;: {<br>        ...<br>        &quot;platform&quot;: {<br>            &quot;<strong>architecture</strong>&quot;: &quot;<strong>config</strong>&quot;,<br>            &quot;<strong>os</strong>&quot;: &quot;<strong>config</strong>&quot;<br>        }<br>    },<br>    &quot;SchemaV2Manifest&quot;: {...}<br>}</pre><p>We see that value for the <strong>os </strong>and<strong> architecture </strong>keys<strong> </strong>is <strong>config</strong>. That’s why docker can’t pull this image and returns the operating system is not supported error.</p><p>To download an image <strong>docker pull</strong> command retrieves a <a href="https://docs.docker.com/edge/engine/reference/commandline/manifest/"><em>manifest</em></a> for it. It contains information about the image and its layers. Using this information it downloads and unpacks all necessary data.</p><p>The same mechanism is used to store your application package. When you run a docker-app deploy {<em>image_name</em>} command, it retrieves the manifest for the image. In contrast to a regular image, this one is incompatible with docker commands and <strong>works only with docker-app</strong>.<strong> </strong>It also has a special layer, which is a <em>tar.gz</em> archive with your application package files (<em>docker-compose.yml</em>, <em>manifest.yml</em>, <em>settings.yml</em>), and it uses these files to start your services.</p><p>You can download the first layer of the image with <a href="https://gist.github.com/alexander-akhmetov/2fd728549deebae768305670319d8f29">this script</a> and check this by yourself:</p><pre><strong>$</strong> <strong>python3.7 download_blob.py</strong></pre><pre>  Getting content for elementsinteractive/flask-graphql-neo4j-app.dockerapp:0.1.0<br>  File downloaded: blob.tar.gz</pre><pre><strong>$ tar -tf blob.tar.gz</strong><br>  metadata.yml<br>  docker-compose.yml<br>  settings.yml</pre><p>That’s it! You can try to deploy the example application using docker-app right now from the Docker Hub :-)</p><pre><strong>$</strong> docker-app deploy elementsinteractive/flask-graphql-neo4j-app:0.1.0</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83c141d8cb0f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/elements/docker-application-packages-83c141d8cb0f">Docker Application Packages in a Nutshell</a> was originally published in <a href="https://medium.com/elements">Elements blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>