Introduction to Docker and Containerization
Introduction to Docker and Containerization
Using Docker
-I
Components of Introduction to
04 Docker
08 Dockerfile
Hypervisor
CPU 10%
Imagine Software A running on Server A which has Ubuntu running on it. This software can
only run in the Ubuntu environment.
CPU CPU
10% 10%
Server A Server B
Software A Software B
running on running on
Ubuntu Windows
Some time later, we needed Software B which can only run on Windows. Therefore, we
had to buy and run a Server B which had windows running on it. The software took only
10% of the CPU resources.
CPU
20%
Server A
Software A Software B running
Windows and
Ubuntu
Windows and Ubuntu OS now are running on the same server in parallel using the Virtualization
technology. This accounts for better CPU utilization and cost savings!
Container Engine
Operating System
Hardware
Developers when run the code on their system, it would run perfectly. But the same code
would not run on the operations team’s system.
Works fine
on my
system!
Doesn’t work
on my
system.
Faulty code!
Developer Operations/
Testing
The problem was with the environment the code was being run in. Well, a simple answer
could be, why not give the same VM to the operations/testing team to run the code.
Well, try
the VM
that I’m That could break
working in. another code on
testing/production
server!
Developer Operations/
Testing
With containers, all the environment issues were solved. The developer could easily wrap
their code in a lightweight container and pass it on to the operations team.
Here is the
container. I
have
Wow, it’s hardly 30
wrapped my
MB. Awesome,
code in.
your code works
just fine!
Developer Operations/
Testing
Pull
run
Docker Hub Push
stop
delete
Container Stages
Containers
Docker Volumes
Docker
File © Copyright 2019 IntelliPaat, All rights reserved
Components of Docker Ecosystem
Docker Hub
Docker Engine is the heart of the docker ecosystem.
Containers
Docker Volumes
Docker
File © Copyright 2019 IntelliPaat, All rights reserved
Components of Docker Ecosystem
Docker Hub
Docker Image is like the template of a container.
It is created in
Docker Engine layers.
Any new changes in the image results in creating a
new layer.
Docker Images
One can launch multiple containers from a
single docker image.
Containers
Docker Volumes
Docker
File © Copyright 2019 IntelliPaat, All rights reserved
Components of Docker Ecosystem
Docker Hub
A Docker Container is a lightweight software
environment.
Containers
Docker Volumes
Docker
File © Copyright 2019 IntelliPaat, All rights reserved
Components of Docker Ecosystem
Docker Hub
Docker Containers cannot persist data.
Docker Volumes
Docker
File © Copyright 2019 IntelliPaat, All rights reserved
Components of Docker Ecosystem
Docker Hub
Dockerfile is a YAML file, which is used to
create custom containers
Docker Engine
It can include commands that have to be run on the
command line
Docker Images This Dockerfile can be used to build custom
container images
Containers
Docker Volumes
Dockerfile
© Copyright 2019 IntelliPaat, All rights reserved
Installing
Docker
© Copyright 2019 IntelliPaat, All rights reserved
Common Docker
Commands
© Copyright 2019 IntelliPaat, All rights reserved
Common Docker Commands
docker --
version
This command helps you know the installed version of the docker software on your system.
This command helps you pull images from the central docker repository.
docker
images
This command helps you in listing all the docker images downloaded on your system.
docker
ps
This command helps in listing all the containers which are running in the system.
docker ps -
a
If there are any stopped containers, they can be seen by adding the -a flag in this command.
docker exec
<container-id>
For logging into/accessing the container, one can use the exec command.
docker stop
<container-id>
docker kill
<container-id>
docker rm
<container-id>
1. Navigate to [Link]
4. Click on Sign up
Let’s try to accomplish the following example with a container and see how we can
commit this container into an image.
Commit these
changes to
the container
apt-get update
apt-get install
apache2
The username has to match with the username you created on DockerHub.
The container-name can be anything.
on DockerHub
© Copyright 2019 IntelliPaat, All rights reserved
Pushing the Container on DockerHub
1. The first step is to login. It can be done using the following command:
docker login
docker push
<username>/<container-id>
A Dockerfile is a text document that contains all the commands a user could call on the command line to
assemble an image. Using the docker build, users can create an automated build that executes several
command-line instructions in succession.
RUN Example
FROM ubuntu
CMD
Dockerfile
ENTRYPOINT
ENV
RUN Example
FROM ubuntu
ADD . /var/www/html
CMD
Dockerfile
ENTRYPOINT
ENV
RUN Example
FROM ubuntu
RUN apt-get update
CMD RUN apt-get -y install apache2
ADD . /var/www/html
ENTRYPOINT
ENV
Dockerfile
RUN Example
FROM ubuntu
RUN apt-get update
CMD RUN apt-get -y install apache2
ADD . /var/www/html
CMD apachectl –D
ENTRYPOINT FOREGROUND
ENV
Dockerfile
RUN Example
FROM ubuntu
RUN apt-get update
CMD RUN apt-get -y install apache2
ADD . /var/www/html
ENTRYPOINT apachectl –D
ENTRYPOINT FOREGROUND
ENV
Dockerfile
RUN Example
FROM ubuntu
RUN apt-get update
CMD RUN apt-get -y install apache2
ADD . /var/www/html
ENTRYPOINT apachectl –D
ENTRYPOINT FOREGROUND
ENV name Devops Intellipaat
ENV
Dockerfile
Example
FROM ubuntu
RUN apt-get update
RUN apt-get -y install apache2
ADD . /var/www/html
ENTRYPOINT apachectl -D
FOREGROUND
ENV name Devops Intellipaat
Dockerfile
2. Enter into this directory and create a file called ‘Dockerfile’, with the same contents as the sample Dockerfile.
3. Create one more file called ‘[Link]’ with the following contents.
7. Finally, login into the container and check the variable $name. It will have the same value as given in the Dockerfile.
A. True
B. False
A. True
B. False
A. Docker save
B. Docker
commit
C. Docker push
D. None of these
A. Docker save
B. Docker
commit
C. Docker push
D. None of
these
3. is a service from Docker which provides registry capabilities for public and
private Docker Images.
A. Docker Cloud
B. Docker Community
C. Docker Hub
D. None of these
3. is a service from Docker which provides registry capabilities for public and
private Docker Images.
A. Docker Cloud
B. Docker Community
C. Docker
Hub
D. None of these
A. True
B. False
A. True
B. False
5. Containers, running on the same machine, share the underlying kernel of the host
OS.
A. True
B. False
5. Containers, running on the same machine, share the underlying kernel of the host
OS.
A. True
B. False
support@[Link]