Thanksgiving Sale - upGrad KnowledgeHut-mobile

HomeBlogDevOpsIntroduction to Docker, Docker Containers & Docker Hub

Introduction to Docker, Docker Containers & Docker Hub

Published
02nd May, 2024
Views
view count loader
Read it in
7 Mins
In this article
    Introduction to Docker, Docker Containers & Docker Hub

    Docker is a tool that makes creating, deploying, and running applications easier with the use of containers. Now, what are containers? These can be described as something that makes it possible for developers to spruce up an application with all the parts needed for it. These could include libraries, for instance, along with other dependencies. Docker assembles all these and presents them as one package. The container gives the developer the assurance that the application will run on just about any Linux machine, no matter to what extent any of its customized settings in a particular machine could be at variance from those on the machine on which the code is written and tested.

    Who is Docker for:

    Docker is aimed to benefit both developers and system administrators. This makes it a part of many DevOps (developers + operations) toolchains. The main benefit that Docker carries for developers is that they can concentrate on their core job of writing the code without having to bog themselves down with which system it will run on.

    How Docker is useful in the IT industry:

    The most vital use of the Docker Enterprise container platform is that it offers value to a business by drastically bringing down its cost on infrastructure and maintenance. It can also do the same when it comes to migrating current. Best of all, all these can be done immediately upon installation. In this way, it saves time, as well. The following infographic illustrates how Docker brings down costs and increases productivity in an enterprise:

    Introduction to Docker, Docker containers & Docker Hub

    Image source

    Docker container:
    Next, let us understand what a container in a Docker is. We can think of it as being a standard unit of software that has the purpose of packaging the code and all its dependencies together.

    It comes with all that an application needs to run, namely settings, code, system tools, runtime, and system libraries.

    The point of making a Docker container in this fashion is to help the application run in a fast and dependable manner between one computing environment and another. A Docker container image has these characteristics:

    • Lightweight
    • Standalone
    • Executable

    In this sense, the container lies at the heart of a Docker.
    Docker containers that run on Docker Engine:
    Let us get down to understanding the Docker containers that power the Docker Engine.
    Standardization: Docker containers were created according to the industry standard for containers. The aim of doing this is that the containers could be made portable.
    Lightweight: Since containers share the machine’s OS system kernel; there is no need for an OS per application. What does this do? It increases server efficiencies and brings down the costs of the server as well as those associated with licensing.
    Security: Security is assured for applications in containers. It is a fact that  Docker comes with the industry-best default isolation capabilities.

    Docker containers that run on Docker Engine

    Let us explain a few Docker commands from the architecture shown above:

    • docker run – Used for running a command in a new container
    • docker start – For starting one or more stopped containers
    • docker stop – For stopping one or more running containers
    • docker build – Used for building an image form in a Docker file
    • docker pull – For pulling an image or a repository from a registry
    • docker push – Given for pushing an image or a repository to a registry
    • docker export – For exporting a container’s filesystem as a tar archive
    • docker exec – To run a command in a run-time container
    • docker search – For searching the Docker Hub for images
    • docker volume- To create and attach to containers to store data.
    • docker network- allows you to attach a container to as many networks as you like. You can also attach an already running container.
    • docker attach – To attach to a running container
    • docker commit – For creating a new image from a container’s changes
    • docker daemon – Having listened for Docker API requests, the Docker daemon (dockerd) manages Docker objects. These include networks, volumes, containers, and images. It also communicates with other daemons when managing Docker services.
    • docker Images – A read-only template, an image has instructions that are used to create a Docker container. Many times, images are based on other images and carry some degree of customization. An image-based on ubuntu can install the Apache web server, your application, and the configuration details that the application needs to run.

    Understanding Docker Hub Registry

    A registry service that is cloud-based; the Docker Hub Registry allows the user to do the following:

    • Link to code repositories
    • Build images and test them
    • Stores images that are manually pushed
    • Links to Docker Cloud to help deploy images to a host.

    In summary, we can understand the Docker Hub Registry as a tool that offers a centralized resource for discovering a container image, managing distribution and change, facilitating collaboration between the user and team, and automating workflow throughout the development pipeline.
    Ref URL.

    docker pull ubuntu

    • pull a docker image with old version

    docker pull ubuntu:16.04

    • create a custom tag to docker image

    docker tag ubuntu: latest admin/ubuntu: demo

    • login to your docker hub registry “sh docker login
    • docker push admin/ubuntu: demo

    testing

    • Remove all images in docker server

    docker image rm -f <Image_id>

    • Pull your custom image from your docker account

    docker pull admin/ubuntu:demo

    Installation Docker on Amazon Web Services (AWS) cloud:

    Why Amazon Web Services:

    AWS is a highly preferred cloud service. It enjoys a position of primacy in the global cloud services market due to the following reasons:

    • Market pioneers
    • Unshakeable customer faith
    • Cost-effectiveness
    • Ease and affordability of building a storage system with no worry of estimating usage
    • Suitability for small businesses, since it is ideal for building a business from bottom to top.

    Advantages of AWS:

    • Easy of usability
    • Agility
    • Security
    • Reliability
    • Services without capacity limits
    • Cost-effectiveness
    • Flexibility
    • 24×7 support.

    Steps to Install docker on Amazon Linux:

    Docker Configuration

    • Click on Launch instance and choose Amazon Linux Ami Ec2 server free tier Eligible.

    Docker Configuration

    • Choose free tier Eligible Ec2 t2. Micro.

    Docker Configuration

    • Here we need configure instance details like region, subnets, vpc.

    Docker Configuration

    • Add storage. By default it will give us 8GB, and we can modify it after launching Ec2.

    Docker Configuration

    • Create security groups and check port 22 is open to allow SSH connection and we can add incoming ports in security groups.

    Docker Configuration

    • Review details of Ec2 instance and click on Launch.

    Docker Configuration

    • Create New key pair or if we have existing key pair, we can use the same; and download and click on Launch instance.

    Docker Configuration

    • Convert Keypair from .PEM file to. PPK using puttygen.  We can Download puttygen and putty from here.
    • Login ec2 instance using putty and Ec2 Public Ip address.

    Docker Configuration

    • Click on SSH in Right panel and click Auth and add PPK key pair for ec2 to login.

    Docker Configuration

    • When we login to ec2 with New key pair we will get security alert. Click on YES and login as “Ec2-user”. If we need to login as root “sudo su – “.

    Docker Reference Code


    Docker Reference Code

    • Update packages for security purpose using command “sudo yum update -y”.
    • Now we need to install docker on Amazon Linux. Use command “ sudo yum install docker -y”.

    Docker Reference Code

    • To check Docker version, we can see output below:

    Docker Reference Code

    • Start docker with “sudo service docker start” command.

    Docker Reference Code

    • Check Docker status.

    Docker Reference Code

    • Now we can download any docker images by using “docker pull command”.

    Docker Reference Code

    Docker Reference Code

    • Check if the docker container is running with “docker ps” command.

    Docker Reference Code

    • To Login into docker container use “docker exec -it –user root container id bash.

    Docker Reference Code

    • Check current docker containers and stopped container with “docker ps -a” command.

    Docker Reference Code

    • To check downloaded docker images with “docker images” command.

    Docker Reference Code

    Conclusion:

    A tool with which creating, deploying and running applications is made much easier, a Docker is a set of packages that uses containers. It is of high value to both developers and system administrators, who can look at their core work without having to worry about writing the code, which runs on any system.

    Docker Enterprise is of immense value to the IT industry, as it brings down the maintenance and infrastructure costs. It can be deployed immediately and can be migrated easily.

    Profile

    Mayank Modi

    Blog Author

    Mayank Modi is a Red Hat Certified Architect with expertise in DevOps and Hybrid Cloud solutions. With a passion for technology and a keen interest in Linux/Unix systems, CISCO, and Network Security, Mayank has established himself as a skilled professional in the industry. As a DevOps and Corporate trainer, he has been instrumental in providing training and guidance to individuals and organizations. With over eight years of experience, Mayank is dedicated to achieving success both personally and professionally, making significant contributions to the field of technology.

    Share This Article
    Ready to Master the Skills that Drive Your Career?

    Avail your free 1:1 mentorship session.

    Select
    Your Message (Optional)

    Upcoming DevOps Batches & Dates

    NameDateFeeKnow more
    Course advisor icon
    Course Advisor
    Whatsapp/Chat icon