Docker installation steps - the most reliable notes

Liu Xiaoran 2021-01-21 17:41:36
docker installation steps reliable notes


 

One 、 System environment planning

Server name

 

Project name

docker

operating system

CentOS Linux release 7.1.1503 (Core)

Docker edition

17.03.2-ce

 

Two 、Docker brief introduction

Docker A container can be simply understood as a lightweight virtual machine , Containers are isolated from each other . There is isolation on the operating system between virtual machines and virtual machines , And between containers is process isolation .

Use Docker It can bring us great convenience , such as : You can create multiple containers on a single host , Use as multiple nodes ; Install multiple... On one machine MySQL example , Their ports are 3306; We can package our applications and so on .

Docker Official homepage : https://www.docker.com

Docker Official documents : https://docs.docker.com/

Docker Hub: https://hub.docker.com

 

3、 ... and 、Docker Installation

Docker Running on the CentOS 7 On , The system is required to be 64 position 、 The kernel version of the system is 3.10 above .Docker Running on the CentOS-6.5 Or later CentOS On , The system is required to be 64 position 、 The kernel version of the system is 2.6.32-431 Or higher CentOS 7 In general, the kernel of is 3.10 Of , and CentOS 6.X In general, the kernel of is 2.6, stay 2.6 Under the core of ,Docker Running will be more card , So you usually choose to upgrade to 3.10 edition .

 

3.1、 Uninstall the old version of the system docker

yum remove -y docker docker-client docker-client-latest docker-common \

docker-latest docker-latest-logrotate docker-logrotate \

docker-selinux docker-engine-selinux docker-engine

 

3.2、 Install related dependency packages :

install docker You may report errors, missing packages, or low version of dependent packages , Install or upgrade dependent packages as appropriate .

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

 

3.3、 To configure docker Source

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

 

 

3.4、 install docker

     Before installation, we can check which ones are available docker edition

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

 

 

install docker: So here's what we installed 17.03.2 edition .

 yum install -y --setopt=obsoletes=0 docker-ce-17.03.2.ce-1.el7.centos.x86_64 \

 docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch

 

 

3.5、 We can also use the official script to install docker   

curl -fsSL get.docker.com -o get-docker.sh

sh get-docker.sh

 

Four 、 see Docker Version and related information

4.1、 installation is complete , see docker Version information

 

 

4.2、 start-up docker

      installed docker The service is not started , Service start required .

systemctl enable docker

systemctl start docker

 

To start over , see docker Service status :

 

4.3docker info see docker Related information

 

5、 ... and 、 Pull the image to create the container

Image( Mirror image ) and Container( Containers ) yes Docker Two basic concepts in .

Here Image It can be understood as the operating system image needed to create a virtual machine , in other words Image It's the image needed to create the container .

We need to pull images from the Internet : This is a centos 7.6 Mirror image

docker pull centos:7.6.1810  

 

Pull over , View downloaded images :

 

 

  With the image, we can use the image to create the container .

 

Of course, images of other versions can also be downloaded

download 7.8 Mirror image

[root@docker ~]# docker pull centos:7.8.2003

7.8.2003: Pulling from library/centos

9b4ebb48de8d: Pull complete

Digest: sha256:8540a199ad51c6b7b51492fa9fee27549fd11b3bb913e888ab2ccf77cbb72cc1

Status: Downloaded newer image for centos:7.8.2003

 

6、 ... and 、 Create a container

6.1、 We use docker ps perhaps docker ps -a Command to view all the container information , as follows , There are currently no containers , So let's create one .

 

 

 

docker run -d --name centos7_6_01 -h container_01 \   

-p 220:22 \

--privileged=true \

centos:7.6.1810 /usr/sbin/init

 

Parameter interpretation :

--name centos7_6_01   Name the container :centos7_6_01

-h container_01 For containers hostnamecontainer_01

-p 220:22    For will 22 Port maps to 220, That is to say, you can use 220 The port connects directly to this container

centos:7.6.1810 Choose which image to use to create the container

 

Creation completed ,docker ps Check out the current container :

 

 

 

Here we see a NAMES by centos7_6_01 The container .

There are two ways to get into a container , as follows :

 docker exec -it  <NAMES>  bash

 docker exec -it  <CONTAINER ID>  bash

That is, you can directly use the container name or container ID To enter

 docker exec -it centos7_6_01 bash

 docker exec -it ed20ee9b8226 bash

 

 

6.2、 Each container has its own IP Of ,IP You can specify... At creation time , It can also automatically generate .

 

 

6.3、 Modify container time :

After the container is created , The internal time is inconsistent with the host operating system , Need modification .

 

 

 

On the host operating system :

docker cp /usr/share/zoneinfo/Asia/Shanghai centos7_6_01:/etc/localtime

  After modification, enter the container again :

 

 

7、 ... and 、 Submit a container as an image template

Docker You can submit a container as a image, In other words, we can use a container as a template to create or copy a container , This can provide us with great convenience , Save more time .

such as : We are centos7_6_01 It's installed in the container MySQL Database and related configuration , We also need to create a container with the same environment and configuration centos7_6_02, So we're going to create an empty container first , Then go and install MySQL Database and other configuration information , Or just put centos7_6_01 As a template, copy a container directly ? Of course, it's faster and more efficient to copy one directly .

View the current container and image information as follows , We put name by centos7_6_01 The container is submitted as a template for our subsequent use , It can also be said that centos7_6_01 Replication to achieve an automated deployment function .

 

 

We put the container centos7_6_01 Submitted as centos7_6  Version is 2.0 A mirror image of :

docker commit centos7_6_01 centos7_6:2.0

 

Let's create a container with the newly created image : Create a file called mysql_01, The host name is mysql_01, Port is 221 The container of :

docker run -d --name mysql_01 -h mysql_01 \

-p 221:22  \

--privileged=true \

centos7_6:2.0 /usr/sbin/init

 

 

At this point we created mysql_01  The container is just like centos7_6_01 The containers are exactly the same .

Containers mysql_01  Have an independent ip Address .

 

 

版权声明
本文为[Liu Xiaoran]所创,转载请带上原文链接,感谢
https://javamana.com/2021/01/20210121173837998h.html

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云