Docker Example
Docker Example
Docker introduction
Agenda
• Containerization and virtualization
• Install Centos
• Install Docker
• Download images
# Type
Linux text
Set Host
Set Region
Set HDD
Set Network
Setup Centos
disable iptables, selinux
# disable firewalld
systemctl disable firewalld
# See status
systemctl status firewalld
Setup Centos
# disable SELinux
setenforce 0
# Edit file
vi /etc/sysconfig/selinux
# change SELINUX=enforcing
# to SELINUX=disable
Connect from Windows
Download PuTTY
https://www.putty.org/
Install Docker
Install Docker
# update repository epel
yum -y install epel-release
# check
yum –y provides docker
# install docker (from Centos Repository)
yum –y install docker
# add to auto-start
systemctl enable docker
Download
images
Download images
# download image from docker hub
docker pull <image name>
# download linux+java
docker pull openjdk
Download images
https://hub.docker.com/
# check by curl
curl -i http://192.168.153.131:8282/tokenlifetime
Copy files
scp (secure copy) command in Linux system
# stop container
docker stop <id/name>
Check by curl
# login
curl -i -X POST --data "name=admin&password=qwerty"
http://192.168.153.131:8282/login
# delete container
docker rm <id/name>
# delete image
docker rmi <id/name>
Building
Docker Images
with Dockerfiles
Dockerfiles
Dockerfile – the file describes the software that will be packaged into an image.
Create Dockerfile
# Create a new directory
mkdir mydockerbuild
The option -p 8282:8080 exposes the Container port 8080 as the Host port 8282
to the world
Dockerfile
FROM openjdk:8-jdk
WORKDIR /server/
EXPOSE 8080
# Expose port 80
EXPOSE 80
# Last is the actual command to start up NGINX within our Container
CMD ["nginx", "-g", "daemon off;"]
Dockerfile commands
# ADD – Defines files to copy from the Host file system onto the Container
ADD ./local/config.file /etc/service/config.file
# CMD – This is the command that will run when the Container starts
CMD ["nginx", "-g", "daemon off;"]
CMD Hello World
# FROM – Select the base image to build the new image on top of
FROM ubuntu:latest
# LABEL maintainer – Optional field to let you identify yourself as the maintainer
of this image.
LABEL [email protected]"
Dockerfile commands
#RUN – Specify commands to make changes to your Image and subsequently the
Containers started from this Image.
RUN apt-get update && apt-get upgrade -y && apt-get install -y nginx && rm -rf
/var/lib/apt/lists/*
#USER – Define the default User all commands will be run as within any
Container created from your Image.
USER docker
Dockerfile commands
#VOLUME – Creates a mount point within the Container linking it back to file
systems accessible by the Docker Host.
VOLUME /var/log
#WORKDIR – Define the default working directory for the command defined in
the “ENTRYPOINT” or “CMD” instructions
WORKDIR /home
References
Reference documentation
https://docs.docker.com/reference/
Dockerhub
https://hub.docker.com/
Docker overview
https://docs.docker.com/get-started/overview/