Docker Lec 23, 24, 25, 26, 27
Docker containers are
very much like a virtual
machine but they don't
have their own OS. They
consume resources only
when they are in need
Docker
It is written in
GO language
Docker uses linux
to run itself either
installed on windows
It performs OS level
virtualization called
containerization in place
of Hardware level
virtualization that VM-
ware perfomrs
It is PaaS
(Platform as
a service)
commands
docker images
docker search [query|string]
docker pull [image_name]
docker run -it --name [give any name]
[image_name] /bin/bash
service docker status
docker start [container_name]
docker attach [container_name]
docker ps -a
docker ps
docker stop [container_name]
docker rm [container_name]
see images present
on local machine
download and run
image or only run
-it :interactive, terminal
-td :terminal, daemon
search images on
docker hub
pull any image
from docker hub
check docker
engine status
To start docker
container
To interact with
container
status of all containers
-ps :process status
status of only
running containers
To stop a
container
To delete a
container
service docker [start|stop]
start or stop
docker engine
cat /etc/os-release
see your OS on
linux or container
difference between containers
between build time and now
docker diff [container_name]
Where in the output
A = append
C = change
D = delete
create an image from
current container state
docker commit [container_name]
[image_name]
Dockerfile
'D' should be capital.
It is a text file and all
the following commands
are written in capital
FROM
for base image, always
on top of all commands
RUN
To execute commands,
it will create a layer in image
MAINTAINER
Author/Owner/Description
COPY
Copy files from local
system(docker VM),
we need to provide
source and destination
ADD
Downlaod and extract .gz
file from the internet
EXPOSE
To expose ports such as
8080 for tomcat, 80 for nginx
WORKDIR
Set working directory
for the container
CMD
Execute commands during
container creation
ENTRYPOINT
Similar to CMD, execute
commands before CMD
ENV
Environment Variables
ARG
Variable that users can pass
at build-time to the builder
Build image from Dockerfile
docker build -t [image_name] ./
FROM ubuntu
WORKDIR /tmp
RUN echo "docker img creation" >> /tmp/testfile
COPY testfile1 /tmp
ADD test.tar.gz /tmp
ENV name rajput
here testfile1 and
test.tar.gz should already
present on local machine