Horje
Log in to Docker for Pulling and Pushing Images

Docker is a platform that provides a set of PaaS ( Platform as a Service ) products that help developers containerize applications, to run them consistently in all supported environments. Docker utilizes virtualization at the OS-level to deliver software in containers. At its core Docker utilizes Docker Engine, an open source component, to build, run and manage Docker Containers. Docker engine consists of two main components:

  • Docker Daemon – It is the process responsible for building, running and managing containerized applications
  • Docker Client – It is a command-line interface ( CLI ) used to interact with docker daemon.

What is a Docker Container?

A container is a self-contained run time instance of an image. It is a virtual environment that consists of the application and all of it’s dependencies. Containerization enables developers to package software and it’s dependencies into one unit and safely deploy them in all supported environments like Kubernetes, AWS EC2 instances, Virtual machines etc.

What is a Docker Image?

A Docker image is a read-only template that contains the instructions and all the necessary components to create a self-contained application instance (Docker container).

Docker Hub and Private Registries

Docker Hub and private registries serve as repositories for storing and managing Docker images. Docker Hub is a public registry offered by Docker itself.

Whereas, Private registries are secure, on-premise or cloud-based repositories specifically designed for storing and managing an organization’s private Docker images.

For pulling private images or pushing your own images to Docker Hub or to access an image from a Private registry, a developer must authenticate himself.

This can be achieved using the Docker CLI.

Setting up your Docker Environment

Prerequisites

  • Operating System: Docker supports most modern operating systems, including Windows, macOS, and various Linux distributions.
  • Hardware Requirements:
    • At least 4 GB of RAM.
    • 64-bit kernel and CPU support for virtualization.

Installation

Windows and macOS:

  • Download Docker Desktop from the official Docker website.
  • Run the installer and follow the on-screen instructions.
  • After installation, launch Docker Desktop and follow the setup wizard.

Ubuntu:

For Ubuntu based distributions you can use the following commands.

#Check Docker's official documentation for further info
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

#install latest version of docker packages
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

#verify docker engine installation is successful
docker --version

For other distributions please refer to the official docker documentation.

Configuration

1. Verify Installation:

To verify docker’s installation open a terminal and run `docker –version`

docker --version
DockerVersion

docker version

2. Start Docker

  • On Windows and macOS, Docker Desktop should start automatically. You can manually start or stop the docker engine by clicking the start/stop button in the bottom left corner of docker desktop
DockerEngineStartStop

Docker Engine Start/Stop

Logging into Docker Hub

To interact with Docker Hub, you first need to create an account and log in via the command line.

Creating a Docker Hub Account

  • Go to Docker Hub.
  • Click on “Sign Up” and fill in the required information.
  • Verify your email to activate your account.

Logging in via Command Line

Step 1: Open a terminal

Step 2: use the `docker login` command

docker login

Step 3: Enter your username and password when prompted

username:<enter your username>
password: <enter your password>
DockerLogin2

Step 4: On Successful login you will be prompted with: `login succeeded`

login succeeded

Pulling and Pushing Docker Images From Docker Hub

Pulling Images from Docker Hub

1. Search for an image

docker search <image_name>

2. Pull the image using `docker pull`

docker pull <image_name>

Example:

DockerSearch

docker search

DockerPull

docker pull

Building And Pushing Your Own Docker Images

1. Create a dockerfile:

A `dockerfile` contains instructions for building a Docker image. Example:

FROM ubuntu:latest
RUN apt-get update && apt-get install -y python3
COPY . /app
WORKDIR /app
CMD ["python3", "app.py"]

2. Build the image:

build the docker image using the following command:

docker build -t <your_image_name> .
docker_builld

docker build

3. Tag the image for a specific repository:

docker tag <your_image_name> <your_dockerhub_username>/<repository_name>:<tag>
docker tag

docker tag

4. Push the image to docker hub using the following command:

You can use docker push to push your image to docker hub as follows

docker push <your_dockerhub_username>/<repository_name>:<tag>
docker push

docker push

Upon successful execution you’ll find your image uploaded to docker hub.

docker hub

docker hub

Docker for Pulling and Pushing Images – FAQs

What is a Docker file?

The Docker file is a file that consists of all the commands to be executed to build a docker image.

What’s the difference between Docker and Docker Compose?

Docker is the core platform for building, running, and managing individual Docker containers. Docker Compose is a tool that helps you define and run multi-container applications.

How to learn to use docker?

The official Docker documentation is a great resource for getting started with Docker and exploring its functionalities. Additionally, you can refer to the vast number of tutorials available on Youtube.




Reffered: https://www.geeksforgeeks.org


DevOps

Related
Azure Logic Apps vs. Functions: Choosing the Right Tool Azure Logic Apps vs. Functions: Choosing the Right Tool
What Is Azure Web Apps ? What Is Azure Web Apps ?
How to Export and Import Docker Containers and images How to Export and Import Docker Containers and images
Terraform Remote State Management in AWS Terraform Remote State Management in AWS
Automating AWS Network Firewall Configurations with Terraform Automating AWS Network Firewall Configurations with Terraform

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
14