<?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: Nitin Singh</title>
    <description>The latest articles on DEV Community by Nitin Singh (@nitin27may).</description>
    <link>https://dev.to/nitin27may</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%2F207440%2F97e0190c-5c1b-4264-8283-ba15ecc698a1.jpeg</url>
      <title>DEV Community: Nitin Singh</title>
      <link>https://dev.to/nitin27may</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nitin27may"/>
    <language>en</language>
    <item>
      <title>Pushing Cutom Images to Docker Hub using GitHub Actions</title>
      <dc:creator>Nitin Singh</dc:creator>
      <pubDate>Fri, 30 Sep 2022 22:18:59 +0000</pubDate>
      <link>https://dev.to/nitin27may/pushing-cutom-images-to-docker-hub-using-github-actions-2511</link>
      <guid>https://dev.to/nitin27may/pushing-cutom-images-to-docker-hub-using-github-actions-2511</guid>
      <description>&lt;p&gt;In last &lt;a href="https://dev.to/nitin27may/pushing-custom-docker-image-to-docker-hub-5ado"&gt;article&lt;/a&gt;, we saw that how to push custom image on Docker hub using docker cli, In this article we are going to see how we can automat this using GitHub Actions. Please keep this article link handy as we will be referring it for few key infomration.&lt;/p&gt;

&lt;p&gt;First, we need an application source code which we have already dockerized, in this case we will take a simple example, Here is the link of the &lt;a href="https://github.com/nitin27may/docker-images-example" rel="noopener noreferrer"&gt;Git Repo&lt;/a&gt;. In this project, we have just two file which have been used. One is 'index.html' and another is 'Dockerfile'. Assumtion is that we already know how to build and run it locally.&lt;/p&gt;

&lt;p&gt;Now, We will keep our docker account details : username and access token handy (Explained in same article).&lt;br&gt;
We will go to our github repository, Settings &amp;gt; Secrets &amp;gt; Actions and click on 'New repository secret'.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftks6jyd7ypi9dk71hvjh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftks6jyd7ypi9dk71hvjh.png" alt="New repository secret"&gt;&lt;/a&gt;&lt;br&gt;
It will open a new window, where we have to add key and value for our docker account access token (in our case, we name it, DOCKERHUB_TOKEN). We also addeed docker hub user name (DOCKERHUB_USERNAME) as secret.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft8idoqtqqv0m42s1gxfz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft8idoqtqqv0m42s1gxfz.png" alt="Add new"&gt;&lt;/a&gt;&lt;br&gt;
Now let's add our first GitHub Action at root of our project like below :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft8rfkmzyjyve55ixhp0n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft8rfkmzyjyve55ixhp0n.png" alt="VS Code"&gt;&lt;/a&gt;&lt;br&gt;
Below is the full script.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In this script we are trigeering the build if any changes are pushed to master branch for all paths. We are using an build agent in this case it is ubunt 22.04&lt;/p&gt;

&lt;p&gt;Ther very &lt;strong&gt;first step&lt;/strong&gt; is &lt;a href="https://github.com/actions/checkout" rel="noopener noreferrer"&gt;actions/checkout@v2&lt;/a&gt; action, which take the latest code from the master branch.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second step&lt;/strong&gt; is &lt;a href="https://github.com/docker/setup-qemu-action" rel="noopener noreferrer"&gt;docker/setup-qemu-action&lt;/a&gt; which installs QEMU static binaries, which are used to run builders for architectures other than the host.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Third step&lt;/strong&gt; is &lt;a href="https://github.com/docker/setup-buildx-action" rel="noopener noreferrer"&gt;docker/setup-buildx-action&lt;/a&gt; configures &lt;a href="https://github.com/docker/buildx" rel="noopener noreferrer"&gt;buildx&lt;/a&gt;, which is a Docker CLI plugin that provides enhanced build capabilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fourth step&lt;/strong&gt; is login (&lt;a href="https://github.com/docker/login-action" rel="noopener noreferrer"&gt;docker/login-action@v2&lt;/a&gt;) in to docker account, it is using username and token configured in the repository's action secret section. Then next step is building and pushing it to docker hub.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fifth step&lt;/strong&gt;, if you will see, we are tagging (&lt;a href="https://github.com/docker/build-push-action" rel="noopener noreferrer"&gt;docker/build-push-action@v3&lt;/a&gt;) the image with 2 tags, one is the latest, so every image will pushed as latest and also as a Variable which is the Github Run Number, which is the number of build (GitHub Action)run for that repo. This way every build will create, it's own tag too and we can pull that particulat image from the dokcer hub.&lt;/p&gt;

&lt;p&gt;Now on any code push to master branch it will trigger a build, and we haven't added any filter or condition. On pushing this script to master branch it will trigger a new build. In below screen shot, the yellow dot shows on GitHub repository if any build has been triggered.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4jum9655973do65epx2x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4jum9655973do65epx2x.png" alt="Build in Queue"&gt;&lt;/a&gt;&lt;br&gt;
The below screenshot is showing that how tags get update in any build.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq9p91qm91k9s1mjryve2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq9p91qm91k9s1mjryve2.png" alt="Build Run Details"&gt;&lt;/a&gt;&lt;br&gt;
Below is the screenshot from a successfull run.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7jfcvjm3klfalnulsv2d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7jfcvjm3klfalnulsv2d.png" alt="Result at Repository"&gt;&lt;/a&gt;&lt;br&gt;
After, sucessfull push, we can see that it pushed 2 tag, one is latest and another is 5, which we can see that it was the build number.&lt;br&gt;
This was a pretty straight forward example to create a GitHub Action to build and push image to Dokcer Hub. Hope this was helpful and thanks for reading.&lt;/p&gt;

</description>
      <category>githubaction</category>
      <category>docker</category>
      <category>dockerhub</category>
      <category>container</category>
    </item>
    <item>
      <title>Pushing Custom Docker Image to Docker Hub</title>
      <dc:creator>Nitin Singh</dc:creator>
      <pubDate>Tue, 27 Sep 2022 15:09:53 +0000</pubDate>
      <link>https://dev.to/nitin27may/pushing-custom-docker-image-to-docker-hub-5ado</link>
      <guid>https://dev.to/nitin27may/pushing-custom-docker-image-to-docker-hub-5ado</guid>
      <description>&lt;p&gt;In this tutorial, we will be going through steps for building, tagging and pushing a custom docker image on a Docker Registry. Docker Hub is one of the most popular Registry, another names are ACR (Azure Container Registry) and Amazon ECR ( Amazon Elastic Container Registry). In this article we will be going through the steps to push our custom image on Docker Hub.&lt;/p&gt;

&lt;p&gt;For simplification I have kept this article in few sections, those are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a Docker Hub Account&lt;/li&gt;
&lt;li&gt;Generate an access token (why to not use password)&lt;/li&gt;
&lt;li&gt;Login to docker registry&lt;/li&gt;
&lt;li&gt;Building a custom image&lt;/li&gt;
&lt;li&gt;Tag it and Push the image to container registry&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;strong&gt;&lt;u&gt;1. Create a Docker Hub Account :&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
 &lt;br&gt;
First, we need a docker hub account, please visit the page &lt;a href="https://hub.docker.com/"&gt;https://hub.docker.com/&lt;/a&gt; and signup for an account, the free account provide you to publish unlimited public repository, if you need private repository, you will have to upgrade your account. Username of your account is important. To access any image from your repository we will have to use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Docker pull &amp;lt;username&amp;gt;/&amp;lt;repository name&amp;gt;:&amp;lt;tag&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we don't pass tag it will fetch the latest image.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;2. Generate access token:&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
For login into docker hub account from docker cli we can use username and password of the account, but this way it will be getting the full access of your account, and also if you are changing the password, you will have to login again.&lt;br&gt;
The Recommended approach is to login in docker hub from cli to use access token so you can limit the access:&lt;br&gt;
Go to Account Settings &amp;gt; Security , In my case it is showing some existing token but in your case it may be blank, Now click on New Access Token:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ACngJvBk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5sf7lly6l7qqt9nedgu0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ACngJvBk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5sf7lly6l7qqt9nedgu0.png" alt="Docker Hub Access Token List" width="880" height="491"&gt;&lt;/a&gt;&lt;br&gt;
We want to Read and Write So we can select Read &amp;amp; Write, but if you want to perform delete too then use that permission and then click generate. After generate it will show the token, copy it and keep it at safe place, it will not show again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TWcIH878--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jsds1xmurlz7gx05knnn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TWcIH878--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jsds1xmurlz7gx05knnn.png" alt="Docker Hub Access Token Add New" width="744" height="571"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;u&gt;3. Login to Docker Registry:&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker login -u &amp;lt;username&amp;gt; -p &amp;lt;accesstoken or account password&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or just run run command &lt;code&gt;docker login&lt;/code&gt; and it will ask username and password.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The recommended approach is ,To increase security, use the - password-stdin flag to instruct Docker to read your password from STDIN. This lets you pipe in a password file, preventing plain text from being captured in your shell history and CI job logs.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat password.txt | docker login - username &amp;lt;username&amp;gt; - password-stdin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, In passwor.txt, we have saved our access token value.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s-cf-aG6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u14nb42teovjdb6zoy3j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s-cf-aG6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u14nb42teovjdb6zoy3j.png" alt="Docker Login" width="828" height="256"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;4. Building a custom image:&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
I have a very simple example by using nginx as base image here is an example, &lt;a href="https://github.com/nitin27may/docker-images-example.git"&gt;Git Repo Link&lt;/a&gt; &lt;br&gt;
 &lt;br&gt;
We just need a sample html file and then we have to create a Dockerfile and keep both file in same folder:&lt;br&gt;
Dockerfile code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM nginx:latest
COPY index.html /usr/share/nginx/html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this docker file, we are pulling latest nginx image and top of that we are copying sampleindfex.html in to html folder, let's build the custom image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -t my-custom-nginx .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In above command we are building image by passing build context as current folder, so that we are passing . (dot).&lt;br&gt;
Output:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--plrpU-zi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x7gpqo59557h9qkgs5bh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--plrpU-zi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x7gpqo59557h9qkgs5bh.png" alt="Docker Build Output" width="828" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;5. Tag it and Push the image to container registry&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
Now tag locally created image with docker hub username and custom image name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker tag my-custom-nginx nitin27may/my-custom-nginx:1.0
docker push nitin27may/my-custom-nginx:1.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In above command, 'nitin27may' is my account name, 'my-custom-nginx' repository name in docker hub and '1.0' is the tag, so the full tag is 'nitin27may/my-custom-nginx:1.0'&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--q0tqXAC6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hyulun6ri6im27r8fkyv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q0tqXAC6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hyulun6ri6im27r8fkyv.png" alt="Docker push Image Output" width="828" height="248"&gt;&lt;/a&gt;&lt;br&gt;
Below is the screenshot from the Docker hub from my account.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oXCVp1HS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x61bqg665do3hurgbdza.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oXCVp1HS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x61bqg665do3hurgbdza.png" alt="Docker Hub Repository Example" width="828" height="479"&gt;&lt;/a&gt;&lt;br&gt;
In Next Article, I will be explaining that how we can automate this using GitHub Action.&lt;/p&gt;

&lt;p&gt;If you have any suggestion, question, please reach out to me.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>dockerhub</category>
      <category>dockerfile</category>
      <category>container</category>
    </item>
  </channel>
</rss>
