Summary
Docker and Kubernetes
Docker Images and
Understanding Containers
Docker
Docker and Kubernetes
Overview of Docker
Understanding This is an open platform used for
Docker developing, shipping and running
applications.
Here you can run your application in an
isolated environment called a container.
Developers can easily create applications
and ship them via containers.
Containers are light-weight in nature.
You can easily deploy containers onto multiple
environments such as development and production.
Docker Desktop
• This is a graphical user interface tool that can be used to
Docker and Kubernetes manage your containers.
• This tool is available for Windows and MacOS.
Understanding • You can manage your images and containers from one tool.
Docker
Docker Hub
• This is an online repository for your Docker images.
Docker and Kubernetes • Docker Hub has a lot of pre-built images.
• You can also share your own Docker images by publishing
Understanding them onto Docker Hub.
Docker
Docker and Kubernetes
Understanding Images and
Containers
Docker
Images Containers Docker Docker
client
This tool is used daemon
This process is
This is a read- This is a running
only template instance of the to issue Docker- used to listen for
that has container. specific Docker
instructions on commands. commands.
how to run the
container.
Docker and Kubernetes
We want the
Understanding Docker
container to run in
the background.
Here we specify the
name of the image
docker run –d –p 80:80 nginx
The docker run
command is used to
We want to publish
create a new
port 80 of the
container
container onto port
80 of the host
machine.
Docker and Kubernetes
Understanding Docker
Command Description
docker images This command is used to list the images.
docker inspect This command can be used to inspect images and containers.
docker ps This command will list the running containers.
docker ps -a This command will list all containers.
docker start -a This command can be used to start a container.
Docker and Kubernetes
Understanding Docker
Command Description
docker rm This command is used to remove a container.
docker rmi This command is used to remove an image.
docker attach This command will attach you to a running container.
docker build This command is used to build a custom image.
Docker and Kubernetes
Understanding Docker
• The Dockerfile can be used by
Docker to build a custom image.
• This is a text file that is parsed by
Docker. The image will be created
based on the instructions.
Summary
Docker and Kubernetes
Docker – Building your
Understanding own Custom Image
Docker
Assigning names for
containers
• By default, Docker will assign a name for the container.
Docker and Kubernetes • But you can assign your own name for the container
which can be referenced later on.
Understanding • docker run --name [container-name] [image-name].
Docker
Removing a container after
exit
• You can ensure a container is removed after it’s
Docker and Kubernetes stopped.
• docker run --rm [image-name].
Understanding
Docker
Docker and Kubernetes
Understanding Docker
• You can have different tags for
your images.
• One use case is to have
different versions for your
images.
The CMD instruction
• The CMD instruction in the Dockerfile can be used to
Docker and Kubernetes provide defaults for the executing container.
• For example you can make it run an executable and pass
Understanding parameters as well to the executable.
Docker
The log options
• You can get the logs from the Docker container at the
Docker and Kubernetes time of execution – docker logs [container-name].
• You can also continuously stream logs – docker logs --
Understanding follow.
Docker
Connecting containers
• Your docker containers by default are attached to a
Docker and Kubernetes default docker network.
• Your containers get an IP address.
Understanding
Docker
Summary
Docker and Kubernetes
Docker Networking and
Understanding Data
Docker
Docker and Kubernetes
Docker Networking
Understanding The Docker containers are launched as part
Docker of a Docker network.
The bridge is the default network driver used for
the network. You have other drivers as well.
Each Docker container gets an IP address on
the network.
Containers can communicate with each
other via the IP addresses.
You can run the docker inspect command to see the
networking details for a container.
Docker and Kubernetes
Understanding Docker
networking
Docker
Network Inspect Connect Run
The docker You can inspect You can connect a Or when running a
network create the network with container to a container you can
command can be the docker network with the make sure the
used to create a inspect docker network container is
network. command. connect command. attached to a
network.
Copying files to a container
• You can copy files to and from a container.
Docker and Kubernetes • docker cp Courses.txt 0bd:/var/www/html.
• The above command can be used to copy the
Understanding Courses.txt file onto the container with an ID of 0bd and
Docker in the directory of /var/www/html.
Using bind mounts
• This can be used to bind a file or a directory from the
Docker and Kubernetes local machine onto the container.
• docker run --name phpapp --mount
Understanding type=bind,source=/mnt/c/tmp6,target=/var/www/html.
• The above command binds the local directory on
Docker /mnt/c/tmp6 onto the container directory of
/var/www/html.
Using a .dockerignore file
• This can be used to exclude files and directories from
Docker and Kubernetes the build context.
• This helps to ensure that unwanted files are not part of
Understanding the build context. This helps to improve the build speed
Docker of your images.
Multi-stage builds
• Here you can have different FROM statements in your
Docker and Kubernetes Dockerfile.
• You can have different stages for your build process.
Understanding • For example, you can have one stage to build your
Docker application and another stage to copy the binary files.
Summary
Docker and Kubernetes
Docker Compose and
Understanding Docker hub
Docker
Docker compose
• This tool can help build and deploy your multi-container
Docker and Kubernetes applications.
• Here a YAML file is used to define the services that will
Understanding run as part of your application.
Docker • Once you have defined your services, you can use
simple commands to have them up and running.
Docker and Kubernetes
Simple docker compose file
Understanding You name the file as docker-compose.yaml.
Docker
You can then define the version of Docker
compose you are using.
A service is an abstract definition of a resource within
an application.
.
The services are backed by containers. Each
service can be scaled independently.
We can publish the ports for our container similar to
when using the docker run command.
Docker and Kubernetes
Understanding Docker
Command Description
docker compose This command is used to bring your docker services up.
up
docker compose up - This command can be used to run the containers in daemon
d mode.
docker compose This command is used to bring the services down.
down
Docker and Kubernetes
Understanding Docker
• If the underlying image can take
environment values you can
define them accordingly.
• Here we are defining the
password to be used for the
root user of the MySQL
database server.
Docker and Kubernetes
Making use
Understanding Docker of volumes
Here we reference
the volume, and
where on the target
container the
volume will be used
to store data
Here we can define a
volume and also
define the name of
the volume.
Docker and Kubernetes
Making use
Understanding Docker of networks
We can ensure that
our container starts as
part of the network.
We can then reference
the container by its
name.
Here we can define a
network. We can also
configure an IP
address for the
network.
Docker and Kubernetes
Building our
Understanding Docker images
We can ask docker
compose to build our
images if they are not
present and then use
the container built out
of the image.
Docker and Kubernetes
Kubernetes
Understanding This is an open-source system.
Kubernetes
It helps to manage the deployment and
management of your container-based
applications.
You can run Kubernetes on your on-premises
machines or on the cloud.
You get various features like self-healing
which can restart containers if they fail.
You get additional features such as service discovery
and load balancing.
Docker and Kubernetes
Understanding
Kubernetes
• When you use Kubernetes you need
to setup a cluster.
• As part of the cluster you have a
master node and worker nodes.
• Your workloads run on the worker
nodes.
• The control plane runs on the
master node.
Docker and Kubernetes
Understanding
Kubernetes Kube-apiserver
• This services sits on the control
plane.
• When you make a request to the
Kubernetes cluster, the request
goes to the API server.
• The API server then manages the
request accordingly.
Docker and Kubernetes
Understanding
Kubernetes etcd
• This services sits on the control
plane, on the master node.
• This is a key-value data store.
• When the API server receives a
request, this could be for the
Nodes, pods etc, the data is
persisted to etcd.
Docker and Kubernetes
Understanding
Kubernetes Kube-controller
• You have various controllers that are
used to manage different aspects.
• Node controller – This is used for
managing the nodes.
• Replication Controller is used for
monitoring the replica’s when it
comes to the pods.
Docker and Kubernetes
Understanding
Kubernetes Kube-scheduler
• The scheduler decides the node that
pod should run on.
• This is required , because the node
should have sufficient capacity to
run the pod.
• The scheduler does not run the
pod, it just schedules the pod on
the required node.
Docker and Kubernetes
Understanding
Kubernetes kubelet
• The kubelet tool actually runs the
pod on the node.
• It downloads the required image
and creates a container out of the
image.
• It monitors the pod and sends the
status of the pod to the kube api
• server.
This service runs on the worker
node.
Docker and Kubernetes
Understanding
Kubernetes Kube-proxy
• This helps in communication across
the pods.
• Each pod gets its own IP address.
• Each pod becomes part of a pod
network.
• The kube proxy tool runs on every
worker node.
Docker and Kubernetes
Understanding
Kubernetes Pod
• The containers are encapsulated
within pods.
• This is the smallest object that you
can create in Kubernetes.
• A pod is used to represent a single
instance of your application.
Docker and Kubernetes
Understanding Understanding
pods
Kubernetes
• You can have different containers running in a pod.
Pod Connect Run
• But normally you will run containers in different pods.
You can connect a Or when running a
• Only if the containers are container
tightly coupled
to a you would consider
container running
you can
Container them in one pod. network with the make sure the
docker network container is
Container connect command. attached to a
network.
Docker and Kubernetes
Understanding Understanding
pods
Kubernetes
Pod Pod Connect Run
• Here the application and database can
You can connect a Or when running a
run in different pods.
container to a you can make sure
Application Database •network
The Utility container couldtherun
with the scriptsis
container
docker network
that are attached to a
required for application
connect command. network.
startup.
Utility
Docker and Kubernetes
Understanding Understanding
pods
Kubernetes
Pod Pod Connect Run
• You can also run multiple instances of
You can connect a Or when running a
your application container.
container to a you can make sure
Application Application
Database •network
This iswith
donethevia running multiple podsis
the container
docker network
at a time. attached to a
connect command. network.
• And this is all managed by Kubernetes.
Utility Utility
Docker and Kubernetes
Understanding Understanding
pods
Kubernetes
Pod Pod Connect Run goes
• Also let’s say that the application
down in the container.
You can connect a Or when running a
• Kubernetes
container to a will not launch
you
a can
newmake sure
Application Application
Database network with in
thethe pod. the container is
container
docker network attached to a
•connect
It will actually
command.create a brand-new
network. pod.
Utility Utility • That is why pods are considered
ephemeral in nature.
Creating Kubernetes
objects
• To deploy Kubernetes objects, we can define the objects
Docker and Kubernetes using YAML files.
• We can interact with the Kubernetes cluster using
Understanding kubectl.
• This is a command line tool that is used to communicate
Kubernetes with the control plan of the Kubernetes cluster.
Docker and Kubernetes The name for the object.
What is the type of
The number of pods we
Kubernetes object.
want to run.
The label selector helps the
The template is based on
deployment to understand
the Pod specification
the pods that need to be
template.
managed by the
A label is a name-value
deployment.
pair. This can be attached
We provide information to a pod. It helps to provide
about the image that is meaningful attributes for
needed for the container the pod.
and also what is the port
number to expose from the
container.
Docker and Kubernetes The name for the object.
What is the type of
What are the pods this
Kubernetes object.
service is linked to.
What is the port number to
expose on the service and
what is the port number to
map to the pod.
What is the type of service.
Creating Kubernetes
objects
• ClusterIP – This assigns an IP address from the pool of IP
Docker and Kubernetes addresses of the cluster.
• NodePort – This helps expose the application on a port
Understanding number of the node.
Kubernetes • LoadBalancer – Here you can use an external load
balancer to distribute requests across the pods.