DOCKER
Speaker: VinhPH2
Why docker
● Problem in Software Development?
○ Install all the necessary dependencies
in our local machine.
○ Application project ready to be
deployed.
○ But, we had to install all the
dependencies in our local machine?
○ Consuming several hours in
configuring every single detail...
● Containerized applications was born.
History
Docker
● Docker is a tool
designed to make it
easier to create,
deploy, and run
applications by using
containers.
Docker
Docker Image
● A Docker container image is a lightweight,
standalone, executable package of software.
● Images become containers when run on
Docker Engine.
● All primary images are stored in a large
repository called Docker Hub.
Docker Hello World
● Install
○ $ sudo apt install docker.io
● Run image Hello World
○ $ docker run hello-world
Docker Image Command
● Pull image từ Docker Hub
○ $ docker pull <image>
○ Ex: $ docker pull nginx.
○ It downloads the latest official image from the docker hub.
● You can specify the tag (simply version) of the image.
○ $ docker pull <image:tag>
○ Ex: $ docker pull nginx:1.14.2
● List all the images in local machine.
○ $ docker image ls
Docker Container Command
● Run an instance of an image: Container.
○ $ docker container run --rm -p
<host_port>:<container_port> --name
<container_name> <image_name>
○ --rm: force remove after shutdown container.
○ -p: port forwarding.
○ We build images, we run containers
○ A container is just a process in your host machine.
Docker Container Command
● Detach container from foreground and put them in
background.
○ Add flag -d
○ Ex: $ docker container run --rm -d -p 80:80 --name
myNginx nginx
● List all the containers are running in local machine
○ $ docker container ls
Docker Container Command
● Docker run container with interactive mode, help to run
command inside a container
○ $ docker container exec -it <container> <command>
○ Ex: docker container exec -it myNginx bash
● There are some command to control the container.
○ $ docker container <action> <container_name>
○ Action can be restart, stop, start
● Remove container:
○ $ docker container rm -f <container_name>
Docker Storage
● By using Storage in Docker we can persist data or files
from the host system into our containers
● There are two techniques:
○ Bind Mounts: are used to storing files and directories into the
container.
■ Add flag -v <path in host>:<path in container>
■ Ex : $ docker container run --rm -p 80:80 --name
myNginx -v $(pwd)/html:/usr/share/nginx/html nginx
○ Volumes: are used to persist data. You will use them for your
Databases.
Docker Networking
● If you want to connect two or more containers, so that they can
communicate with each other, they have to share the same
network.
● Create network.
○ $ docker network create <network name>
○ Ex: $ docker network create my-network
● Link container to network
○ Add flag --network <network name>
○ Ex: $ docker container run -d --rm --network my-network --name
myNginx nginx
Dockerfiles
● Write Dockerfile to custom image.
● Command in Dockerfile.
Dockerfiles
● Build Dockerfile to Image
○ $ docker build -t <name image> <path dockerfile>
○ Ex: $ docker build -t custom-Nginx .
Next step
● Docker compose.
● Docker Swarm.
● Kubernetes.
THANK YOU!