Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications, whether on laptops, data center VMs, or the cloud. To know about Docker in details, click here. The installation and configuration process is described in our different blog. Click here to access that.
Here at linuxnix.com, we have a list of activities to be performed in this Docker series. With these tasks, we will be getting a clear picture on docker day-to-day use and the real-time scenarios we face where we need Docker the most. The lists of the activities are mentioned below:
- Dockerize a 2-Tier Java application by creating a Docker Image.
- Push the same Docker Image to Docker Hub.
- Run a container based version of the Application Database using the Docker-Compose file.
- Ensure data persistence by mounting the data outside of the containers.
In this section, we are going to start the second task. To go through the first task, click here.
Pushing Docker Image to Docker Hub
Docker Hub vs Creating a Local Docker Registry
Docker Hub is a cloud-based registry service which allows you to stores the manually pushed images and links it to the Docker Cloud. It provides a centralized resource for container image discovery. This also helps us to deploy images to our hosts in a centralized way. Docker Registry is a storage solution for Docker Images. Just think about GitHub, but for Docker Images.
Docker Hub offers a great functionality for free. but what if we need more privacy? What if our partner needs it in their own server. In that case, we can make our own registry. Like GitLab provided their service in your own server, Docker also provides their service as a local Docker Registry.
Docker Hub Login/SignUp
In the previous blog, we took a Java project, created a Dockerfile. Built the image using the Dockerfile, created the container, ran it and verified the running application on the port specified. In this section, we are taking the same image and pushing it to the Docker Hub.
You can log in to Docker Hub using your free account ID. If you don’t have one, you can create a free id on hub.docker.com.
Now, once we have the account created, we can log in to the Docker Hub via CLI where our Docker installation exists. The command to log in to the command line is “docker login“.
Docker commands and Docker Hub
Docker provides access to Docker Hub vial various CLI commands like docker search, login, pull and push. Let’s understand them:
- docker login: As seen above, This command is used to login to the Docker registry.
- docker search: It is used to search images in Docker Hub.
- docker pull: This command is used to pull an image or repository from the Docker registry.
- docker push: This is used to push a repository or an image to Docker registry.
Pushing Docker Image to Docker Hub
A Docker Image is a file comprised of many layers used to execute commands in Docker Container. It includes system libraries, files, dependencies, etc.
Let’s check our docker images. For this, we use the command “docker images“. We can see the image named “docker201” is available which we will be pushing to Docker Hub.
Now to push the image, we need to create a Docker Hub tag for the image. We use “docker tag docker201 iankesh/docker201” to create the tag. Here, “docker tag” is the command to create a tag, “docker201” is the name of the image and “iankesh/docker201″ is the repository name for the Docker Hub.
docker tag docker201 iankesh/docker201
Once the tag is created, we can push the image using “docker push iankesh/docker201“. “docker push” is the command to push the images and “iankesh/docker201” is the repository name which we want to get created in Docker Hub.
docker push iankesh/docker201
Verifying the Image in Docker Hub
We have created the Docker Hub account in the first step. Log in to the console and check whether the pushed image is available or not.
Our Image is now available on Docker Hub..!!! We have successfully pushed an Image via Docker. The next blog will focus on running a container based version of Database and connect it to the Application. To go through it, click here.
Stay tuned for more updates @ linuxnix.com..
Latest posts by Ankesh K (see all)
- How to Push Docker Images to Docker Hub/repository - September 11, 2018
- What is Docker-Compose and How to run multiple containers as a single service? - September 11, 2018
- What is dockerfile and how to Dockerize a 2-Tier Application? - September 10, 2018
- What is Terraform and its Benefits? - September 3, 2018
- Embedding Excel/CSV file in Email from Linux CLI - August 22, 2018