0% found this document useful (0 votes)
13 views3 pages

Understanding Docker: Containers & Images

Provides the basic understanding of the docker and its functionalities. Drafted for a beginner to start from scratch.

Uploaded by

Satish Kushwah
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Understanding Docker: Containers & Images

Provides the basic understanding of the docker and its functionalities. Drafted for a beginner to start from scratch.

Uploaded by

Satish Kushwah
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

What is Docker?

 We can imagine Docker as a Cargo Ship that can hold big boxes (containers) having their
distinct objectives and id.
 These containers contain items (Application + Dependencies) that are required to make
that container useful and runnable anywhere.
 These items are manufactured using templates (Docker File).
 Docker is a containerization platform which packages your application and all its
dependencies together in the form of containers to ensure that your application works
seamlessly in any environment, be it development, test or production.
 Hence a container contains complete ecosystem of your application.
 Including the application and all its dependencies, and everything that is needed for an
application to run on the server.
 This guarantees that the software will always run the same, regardless of its
environment.

What is Docker file?


 This text file provides a set of instructions to build a Docker image, including the
operating system, languages, environment variables, file locations, network ports, and
any other components it needs to run.
 Each time command is run in Docker file, a new layer is created on top of the previous
layers. This allows Docker images to be built incrementally, with each layer representing
a separate instruction in the Docker file. It also allows Docker to reuse layers between
images, which can help reduce the size of images and improve build times.
 For example, if you specify a command to install a package in your Docker file, a new
layer will be created that includes the package and its dependencies. If you make
another change, such as adding a file to the image, another layer will be created on top
of the previous one.
DockerFile:
FROM openjdk:17-alpine
WORKDIR /opt
ENV PORT 8080
EXPOSE 8080
COPY target/*.jar /opt/[Link]
ENTRYPOINT exec java $JAVA_OPTS -jar [Link]
What is Docker Image?
 Docker-images are a read-only binary template (like snapshots) used to build
containers. Images also contain metadata that describe the container’s capabilities and
needs.
 Create a docker image using the docker build command whenever you pass a Docker
file to the docker build command then the docker daemon will create a docker image
according to the Docker file instruction.
 Docker images can’t be executed by themselves and cannot run or start. It is just a
blueprint for creating Docker containers.
 Run the docker images using the docker run command. Whenever we pass the
command to docker client then the docker client passes this command to the docker
daemon then docker daemon will create the container for that image.
 Push the docker image to the public registry like DockerHub using the docker push
command after pushed you can access these images from anywhere using the docker
pull command.

What is Docker Container?


 A container is a runnable instance of an image. You can create, start, stop, move, or
delete a container using the Docker API or CLI.
 Containers provide you with a lightweight and platform-independent way of
running your applications. Every container is isolated but access to resources on
another host or container can be allowed with the help of docker networking.
 A container is volatile it means whenever you remove or kill the container then all its
data will be lost from it. If you want to persist the container data use the docker
storage concept.
 Containers only have access to resources that are defined in the image, unless
additional access is defined when building the image into a container
 All the docker images become docker containers when they run on Docker Engine.

What is Docker Hub?


 Docker images are stored in a registry, which is a centralize location for storing and
distributing Docker images.
 When you run a Docker container, Docker pulls the image from the registry and runs it
on your local machine.
 Several public registries are available, such as Docker Hub, the default registry for
Docker. You can also set up your private registry if you want to store and manage images
internally.
 Docker hub is a cloud-based registry service that allows you to link to code
repositories, build your images and test them, store manually pushed images, and link to
the Docker cloud so you can deploy images to your hosts. It provides a centralized
resource for container image discovery, distribution and change management, user and
team collaboration, and workflow automation throughout the development pipeline.
 [Link]

Did you use Docker in your Project? If yes, why?


 Yeah, we did. We had a common problem of Developers saying “BUT IT WORKS ON MY
MACHINE”
 There are some scenarios which motivated us to move to dockerized application
 We sometimes faced issue that our same code base when deployed to test, dev, worked
fine but breaks on prod or QA servers. We found that even though code base is same but
dependencies/their version were problematic hence if we can package everything in
one big container and run application in that container with same configuration,
dependency then things won’t break abruptly. Hence, we moved to Docker.
 Apart from that we achieved few more advantages like –
o Docker is an open platform for developing, shipping, and running applications.

o Docker enables you to separate your applications form your infrastructure so you
can deliver software quickly.
o With Docker, you can manage your infrastructure in the same ways you manage
your applications.
 By taking advantage of Docker’s methodologies for shipping, testing, and deploying code
quickly, you can significantly reduce the delay between writing code and running it in
production.
 User cases involve –
o Environment standardization

o Faster configuration with consistency

 Better disaster recovery – Disaster is unpredictable. However, you can back up a Docker
image (also called “snapshot”) for the state of the container at that back-up moment and
retrieve it later when serious issues happen. For example, a hardware failure just
happened, and you need to switch your work to a new hardware. With Docker, you can
easily replicate the file to the new hardware.
 Sometimes we found a bug when deploying a new version of one software. We can
revert to the last version with the previous Docker image easily. Without Docker, we
have to set up the rollback step from runtime to runtime.
 Improvement in adoption of DevOps.

Common questions

Powered by AI

A Docker image is a read-only template that contains the application and its environment specifications, necessary to create a Docker container. On the other hand, a Docker container is a live, running instance derived from a Docker image. While images are static and cannot be executed directly, containers can be started, stopped, and moved. Containers function as isolated applications, running the image's specifications .

Docker provides environment standardization, ensuring applications work seamlessly across different environments by packaging the application and its dependencies in containers. It reduces configuration inconsistencies and allows for faster application deployment. Docker's containerization also aids in disaster recovery by enabling easy image backups and restores to different hardware . Moreover, Docker improves the DevOps process by allowing easier and more consistent deployment pipelines .

Docker containers can be efficiently managed using the Docker API or CLI, which supports operations like starting, stopping, and removing containers. Efficient management involves leveraging Docker's networking to connect containers, using persistent storage to handle volatile container data, and utilizing orchestration tools like Docker Compose for managing multi-container applications. Docker also allows resource allocation tuning to optimize performance .

Docker Hub acts as a centralized platform for storing and distributing Docker images. It provides a location for developers to push their images, which can then be pulled from anywhere when needed. This facilitates easy sharing and collaboration on Docker images across teams and the broader community. Docker Hub also integrates with code repositories and supports automated builds and deployments, contributing significantly to the Docker workflow .

Docker uses containers to package applications with all their dependencies, creating an isolated environment that encompasses everything the application needs to run. This containment guarantees that the software runs consistently across any environment, whether it's development, testing, or production, because the underlying environment configurations and dependencies are encapsulated within the container itself .

Docker facilitates DevOps adoption by standardizing development environments through containerization, which helps reduce the configuration inconsistencies that can delay development and deployment. This standardization processes make continuous integration and deployment (CI/CD) more efficient by ensuring that containerized applications behave predictably across different stages. Docker also supports version control of environments, allowing for rapid rollbacks and versioning that align with DevOps practices .

Docker uses a layer-based system where each command in a Dockerfile adds a new layer. These layers are read-only and are reused across different images, which optimizes both the creation and usage of Docker images. When changes are made, only the new layers need to be downloaded or updated, resulting in faster build times and reduced image sizes .

Docker addresses the "works on my machine" issue by encapsulating applications along with all necessary dependencies and configurations within containers. This packaging ensures that the application runs the same way across different environments, eliminating discrepancies due to differing local setups or environment variables. As a result, developers can be more confident that code running on their machine will behave identically in testing and production environments .

Docker enhances disaster recovery by allowing users to create snapshots of containers, which can be backed up and restored seamlessly, even on new hardware following a failure. This capability simplifies the recovery process compared to traditional setups that might require extensive reconfiguration. Docker’s consistent and isolated environments mean that these snapshots include all necessary configurations, leading to easier and faster recovery .

Building a Docker image using a Dockerfile involves using the 'docker build' command. A Dockerfile contains a series of instructions, each creating a new layer on top of the previous one. These instructions define the operating system, environment variables, network ports, and other necessary components. Layers are built incrementally, allowing Docker to reuse layers between different images, optimizing image size and build times .

You might also like