Docker Fundamentals 2022
Docker Fundamentals 2022
What is Docker
Docker is a platform for developers and sysadmins to develop, ship, and run applications by using containers.
Docker aids the user to test and deploy the code into production Quickly!
IMP
V Why use Docker ?
3 Multitenancy
4 Rapid Deployment
What is Application Packaging?
Docker helps you package applications and their dependencies into portable application images that are
straightforward to distribute to artifact repositories and then onto container hosts that will run them
Docker Engine consist of server which a program which called as docker daemon
What is Process Isolation in Docker?
Docker’s container engine and command line tool make it simple to retrieve application images and start
isolated instances of each application process.
host system
Key terms to Remember
Docker’s container engine and command line tool make it simple to retrieve application images and start
isolated instances of each application process.
host system
Workflow to Containerize
any application
builds
run
Read-only
template
docker container
docker image 2
Docker file 1
3
Workflow to Containerize any
application
2 docker build
3 docker run
dockerfile
1
IMP
V Basic Docker Commands
docker build : The docker build command builds Docker images from a
1 Dockerfile
2
7 docker kill : Kill one or more running containers
11
1 docker logs: Fetch the logs of a container
12
2 docker run :Run a command in a new container
IMP
V Step1: Create Docker File
Docker File is text file that consist of all the instructions that are required a docker image.
Each instruction creates a docker layer in the image!
FROM
FROM is used to begin a new build stage. This sets the base image for subsequent
instructions.
Syntax: FROM <image> [AS <name>]
Remember:
It's all ways the First instruction in DockerFile
FROM can be written multiple times to create images in a DockerFile.
name is the build stage in the Dockerfile!
INSTRUCTION LIST
Run
INSTRUCTION LIST
CMD
FROM is used to begin a new build stage. This sets the base image for subsequent
instructions.
Syntax: FROM <image> [AS <name>]
INSTRUCTION LIST
CMD
Remember:
It's all ways the First instruction in DockerFile
FROM can be written multiple times to create images in a DockerFile.
name is the build stage in the Dockerfile!
INSTRUCTION LIST
LABEL
If you wish to add extra information or metadata information to the image you
can use LABEL instruction
Syntax: LABEL <key>=<value>
Remember:
A LABEL is a key-value pair.
Example:
label “application_environment”=”development”
INSTRUCTION LIST
ADD
ADD copies new directories, files, and URLs of remote files from src.
The is a path where the source is copied in the destination container.
Syntax: ADD [--chown=<user>:<group>] <src> .. <dest>
Example:
Shell Form – ADD src dest
add /root/testData /data/
INSTRUCTION LIST
COPY
The COPY copies new directories and files from source.
COPY also adds those new directories and files to the container’s filesystem
at the path <DEST>
Shell Form
Executable Form
copy src dest copy [“src”,”dest”]
copy /root/testData /data/
INSTRUCTION LIST
EXPOSE
EXPOSE sends information to Docker that the container listens on the specified
network ports at runtime.
INSTRUCTION LIST
ENV
ENV is a key-value pair. It sets the <KEY> , an environment variable, to the value
<VALUE>.
These variables will be set during the image build also available after the container
is launched.
Syntax: EXPOSE <port>[PORT/<PROTOCOL>
Remember:
Examples:
env app_dir /data/
INSTRUCTION LIST
USER
USER assigns user name and user group while running the image. It also assigns
user name and user group for the RUN, CMD, and ENTRYPOINT instructions.
INSTRUCTION LIST
VOLUME
Remember:
VOLUME instruction is used to create or mount a volume to the docker container
from the docker host filesystem.
INSTRUCTION LIST
WORKDIR
WORKDIR sets the directory for RUN, CMD, ENTRYPOINT, COPY, and ADD
Remember:
WORKDIR instruction is used to set the working directory.
INSTRUCTION LIST
ARG
ARG defines the variables that are passed by the user to the builder at the build-
time.
Remember:
ARG instruction is also used to set environment variables with key and value, but
this variables will set only during the image build not on the container
IMP
V How to Optimize a Docker File
Remember:
1 Always use Alpine 5 Reduce Number of Layers created byDockerFile