DCA - Section 2 Image Management
DCA - Section 2 Image Management
DCA - Section 2 Image Management
ISSUED BY
Zeal Vora
REPRESENTATIVE
instructors@kplabs.in
Module 1: Working with Docker Images
Every Docker container is based on an image.
Till now we have been using images that were created by others and available in Docker Hub.
Docker can build images automatically by reading the instructions from a Dockerfile
A Dockerfile is a text document that contains all the commands a user could call on the
command line to assemble an image.
# Comment
INSTRUCTION arguments
There are multiple INSTRUCTIONS that are available in Dockerfile, some of these include:
● FROM
● RUN
● CMD
● LABEL
● EXPOSE
Module 3: COPY vs ADD Instruction
COPY and ADD are both Dockerfile instructions that serve similar purposes.
They let you copy files from a specific location into a Docker image.
COPY takes in an src and destination. It only lets you copy in a local file or directory from your
host
ADD lets you do that too, but it also supports 2 other sources.
Using ADD to fetch packages from remote URLs is strongly discouraged; you should use curl or
wget instead.
.
Module 4: EXPOSE Instruction
The EXPOSE instruction informs Docker that the container listens on the specified network
ports at runtime.
It functions as a type of documentation between the person who builds the image and the
person who runs the container, about which ports are intended to be published.
When Docker starts a container, it monitors the process that the container runs. If the process
ends, the container exits.
That's just a basic check and does not necessarily tell the detail about the application.
We can specify certain options before the CMD operation, these includes:
FROM ubuntu
ENTRYPOINT ["top", "-b"]
CMD ["-c"]
Sample Snippet:
● WORKDIR /a
● WORKDIR b
● WORKDIR c
● RUN pwd
Output = /a/b/c
Example Snippet:
You can use -e, --env, and --env-file flags to set simple environment variables in the container
you’re running or overwrite variables that are defined in the Dockerfile of the image you’re
running.
Example Snippet:
docker run --env VAR1=value1 --env VAR2=value2 ubuntu env | grep VAR
They are aliases to the ID of your image which often look like this: 8f5487c8b942
By default, the container being committed and its processes will be paused while the image is
committed.
Syntax:
The --change option will apply Dockerfile instructions to the image that is created.
The major difference between a container and an image is the top writable layer.
All writes to the container that adds new or modifies existing data are stored in this writable
layer.
11.2 Understanding Image Layers:
● Creation Date
● Command
● Environment Variables
● Architecture
● OS
● Size
docker image inspect command allows us to see all the information associated with a docker
image.
Dangling Images = Image without Tags and Image not referenced by any container
Module 15: Flattening Docker Images
In a generic scenario, the more the layers an image has, the more the size of the image.
Flattening an image to a single layer can help reduce the overall size of the image.
Docker Hub is the simplest example that all of us must have used.
● Docker Registry
● Docker Trusted Registry
● Private Repository (AWS ECR)
● Docker Hub
To push the image to a central registry like DockerHub, there are three steps:
2. Tag Docker Image with Registry Repository and optional image tag.
Description Command
Search for Busybox image with Max Result of 5 docker search busybox --limit 5
James has created an application based on Docker. He has the image file in his laptop.
The docker save command will save one or more images to a tar archive
Example Snippet:
The docker load command will load an image from a tar archive
Example Snippet:
docker load < busybox.tar
Docker uses a layer cache to optimize the process of building Docker images and make it
faster.
If the cache can’t be used for a particular layer, all subsequent layers won’t be loaded from the
cache.
We invite you to join our Discord community, where you can interact with our support team for
any course-based technical queries and connect with other students who are doing the same
course.
Joining URL:
http://kplabs.in/chat