Skip to main content

Docker

Docker is a platform for containerization. In simple terms, it allows us to package an application and all its dependencies into a single, portable unit called a container

 Docker is a container that can run on any OS (platform independent ) 

We can develop the entire application within the Docker container, and that container can run anywhere 

example: developer1 developed his entire software in Docker container with  PHP (Backend) , MySQl and JAva for both backend and front end  developer 2 can get the container from developer 1 the docker container and run without any dependencies and without wasting their time on creating the environment .





Advantages of Docker:

  • Portability:
    • Docker containers ensure that applications run consistently across different environments, from development to production. This eliminates the "it works on my machine"  problem.  
  • Resource Efficiency:
    • Docker containers are lightweight compared to traditional virtual machines, allowing for better resource utilization.
  • Isolation:
    • Containers provide isolation, preventing applications from interfering with each other and enhancing security.
  • Scalability:
    • Docker simplifies scaling applications by allowing you to easily create and manage multiple container instances.
  • Faster Deployment:
    • Docker streamlines the deployment process, enabling faster and more consistent deployments.
  • Consistency:
    • Docker allows for the creation of consistent environments throughout the software development life cycle.

Disadvantages of Docker:

  • Security Concerns:
    • Docker containers share the host OS kernel, which can create security vulnerabilities if not properly managed.
    • Vulnerabilities within Docker images themselves can also pose a threat.
  • Complexity:
    • Managing complex Docker environments, especially at scale, can be challenging.
    • Orchestrating containers with tools like Kubernetes adds another layer of complexity.
  • Performance Overhead:
    • While lightweight, Docker containers do introduce some performance overhead compared to running applications directly on the host OS.
  • Persistent Data Storage:
    • Managing persistent data in Docker containers requires careful planning and configuration.
  • Networking complexities:
    • Setting up and managing complex network configurations between multiple containers can be difficult.

after installing and open 





and to check its working properly in cmd give docker --version , docker info to display all the images .

To understand docker :

Key Concepts:

  • Dockerfile:
    • A Dockerfile is a text file containing instructions for building a Docker image. It defines the base image, adds application code, sets environment variables, and specifies other configurations.
  • Docker Registry:
    • A Docker registry is a storage and distribution system for Docker images. Docker Hub is the most popular public registry, with a vast collection of pre-built images. You can also create private registries.
  • Docker Hub:
    • This is the default public registry. It contains a very large number of premade docker images.

Docker image is the temple contains everything to build the software , immutable , Docker images are built in layers. Each layer represents a set of changes. This layered architecture optimizes storage and makes image distribution efficient




software application  converted into  docker image 


Docker image is created in your system and put into the docker hub 



Pull Docker \Download the docker image :

go to cmd and give docker pull hello-world   hello-world id the image 


you can see the pulled  docker image in the docker application under images 
and also by using docker images in cmd 



To run the docker 

cmd --> docker run image name 



or in GUI under actions --> run 





inorder to run creating the container 

run and output came in the logs 



for each run, a new container is created. we run two times, one in GUI and another in CMd, so two containers were created.


common command :


to list the container : docker ps -a 

ps --> list of container 
a --> all 


To create the simple Docker image :

in order to create a new Dockerfile, go to any IDE, I went to PyCharm and just create the project and file, and named the file as Dockerfile, and D must be in caps. after it automatically ask to install the plugin 
by just downloading the plugin we can create the environment for Dockerfile .

inorder to run the Docker file, we need a lightweight Linux env image is alphine is available 

# alphine is the liunx image available in docker we pull using FROM
FROM alpine:latest
# CMD is the command and echo is to display a line of text or strings that are passed to it as arguments
CMD["echo","Hello","Docker!"]


save the docker file and run 





To build the docker image using dockerfile 

before make sure the docker file is in the directory /path 







and go to terminal inside the IDE 

and give docker build -t my-app:latest in correct path and run 

explanation :

docker build:

  • This is the core command that initiates the Docker image build process.

2. [OPTIONS]:

  • These are optional flags that modify the build process. Some of the most frequently used options are:
    • -t, --tag name[:tag]:
      • Assigns a name and optional tag to the image.
      • Example: docker build -t my-app:latest . (names the image "my-app" and tags it "latest").
    • -f, --file PATH/Dockerfile:
      • Specifies the path to the Dockerfile. If not provided, Docker assumes the Dockerfile is in the build context directory.
      • Example: docker build -t my-app:v1 -f ./my-dockerfiles/Dockerfile .
    • --no-cache:
      • Disables the use of cached intermediate layers during the build. This is useful for ensuring a fresh build.
      • Example: docker build --no-cache -t my-app:latest .
    • --build-arg <varname>=<value>:
      • Sets build-time variables.
      • Example: docker build --build-arg VERSION=1.2.3 -t my-app .

3. PATH | URL | -:

  • This specifies the build context:
    • PATH: A local path to a directory containing the Dockerfile and any files the Dockerfile needs. The . (dot) represents the current directory.
    • URL: A Git repository URL.
    • -: Reads the Dockerfile from standard input.


To Check whether the Docker image was created properly : 
go to docker application --> check under images .
my app image which we created was there.


click action button to check its runs properly 



created docker container and runs properly .:)




























Comments

Popular posts from this blog

Entity Relationship (ER) Diagram Model with DBMS Example

Reference :   Entity Relationship (ER) Diagram Model with DBMS Example What is ER Diagram? ER Diagram  stands for Entity Relationship Diagram, also known as ERD is a diagram that displays the relationship of entity sets stored in a database. In other words, ER diagrams help to explain the logical structure of databases. ER diagrams are created based on three basic concepts: entities, attributes and relationships. ER Diagrams contain different symbols that use rectangles to represent entities, ovals to define attributes and diamond shapes to represent relationships. At first look, an ER diagram looks very similar to the flowchart. However, ER Diagram includes many specialized symbols, and its meanings make this model unique. The purpose of ER Diagram is to represent the entity framework infrastructure. Entity Relationship Diagram Example Table of Content: What is ER Diagram? What is ER Model? History of ER models Why use ER Diagrams? Facts about ER Diagram Model ER Diagram...

SQL Joins and advanced joins and Subqueries

  Refernce :  Expert Guide to Advanced SQL Joins: What You Need to Know It's helpful to visualize how these different SQL joins work. Here's a breakdown in a table-like format, along with explanations: SQL Join Types Overview Join Type Description Key Characteristics Use Cases INNER JOIN Returns rows where there is a match in both tables. - Shows only matching records. - Excludes unmatched rows from both tables. - Retrieving related data that exists in both tables. - Finding records with corresponding entries in another table. LEFT OUTER JOIN (LEFT JOIN) Returns all rows from the left table, and the matched rows from the right table. - Includes all records from the left table. - Fills in NULL values for columns from the right table where there's no match. - Retrieving all records from one table and their related data from another, even if some records don't have matches. - Finding records in one table that don't have corresponding entries in another. RIGHT OUTER JO...

GIT BASH

  Bash Shell: Git Bash uses the Bash (Bourne Again SHell) command-line interpreter. This means you can use many of the same commands you'd find in a Linux or macOS terminal. Git Integration: Git Bash is tightly integrated with Git, making it easy to execute Git commands Essential Commands: Navigation: pwd : Prints the current working directory. ls : Lists files and directories in the current directory. cd <directory> : Changes the current directory. cd .. : Moves to the parent directory. File Management: mkdir <directory> : Creates a new directory. touch <file> : Creates a new file. rm <file> : Removes a file. rmdir <directory> : Removes an empty directory. Git Commands: git init : Initializes a new Git repository. git clone <repository URL> : Clones an existing Git repository. git status : Displays the status of your working directory. git add <file> : Adds a file to the staging area. git commit -m "commit message" : Commits chan...