<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>registry on Andrew Beaton</title>
    <link>https://andrewbeaton.net/tags/registry/</link>
    <description>Recent content in registry on Andrew Beaton</description>
    <image>
      <title>Andrew Beaton</title>
      <url>https://andrewbeaton.net/me.jpeg</url>
      <link>https://andrewbeaton.net/me.jpeg</link>
    </image>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Fri, 09 Jun 2023 00:00:00 +0000</lastBuildDate><atom:link href="https://andrewbeaton.net/tags/registry/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Create and Publish a Docker Image to GitHub&#39;s Container Registry using GitHub Actions.</title>
      <link>https://andrewbeaton.net/posts/2023/06/docker-github-registry-actions/</link>
      <pubDate>Fri, 09 Jun 2023 00:00:00 +0000</pubDate>
      
      <guid>https://andrewbeaton.net/posts/2023/06/docker-github-registry-actions/</guid>
      <description>A guide on how to publish a Docker image to GitHub&amp;#39;s Container Registry using GitHub Actions.</description>
      <content:encoded><![CDATA[<h2 id="introduction">Introduction</h2>
<p>In this tutorial, I will walk you through the process of publishing a Docker image to GitHub&rsquo;s Container Registry using GitHub Actions. By using GitHub Actions, you can automate the build and publish process, making it easier to distribute your Docker images.</p>
<h2 id="prerequisites">Prerequisites</h2>
<p>Before getting started, make sure you have the following:</p>
<ol>
<li>A GitHub account.</li>
<li>A Dockerfile that describes your application&rsquo;s dependencies and build instructions.</li>
<li>A GitHub repository where you want to publish your Docker image.</li>
</ol>
<h2 id="step-1-set-up-github-actions-workflow">Step 1: Set up GitHub Actions workflow</h2>
<p>GitHub Actions allow you to automate tasks by creating workflows.</p>
<p>To publish a Docker image, we&rsquo;ll create a workflow file named <code>publish.yml</code>.</p>
<p>Create a new directory called <code>.github/workflows</code> in the root of your repository, if it doesn&rsquo;t already exist.</p>
<p>Inside this directory, create a new file named <code>publish.yml</code> and add the following content:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">name</span>: <span style="color:#ae81ff">Publish Docker Image</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">on</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">push</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">branches</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#ae81ff">main</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">jobs</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">build-and-publish</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">runs-on</span>: <span style="color:#ae81ff">ubuntu-latest</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">steps</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">name</span>: <span style="color:#ae81ff">Checkout code</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">actions/checkout@v2</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">name</span>: <span style="color:#ae81ff">Login to GitHub Container Registry</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">docker/login-action@v1</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">with</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">registry</span>: <span style="color:#ae81ff">ghcr.io</span>
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">username</span>: <span style="color:#ae81ff">${{ github.actor }}</span>
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">password</span>: <span style="color:#ae81ff">${{ secrets.GITHUB_TOKEN }}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">name</span>: <span style="color:#ae81ff">Build and push Docker image</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">docker/build-push-action@v2</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">with</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">context</span>: <span style="color:#ae81ff">.</span>
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">push</span>: <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">tags</span>: <span style="color:#ae81ff">ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:${{ github.sha }}</span>
</span></span></code></pre></div><p>This workflow will trigger whenever you push changes to the <code>main</code> branch. It checks out the code, logs in to GitHub&rsquo;s Container Registry using your GitHub credentials, and builds and pushes the Docker image to the registry.</p>
<h2 id="step-2-configure-the-dockerfile">Step 2: Configure the Dockerfile</h2>
<p>In your repository, create a file named <code>Dockerfile</code> and add the necessary instructions to build your Docker image. Here&rsquo;s an example <code>Dockerfile</code> for a Node.js application:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-Dockerfile" data-lang="Dockerfile"><span style="display:flex;"><span><span style="color:#66d9ef">FROM</span><span style="color:#e6db74"> node:14</span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010"></span><span style="color:#66d9ef">WORKDIR</span><span style="color:#e6db74"> /app</span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010"></span><span style="color:#66d9ef">COPY</span> package.json package-lock.json ./<span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010"></span><span style="color:#66d9ef">RUN</span> npm ci --only<span style="color:#f92672">=</span>production<span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010"></span><span style="color:#66d9ef">COPY</span> app.js .<span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010"></span><span style="color:#66d9ef">CMD</span> [<span style="color:#e6db74">&#34;node&#34;</span>, <span style="color:#e6db74">&#34;app.js&#34;</span>]<span style="color:#960050;background-color:#1e0010">
</span></span></span></code></pre></div><p>Make sure to modify the <code>Dockerfile</code> to suit your application&rsquo;s requirements.</p>
<h2 id="step-3-push-changes-to-your-repository">Step 3: Push changes to your repository</h2>
<p>Commit and push the <code>Dockerfile</code>, <code>publish.yml</code>, and any other files you may have modified to your repository.</p>
<h2 id="step-4-monitor-the-workflow-execution">Step 4: Monitor the workflow execution</h2>
<p>After pushing the changes, navigate to the &ldquo;Actions&rdquo; tab in your GitHub repository. You should see the workflow you created (&ldquo;Publish Docker Image&rdquo;) listed there. Click on it to monitor the execution.</p>
<h2 id="step-5-verify-the-docker-image-in-github-container-registry">Step 5: Verify the Docker image in GitHub Container Registry</h2>
<p>Once the workflow execution is complete, go to the &ldquo;Packages&rdquo; tab in your GitHub repository. You should see your Docker image listed there. Click on it to view the details.</p>
<h2 id="summary">Summary</h2>
<p>You have successfully published a Docker image to GitHub&rsquo;s Container Registry using GitHub Actions. By automating this process, you can easily distribute your Docker images and ensure consistent deployment across different environments. GitHub Actions provides a powerful platform for automating various tasks in your development workflow, saving you time and effort.</p>
]]></content:encoded>
    </item>
    
    <item>
      <title>Create and Publish a Docker Image to GitHub&#39;s Container Registry</title>
      <link>https://andrewbeaton.net/posts/2023/06/docker-github-container-registry/</link>
      <pubDate>Thu, 08 Jun 2023 00:00:00 +0000</pubDate>
      
      <guid>https://andrewbeaton.net/posts/2023/06/docker-github-container-registry/</guid>
      <description>A guide on how to publish a Docker image to GitHub&amp;#39;s Container Registry using Docker Push.</description>
      <content:encoded><![CDATA[<h2 id="introduction">Introduction</h2>
<p>Docker has become an essential tool in modern software development, enabling easy and efficient containerisation of applications. GitHub&rsquo;s Container Registry provides a convenient way to store and manage Docker images within the GitHub ecosystem.</p>
<p>In this tutorial, we will walk through the process of creating, editing, and publishing a Docker image to GitHub&rsquo;s Container Registry.</p>
<h2 id="prerequisites">Prerequisites</h2>
<p>Before we begin, ensure that you have the following:</p>
<ol>
<li>A GitHub account</li>
<li>Docker installed on your local machine</li>
<li>Basic familiarity with Docker commands</li>
</ol>
<h2 id="step-1-create-a-dockerfile">Step 1: Create a Dockerfile</h2>
<p>The first step is to create a Dockerfile, which defines the instructions to build your Docker image. Open a text editor and create a new file called <code>Dockerfile</code>. Here&rsquo;s a basic example:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-Dockerfile" data-lang="Dockerfile"><span style="display:flex;"><span><span style="color:#75715e"># Use a base image</span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010"></span><span style="color:#66d9ef">FROM</span><span style="color:#e6db74"> ubuntu:latest</span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010"></span><span style="color:#75715e"># Set the working directory</span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010"></span><span style="color:#66d9ef">WORKDIR</span><span style="color:#e6db74"> /app</span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010"></span><span style="color:#75715e"># Copy files to the container</span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010"></span><span style="color:#66d9ef">COPY</span> . /app<span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010"></span><span style="color:#75715e"># Install dependencies</span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010"></span><span style="color:#66d9ef">RUN</span> apt-get update <span style="color:#f92672">&amp;&amp;</span> apt-get install -y &lt;your-package-name&gt;<span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010"></span><span style="color:#75715e"># Specify the command to run when the container starts</span><span style="color:#960050;background-color:#1e0010">
</span></span></span><span style="display:flex;"><span><span style="color:#960050;background-color:#1e0010"></span><span style="color:#66d9ef">CMD</span> [<span style="color:#e6db74">&#34;&lt;your-command&gt;&#34;</span>]<span style="color:#960050;background-color:#1e0010">
</span></span></span></code></pre></div><p>Customise the <code>FROM</code> line with the base image you want to use and replace <code>&lt;your-package-name&gt;</code> with the required packages for your application. Also, update <code>&lt;your-command&gt;</code> with the command to start your application.</p>
<h2 id="step-2-build-the-docker-image">Step 2: Build the Docker Image</h2>
<p>Once you have the Dockerfile ready, you can build the Docker image.</p>
<p>Open a terminal or command prompt and navigate to the directory containing the Dockerfile.</p>
<p>Run the following command:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>docker build -t &lt;image-name&gt; .
</span></span></code></pre></div><p>Replace <code>&lt;image-name&gt;</code> with the desired name for your Docker image.</p>
<p>The <code>.</code> at the end specifies the build context, which includes the files needed for building the image.</p>
<p>Wait for the build process to complete.</p>
<p>Docker will execute the instructions in the Dockerfile and generate the image.</p>
<h2 id="step-3-tag-the-docker-image">Step 3: Tag the Docker Image</h2>
<p>To publish the Docker image to GitHub&rsquo;s Container Registry, you need to tag it accordingly.</p>
<p>Run the following command:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>docker tag &lt;image-name&gt; ghcr.io/&lt;username&gt;/&lt;repository&gt;:&lt;tag&gt;
</span></span></code></pre></div><p>Replace <code>&lt;username&gt;</code> with your GitHub username, <code>&lt;repository&gt;</code> with the name of the repository you want to push the image to, and <code>&lt;tag&gt;</code> with the desired tag (e.g., version number or <code>latest</code>).</p>
<h2 id="step-4-log-in-to-github-container-registry">Step 4: Log in to GitHub Container Registry</h2>
<p>Before you can publish the image, you need to authenticate with GitHub&rsquo;s Container Registry.</p>
<p>Run the following command:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>docker login ghcr.io -u &lt;username&gt;
</span></span></code></pre></div><p>Replace <code>&lt;username&gt;</code> with your GitHub username. You will be prompted to enter your GitHub password or a personal access token.</p>
<h2 id="step-5-publish-the-docker-image">Step 5: Publish the Docker Image</h2>
<p>Now that you&rsquo;re logged in, you can publish the Docker image to GitHub&rsquo;s Container Registry.</p>
<p>Run the following command:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>docker push ghcr.io/&lt;username&gt;/&lt;repository&gt;:&lt;tag&gt;
</span></span></code></pre></div><p>Replace <code>&lt;username&gt;</code>, <code>&lt;repository&gt;</code>, and <code>&lt;tag&gt;</code> with the values you used in Step 3.</p>
<p>Wait for the push process to complete. Once finished, your Docker image will be available in GitHub&rsquo;s Container Registry, associated with your specified repository.</p>
<h2 id="step-6-update-and-re-publish">Step 6: Update and Re-Publish</h2>
<p>If you make changes to your Docker image or need to update it with a new version, follow the steps again from Step 2 onwards.</p>
<p>Remember to tag the image with a new version number or an appropriate tag, and push it to GitHub&rsquo;s Container Registry.</p>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
