What is Docker Images
Docker Image Architecture
Structure Of Docker Image
Explain different type of docker image in registry and their role
Docker FAQ and terms
Importnt video terms or topic and command
create container from image with dependency and database connection config
What is Docker Images
A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings
Docker image is an executable package of software that includes everything needed to run an application
- Docker images are immutable, they can't be changed.
- Docker images can be duplicated, shared or deleted.
- Docker image also act as the starting point when using Docker. 5. Docker image contains appication code, libraries, tools, dependencies and other files needed to make an application run. 6. Docker images have multiple layers, each one originates from the previous layer but is different from it.
- Docker images are a reusable asset deployed o any host.
- Docker images has many layers such as base image, parent image, layers, container layer, docker manifest.
- Docker image informs how a container should instantiate which software components will run and how 10.Docker image informs how a container should determining which software components will run and how
Docker Image Architecture
Docker Image is an executable package of software that includes everything needed to run an application. This image informs how a container should instantiate, determining which software components will run and how. Docker Container is a virtual environment that bundles application code with all the dependencies required to run the application. The application runs quickly and reliably from one computing environment to another.
Uses of Docker Images
- We can easily and effectively run the containers with the aid of docker images.
- All the code, configuration settings, environmental variables, libraries, and runtime are included in a Docker image.
- Docker images are platform-independent.
- Layers are the building blocks of an image.
- WithWhen using the build command, the user has the option of completely starting from scratch or using an existing image for the first layer
Difference between Docker Image and Docker Container
Structure Of Docker Image
The layers of software that make up a Docker image make it easier to configure the dependencies needed to execute the container.
Base Image: The basic image will be the starting point for the majority of Dockerfiles, and it can be made from scratch.
Parent Image: The parent image is the image that our image is based on. We can refer to the parent image in the Dockerfile using the FROM command, and each declaration after that affects the parent image.
Layers: Docker images have numerous layers. To create a sequence of intermediary images, each layer is created on top of the one before it.
Docker Registry: Refer to this page on the Docker Registry for further information.
Explain different type of docker image in registry and their role
Docker images are snapshots of a file system, along with metadata and configuration details, that form the basis of containers. These images can be stored in container registries, which are repositories for managing and distributing container images. Here are different types of Docker images commonly used in container registries:
Base Images:
Role: Base images serve as the foundation for other images. They contain the essential components needed to run an application but lack specific application code or dependencies.
Example: alpine, ubuntu, and centos are commonly used base images.
docker pull alpine:latest
Official Images:
Role: These are curated and maintained by the upstream communities (like Alpine, Ubuntu, etc.) or by the organizations behind the software. They are generally considered reliable and secure.
Example: nginx, postgres, and python official images are available on Docker Hub.
docker pull nginx:latest
Custom Images:
Role: Custom images are created by users to package and distribute their applications along with their dependencies. These images often start with a base image and add application-specific configurations and code.
Example: If you have a Python web application, you might start with the official python image and then add your application code and necessary dependencies.
docker build -t my-python-app .
Multi-Stage Build Images:
Role: These images are used to optimize the size of the final production image by building in multiple stages. The first stage can include build tools and dependencies, and the final stage contains only the necessary artifacts for runtime.
Example: A Go application might have one stage for compiling the code and another for running the compiled binary, resulting in a smaller image.
docker build -t my-go-app .
Builder Images:
Role: Builder images are used for building applications or libraries but not necessarily for running them. They often contain build tools, compilers, and other necessary components.
Example: An image containing a full development environment with compilers and build tools, used for compiling software before being packaged into a smaller runtime image.
docker build -t my-builder .
Slim and Alpine Images:
Role: These images are designed to be lightweight by using minimalistic base images. Alpine Linux-based images, in particular, are known for their small size.
Example: The official nginx:alpine image is a slim version of Nginx based on Alpine Linux.
docker pull nginx:alpine
Scratch Images:
Role: Scratch is a special empty image that can be used as a starting point for building minimalistic images. This is often used for building completely static binaries.
Example: Images for some Go applications might start with a scratch image to create minimalistic, standalone binaries.
docker build -t my-minimal-app -f Dockerfile.scratch .
When using container registries like Docker Hub or a private registry, these images can be stored, versioned, and shared among teams. Understanding the types of images and their roles helps in creating efficient, secure, and manageable containerized applications.
# Use a scratch image
FROM scratch
# Copy the statically compiled binary into the image
COPY myapp /
# Set the binary as the entry point
ENTRYPOINT ["/myapp"]
=======================Docker FAQ and terms================
https://www.debug.school/myelleti_434/what-is-a-docker-image-and-how-is-it-different-from-a-docker-container-1747
==concept of Image and Container is like class and object
==container is running instance of docker imagelike object is running instance of class
==same class multiple object ,similarly same image multiple container
==Docker images are immutable
==Docker image is a map of the house, then a Docker container is an actually built house,
==container is call it an instance of an image
==container is a runnable instance of an image
==dockerfile that contains a set of instructions for building a Docker image eg-pecifies the base image, copies files, installs dependencies, and sets up the environment for your application.
==Docker is a container management tool which manages the states like create, start, stop, restart, kill, pause e
==Container is an environment for running applications.
==Docker images consist of set of rules to be executed with root system
==Docker container is a runtime instance of a Docker image.
A Dockerfile is simply a text-based file with no file extension that contains a script of instructions. Docker uses this script to build a container image
A docker image consists of layers of filesystem
https://www.debug.school/nilesh35apiit_74/what-is-a-docker-image-3ca4
when merging happens?
Merging happens when we create a container out of this image.
Merging happens When we starts the container all these layers are merged, if there is conflict in any file then top layer will take precedence.
https://www.debug.school/sujatha14seenu_955/what-is-docker-2ag8
Q.why docker
To run the multiple similar application in a single PC we can use dockers which again request kernel for separate resources isolated with each other, Will reduce time, cost and effort of running the application..
Container is basically a bundle of rootfs, pid tree, users, with application on top of it.
https://www.debug.school/sati1241_119/day-1-dockers-realted-questions-40c7
Docker containers encapsulate everything an application needs to run (and only those things)
A container is a unit of software that packages code and its dependencies so the application runs quickly
https://www.debug.school/sivakumarsiya_779/docker-images-2pkl
==Docker image is collection of filesystems in simple.
==Docker images contains the ROOTFS (root file system), USERFS (user file system), APPFS (application file systems for OPENJDK,TOMCAT and CUSTOMAPPS).
==ROOTFS and USERFS together called as basic layer of an image.
==APPFS (for example: openjdk, tomcat, custom app) together called as application layer of an image
==to fine the storage driver used by docker server, run docker info and see the storage driver output.
==overlay2 is one of the storage driver used in docker to store docker images.
==overlay2 directory is located inside of DOCKER-ROOT directory, whenever we pull images from other repository (like docker hub), that image layers will be stored in overlay2 directory as image layer sub directories.
==when we create docker runtime, all layers of that image will be merged as single layer and attached to container as single mount (MNT) file system.
==whenever we make changes (like writing file/updating file), that changes will get updated in both merged layer and image layer.
==Docker uses sha2-256bit algorithm for encryption of docker images.
create docker file---->build image from docker file--->Create & Run Docker Container from image --->Access Container
START
↓
[1] Create Dockerfile
- Command: No specific command; create a file named `Dockerfile`
- Example content:
```
Dockerfile
FROM ubuntu:latest
RUN apt-get update && apt-get install -y nginx
CMD ["nginx", "-g", "daemon off;"]
```
↓
[2] Build Docker Image
- Command: `docker build -t my-image-name .`
- Description: Builds an image from the Dockerfile in the current directory
↓
[3] Create & Run Docker Container
- Command: `docker run -d --name my-container-name my-image-name`
- Description: Starts a container from the image in detached mode
↓
[4] Deploy (Optional – depends on your environment)
- Example Deployment Command (Docker Compose):
`docker-compose up -d`
- Or, push image to registry:
```
docker tag my-image-name username/my-image-name:latest
docker push username/my-image-name:latest
```
↓
[5] Run / Access Container
- Command: `docker exec -it my-container-name bash`
- Description: Open shell into the running container to interact with it
↓
END
=======Important video terms or topic and command==============
==============================video--6
bootfs(filesystem)+root(rootfilesystem +user fs + apps fs
bootfs==kernel fs
root=flavour==ubuntu+rhel+centos (like cdrive/d reive) it can be one ore more os
usefs== home/desktop
apps==java,apache
docker image== have no boot fs
docker image= rootfs +userfs +appfs(no bootfs)
hernal
Human → Client → Daemon → Containerd → Kernel
Human (You, the User): Initiate an action via a CLI client.
Docker Client: Sends your command (like docker run ...) to the Docker daemon
Docker Daemon: The background manager service for Docker.
Containerd: A core container runtime responsible for managing container lifecycle.
Kernel: The lowest-level component that creates the actual container using Linux features (namespaces, cgroups, etc.).
kernel create
same user==create one new network
same user= create one new pid
single image=multiple layer layer0(base image rootfs)+layer1(nginx)+...layer +top layer(content) eacg layer identified ==hash value
how to see hash value or layer== docker inspet container id
how to see mount==df -kh
all layer mergerd in one layer that create container see that meger layer df -kh overlay
how to see docker root dir ==docker info
when u pull image in output how many pull complete that many layer created eg docker pull ubuntu
to see how many layer in image go to overlay2 eg cd overlay2 then ls if suffix -init is with layer then it is merged layer
when u create container all layer is merged into additional layer
all layer of image is read only
but additional layer(merged layer) of image is read write both
Image contains multiple filesystems,
each layered over the other (called layers),
with the base layer as the root filesystem and additional app/dependency layers;
when creating a container, all image layers are merged into one additional writable layer via union mounts,
with all image layers being read-only and only the additional layer being read-write;
container layers are divided into "merged" (all layers of the image) and "diff" (changes in the container),
and when a container stops, the merged layer disappears;
when starting, image layers plus diff are merged into the merged directory.
===============================================
video 7how to develop docker image
1) manually==require existing container
2)ci/cd automated way==docker =docker build==required docker file
docker diff== all changes or updation in particular container
docker file
list of instruction
each line create one layer
eache layer gets created from container of previous line of dockerfile
=============================
video-8
https://github.com/jenkinsci/docker/blob/587b2856cd225bb152c4abeeaaa24934c75aa460/Dockerfile
ARG user=jenkins
ARG group=jenkins
ARG uid=1000
here ARG is way to create variable in image and reuse in multiple time during runtimeeg see below ex
RUN groupadd -g ${gid} ${group} \
&& useradd -d "$JENKINS_HOME" -u ${uid} -g ${gid} -m -s /bin/bash ${user}
entrypoint vs cmd
how to set PID 1
cmd can be replaced
entrypoint cannot be replaced
create container from image with dependency and database connection config
docker run -d --name motorenter-web \
-p 8080:80 \
-e DB_HOST=172.30.160.1 \
-e DB_PORT=3306 \
-e DB_USER=root \
-e DB_PASSWORD=your_mysql_password \
-e DB_NAME=livemotoshare \
apachephpdockerfile
docker run -it --name motopartner-web \
-p 8080:80 \
-e DB_HOST=host.docker.internal \
-e DB_PORT=3306 \
-e DB_USER=root \
-e DB_PASSWORD= \
-e DB_NAME=livemotoshare \
apachephpdockerfile
===============ASK DOUBT RAJESH================
while linking container manual way uaing link flag is legacy way why not prefer docker compose
after start container and entering shell suddenly exit why how to debug or log
example:
docker run -d --name container6 -v shared-data:/data alpine sh
docker run -d --name container7 -v shared-data:/data alpine sh
now i run
docker start container6 and check docker ps -a container6 not showing up
but it deploy website in container is working using official image alpine is not working using custom image motoshare is working
docker start motoshare
docker inspect --format='{{.Config.Cmd}}' moto-web
===================command============
docker run -it --name mycontainer motoshare bash
Why is /data given in docker run -v myvolume:/data busybox
how to see to see the /data directory inside a Docker container
Mounting a Docker Volume to an Existing Directory Inside the Container
root@d06f16e55c55:/opt/lampp/htdocs
docker exec -it 94badc311fe2 bash
docker start 70f935f448d0
docker run -it --name firstmotocontainer -v shared-data:/data motoshare
docker run -it --name mycontainer motoshare bash
echo "Hello from motoshare" > /opt/lampp/htdocs/hello.txt
docker exec -it 70f935f448d0 bash
echo "Hello from motocontainer" > /data/hello.txt
docker run -it --name container1 -v shared-data:/resources/views motoshare
docker start 70f935f448d0
docker exec -it 70f935f448d0 bash
container4
echo "Hello from motoshare" > /opt/lampp/htdocs/hello.txt
docker run -it --name container2 -v shared-data:/data ubuntu
docker run -it --name newmotocontainer -v shared-data:/data motoshare
echo "Hello from motoshare" > /opt/lampp/htdocs/hello.txt
docker run -it --name thirdmotocontainer -v shared-data:/opt/lampp/htdocs motoshare bash
Copy the File Into the Volume
docker run -it --name newcontainer -v shared-data:/opt/lampp/htdocs motoshare bash
docker cp ./hello.txt newcontainer:/opt/lampp/htdocs/hello.txt
docker run -d --name fifthmotocontainer --mount source=my_shared_volume,target=/opt/lampp/htdocs motoshare bash
docker run -d --name sixmotocontainer --mount source=my_shared_volume,target=/opt/lampp/htdocs motoshare bash
docker exec fifthmotocontainer bash -c 'echo "Hello from thirdmotocontainer!" > /opt/lampp/htdocs/moto.txt'
docker logs fifthmotocontainer
docker run -d --name sevenmotocontainer --mount source=new_shared_volume,target=/opt/lampp/htdocs motoshare
docker run -d --name eightmotocontainer --mount source=new_shared_volume,target=/opt/lampp/htdocs motoshare
docker exec sevenmotocontainer bash -c 'echo "Hello from sevenmotocontainer!" > /opt/lampp/htdocs/news.txt'
docker exec sevenmotocontainer cat /opt/lampp/htdocs/mine.txt
docker run -dit --name moto9 --network my-bridge-network motoshare sh
docker run -dit --name moto11 --network my-bridge-network motoshare sh
docker exec -it moto10 sh
docker run -dit --name container4 --network my-bridge-network alpine sh
docker run -dit --name container5 --network my-bridge-network alpine sh
docker exec -it container4 sh
ping container5
docker run -d --name container6 -v shared-data:/data alpine sh
docker run -d --name container7 -v shared-data:/data alpine sh
docker exec -it container7 sh
Top comments (0)