watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Docker Is a software that provides a centralized platform to execute applications . It packages software into a complete standardized unit , It 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 , Can start immediately and use less memory . Very safe , Each container is separated from each other . This article will show you how to use Docker, So as to improve our production efficiency .

01

Docker Use the premise

1

Environmental requirements

Before that, we need to see if the environment meets the requirements ( The machine has to be 64 position ,linux Version of must be greater than or equal to 3.10)

$ uname -r

02

Docker Installation

2

Installation steps

2.1

Docker requirement CentOS The kernel version of the system is higher than 3.10, Check the prerequisites to verify your CentOS Does the version support Docker. adopt uname -r  Command to view your current kernel version

$ uname -r

2.2

Use root Permission to login CentOS. Make sure yum The package is updated to the latest .

$ sudo yum update

2.3

Uninstall old version ( If you have an older version installed )

$ sudo yum remove docker docker-common docker-selinux docker-engine

2.4

Install the required packages ,yum-util Provide yum-config-manager, The other two are devicemapper driving-dependent

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

2.5

Set up yum Source

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

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

2.6

You can view all in all repositories docker edition , And select a specific version to install

$ yum list docker-ce --showduplicates | sort -r

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

2.7

install docker

$ sudo yum install docker-ce # because repo On by default stable Warehouse , So the latest stable version is installed here 17.12.0
$ sudo yum install <FQPN> #  for example :sudo yum install docker-ce-17.12.0.ce

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

2.8

Boot and join boot on

$ sudo systemctl start docker
$ sudo systemctl enable docker

2.9

Verify that the installation was successful ( Yes client and service Two-part representation docker Installation and startup were successful )

$ docker version

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Be careful

Because I've installed an older version of docker, Errors are reported as follows 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-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
  file /usr/bin/docker-containerd from install of docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
  file /usr/bin/docker-containerd-shim from install of docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
  file /usr/bin/dockerd from install of docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64

Uninstall old version of package

$ sudo yum erase docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk= 

Re install docker

$ sudo yum install docker-ce

03

Docker Use

3

Usage flow

3.1 Get the image from the warehouse ( Go abroad to download )

docker pull centos:6.6

3.2  Download from foreign images

docker pull daocloud.io/centos:6.6

3.3  Look at the mirror image

docker images

3.4  Image search

docker search centos

3.5  Image creation

docker commit  / docker build  and Dockerfile  To create
    3.5.1: adopt commit To create ( Run the image you just downloaded )
    docker run -it  Mirror name  /bin/bash
    eg: docker run -it centos:6.6 /bin/bash
    3.5.2: stay centos Install in tar  And submit
     docker run -it centos:6.6 /bin/bash
     yum install tar
    docker commit  The name of the instance   My own name :6.6
    docker ps -a : View the currently running instance
    docker images
  3.5.3: See the details of the image
  docker inspect  mirrored id
  3.5.4: delete mirror
  docker rmi --force  Mirror image id  Force a mirror to be deleted
  3.5.5: Delete container
  docker rm  Containers id

04

create mirror (Dockerfile)

4

create mirror

4.1  Prepare the environment

4.1.1: take Tomcat and jdk copy to /usr/local/docker-content in
       
        4.1.2: Unzip the file
         
             tar -zxvf ....

4.2  establish Dockerfile file

FROM centos:6.6
#copy file
RUN mkdir -p /home/demo
ADD ./jdk-8u20-linux-x64.gz /home/demo
ADD ./apache-tomcat-9.0.10.tar.gz /home/demo
ENV JAVA_HOME /home/demo/jdk1.8.0_20
ENV PATH $JAVA_HOME/bin:$PATH
ENV LANG en_us.UTF-8
#EXPOSE
EXPOSE 8080
#init tomcat
ENTRYPOINT /home/demo/apache-tomcat-9.0.10/bin/startup.sh && tail -f /home/demo/apache-tomcat-9.0.10/logs/catalina.out

4.3 create mirror

docker build -t centostj:1.0 .

4.4  Test whether the image is created successfully

docker images

4.5  Run this image

docker run -it  -p 8080  centostj:1.0 /bin/bash

4.6  Look at the binding of the port

docker ps -a

05

Loading and exporting images

5

Loading and exporting images

5.1 Export container (export)

docker export  Example of id  > xxx.tar
         eg:docker export 0c1d5677294c > back.tar

5.2  Import container

cat back.tar | docker import - centostj:v1.0

5.3 Use save Export container

docker save centostj > back1.tar    The one in the middle is the name of the mirror 

5.4 Use load Import mirror

docker load  < docker-seelight.tar

docker logs  Container of id  perhaps   name   Look at the commands used
    Map ports on the mirror to the physical machine
      1:docker run -d -p 5000( Represents the port on the physical machine ):5000( This port on the mirror )  The name of the image   The program to run
   docker ps -l : Look at the last container created
    The way to get into this container :docker exec -it 95c133b8dce9 /bin/bash
   docker cp  Take the outside cp Go inside  docker cp /www/runoob 96f7f14e99ab:/www
   docker stop  Containers id: It means to stop a container
   docker cp  Local file path  ID Full name : Container path   Upload local files to docker in 

I hope this article can help those who haven't been in touch with container deployment , It will be updated later Docker More articles in series , Thank you for your support !

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

If you think that asamura's article will help you , Please search and follow on wechat 「 Shallow feathered IT hut 」 WeChat official account , I'll share my computer information knowledge here 、 Theoretical Technology 、 Tool resources 、 The software is introduced 、 The backend development 、 interview 、 A series of articles, such as thoughts on work and some thoughts on life . What you see and what you get , It's all about life . take your time , Work harder , You and I grew up together ...

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

I set up a technology group , If you want to know more about IT The technology of the industry and the problems in life , Welcome to join the group , Just add my wechat , Note that you can enter the group , We look forward to your participation .

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Previous recommendation

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Dubbo Cluster You don't know that .


watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

About using Druid Configuration of database monitoring


watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

IntelliJ IDEA Hot deployment tools JRebel The use of the tutorial


watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

About Maven, How do I understand and use


watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

One article for you to understand Spring Basic use of framework


watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Java What we need to pay attention to in generics


watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

How to be in Java Create elegant objects to improve program performance


watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

dried food !MySQL Optimization principle analysis and optimization scheme summary


watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Shallow feather

Message area

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

Point a praise , Prove that you still love me