Docker is software that provides a centralized platform to execute applications. It wraps the software into a complete standardized unit that contains everything to run. Whether it’s code, runtime environment, tools, or libraries. It ensures that the software always works as expected. It provides the ability to run applications in an isolated environment called a container. We can run multiple containers on the host at the same time. And it’s lightweight, starts up immediately and uses less memory. It’s safe. Each container is separate from each other. This article will take you to understand how to use Docker, so as to improve our production efficiency.

01

Docker use prerequisites

1

Environmental requirements

Before doing so, we need to check whether the environment meets the requirements (the machine must be 64-bit and Linux version must be 3.10 or greater).

$ uname -r
Copy the code

02

The installation of a Docker

2

** Installation steps **

2.1

Docker requires a CentOS kernel version later than 3.10. Check whether your CentOS version supports Docker. Check your current kernel version with the uname -r command

$ uname -r
Copy the code

2.2

Log in to CentOS as user root. Make sure the YUM package is up to date.

$ sudo yum update
Copy the code

2.3

Uninstall the old version (if one has been installed)

$ sudo yum remove docker docker-common docker-selinux docker-engine
Copy the code

2.4

Install the required package, yum-util provides yum-config-manager, the other two are dependent on devicemapper driver

$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Copy the code

2.5

Set the yum source

$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Copy the code

2.6

You can view all docker versions in all repositories and select a specific version to install

$ yum list docker-ce --showduplicates | sort -r
Copy the code

2.7

Install the docker

# $sudo yum install docker-ce # $sudo yum install <FQPN> # Sudo yum install docker - ce - 17.12.0. CeCopy the code

2.8

Start and join boot boot

$ sudo systemctl start docker$ sudo systemctl enable docker
Copy the code

2.9

Verify whether the installation is successful (client and Service indicate that the installation and startup of Docker are successful)

$ docker version
Copy the code

Pay attention to

Because the old version of Docker was installed before, the following error was reported during installation:

Transaction check error: File /usr/bin/docker from install of docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package Docker 2-1 - common - 12.6-68. Gitec8512b el7. Centos. X86_64 file/usr/bin/docker - containerd from the install of Docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package Docker 2-1 - common - 12.6-68. Gitec8512b el7. Centos. X86_64 file/usr/bin/docker containerd - shim the from the install of Docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package Docker 2-1 - common - 12.6-68. Gitec8512b el7. Centos. X86_64 file/usr/bin/dockerd from the install of Docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package Docker 2-1 - common - 12.6-68. Gitec8512b el7. Centos. X86_64Copy the code

Uninstall packages of earlier versions

$sudo yum erase docker - common - 2:1. 12.6-68. Gitec8512b el7. Centos. X86_64Copy the code

Install docker again

$ sudo yum install docker-ce
Copy the code

03

The use of the Docker

3

** Uses the process **

3.1 Obtaining an Image from the Warehouse

Docker pull centos: 6.6Copy the code

3.2 Download it from a foreign image

Docker pull daocloud. IO/centos: 6.6Copy the code

3.3 Viewing a Mirror

docker images
Copy the code

3.4 Mirror Search

docker search centos
Copy the code

3.5 Creating a Mirror

3.5.1: Create (run) docker run -it /bin/bash Docker run -it centos:6.6 /bin/bash yum install tar docker run -it centos:6.6 /bin/bash yum install tar docker 6.6 docker ps -a: view the running instance docker images 3.5.3: View the details of the image docker inspect ID 3.5.4: Delete the image docker Rmi --force Mirror ID Forcibly delete an image 3.5.5: Deleting a container Docker RM container IDCopy the code

04

Create an image (Dockerfile)

4

** Create mirror **

4.1 Preparing the Environment

4.1.1: Copy Tomcat and JDK to /usr/local/docker-content 4.1.2: Decompress tar -zxvf....Copy the code

4.2 Creating a Dockerfile File

FROM centos:6.6#copy fileRUN mkdir -p /home/demoADD ./jdk-8u20-linux-x64.gz /home/demoADD ./apache-tomcat-9.0.10.tar.gz /home/demoENV JAVA_HOME /home/demo/jdk1.8.0_20ENV PATH $JAVA_HOME/bin:$PATHENV LANG en_us.UTF-8#EXPOSEEXPOSE 8080#init tomcatENTRYPOINT /home/demo/apache-tomcat-9.0.10/bin/startup.sh && tail -f /home/demo/apache-tomcat-9.0.10/logs/catalina.out
Copy the code

4.3 Creating a Mirror

Docker build-t Centostj :1.0Copy the code

4.4 Testing whether a Mirror is successfully created

docker images
Copy the code

4.5 Running the image

Docker run it -p 8080 centostj:1.0 /bin/bashCopy the code

4.6 Checking Port Bonding

docker ps -a
Copy the code

05

Image loading and exporting

5

** Image loading and exporting **

5.1 Exporting Containers (Export)

Docker export instance ID > xxx.tar eg:docker export 0c1d5677294c > back.tarCopy the code

5.2 Importing Containers

The cat back. Tar | docker import - centostj: v1.0Copy the code

5.3 Using Save to Export containers

Docker save Centostj > back1.tarCopy the code

5.4 Importing Image Files using Load

Docker load < docker-seelight. Tar Docker logs container id or name Docker ps -l: docker ps -l: docker ps -l: docker ps -l: docker ps -l: docker ps -l: Docker cp/WWW /runoob 96f7f14e99ab:/ WWW docker stop docker stop Docker cp local file path ID Full name: container path upload local file to dockerCopy the code

I hope this article will be helpful to those who have not been exposed to containerized deployment. We will update the Docker series with more articles in the future. Thank you for your support!

“Like” to prove you still love me