<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Andrew Smithson</title>
    <description>The latest articles on DEV Community by Andrew Smithson (@crshnburn).</description>
    <link>https://dev.to/crshnburn</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F25494%2F23e661bb-d82e-449d-a5d9-0d47321ee86e.jpg</url>
      <title>DEV Community: Andrew Smithson</title>
      <link>https://dev.to/crshnburn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/crshnburn"/>
    <language>en</language>
    <item>
      <title>How I built a multi-arch image to run in zCX</title>
      <dc:creator>Andrew Smithson</dc:creator>
      <pubDate>Sat, 25 Jan 2020 21:21:37 +0000</pubDate>
      <link>https://dev.to/crshnburn/how-i-built-a-multi-arch-image-to-run-in-zcx-c09</link>
      <guid>https://dev.to/crshnburn/how-i-built-a-multi-arch-image-to-run-in-zcx-c09</guid>
      <description>&lt;p&gt;The latest version of z/OS (2.4) has added a really cool new feature called &lt;a href="https://www.ibm.com/support/z-content-solutions/container-extensions/"&gt;&lt;strong&gt;z/OS Container Extensions&lt;/strong&gt;&lt;/a&gt; (zCX) which allows you to run Docker containers built for Linux on Z alongside existing z/OS applications on the same LPAR. Having got access to a system I was keen to try and get a simple Liberty application running to try it out.&lt;/p&gt;

&lt;p&gt;I already had the Dockerfile and all the components on my local machine ready to build a local image so needed to convert that into a multi-arch image build workflow which could then be pushed to a local registry and run on the zCX appliance. This seemed easier that trying to recreate my development environment on the remote machine and running the Docker commands locally there.&lt;/p&gt;

&lt;p&gt;Needing to keep everything in house I needed an image registry to store the multi-arch images. This is easy to set-up for development testing by running a container containing the registry itself. Issuing the following command in the zCX instance brings up the registry&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -d -p 5000:5000 --restart=always ibmcom/registry-s390x:2.6.2.5
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;(Note: there isn’t an image tagged with &lt;code&gt;latest&lt;/code&gt; so ensure you add a version onto the image name)&lt;/p&gt;

&lt;p&gt;Building multi-arch images is possible with the latest version of Docker Desktop that I had on my laptop, just so long as I had the experimental features turned on. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--t1_vMK6s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ae0abtjwg9h2yyqccgnw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--t1_vMK6s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ae0abtjwg9h2yyqccgnw.png" alt="Docker preferences with experimental enabled"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With all this in place the &lt;a href="https://docs.docker.com/engine/reference/commandline/buildx/"&gt;&lt;code&gt;docker buildx&lt;/code&gt;&lt;/a&gt; group of commands is available which does all the work for us.&lt;/p&gt;

&lt;p&gt;As the registry I created was a simple development one with no security, the image builder needed to be configured to know that http should be used for communication with it rather than https. This configuration is managed in a toml configuration file which I needed to create.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="nn"&gt;[registry.”zcxmachine:5000”]&lt;/span&gt;
  &lt;span class="py"&gt;http&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;(Note: I had to use spaces to indent the properties as tabs didn’t seem to work)&lt;/p&gt;

&lt;p&gt;Now it was time to get the builder ready to build the image. The default builder will only create images for your local machine so I had to create a new one using the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker buildx create --name mybuilder --config=/path/to/config.toml
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once this completed then it needed to be set as the one to use.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker buildx use mybuilder
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Alternatively I could have added the &lt;code&gt;--use&lt;/code&gt; flag to the create command to create and set as default in one go.&lt;/p&gt;

&lt;p&gt;The builder then needed to be initialised&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker buildx inspect —bootstrap
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Checking output showed the platforms that can now be built for, which includes linux/s390x&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[+] Building 7.4s (1/1) FINISHED
 =&amp;gt; [internal] booting buildkit                                                                7.3s
 =&amp;gt; =&amp;gt; pulling image moby/buildkit:buildx-stable-1                                             3.0s
 =&amp;gt; =&amp;gt; creating container buildx_buildkit_mybuilder0                                           4.3s
Name:   mybuilder
Driver: docker-container

Nodes:
Name:      mybuilder0
Endpoint:  unix:///var/run/docker.sock
Status:    running
Platforms: linux/amd64, linux/arm64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now it was possible to build the image and push it to the local registry. So in the directory containing the Docker file I ran this command which specified the platforms to build for and to push the resulting images to the registry.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker buildx build --platform linux/amd64,linux/s390x -t zcxmachine:5000/image:latest . --push
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With the image now successfully built and pushed to the registry it could be run on the zCX appliance in the standard way.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run localhost:5000/image:latest
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now that I’ve managed to build an image off the machine where the containers need to run the next step will be building this into a CI/CD pipeline and automating as much as possible.&lt;/p&gt;

</description>
      <category>zos</category>
      <category>zcx</category>
      <category>docker</category>
      <category>buildx</category>
    </item>
  </channel>
</rss>
