一、Docker简介
百科说:Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化,容器是完全使用沙箱机制,相互之间不会有任何接口。
看起来有点雾,用过虚拟机的应该对虚拟化技术有点印象,不知道也没关系,就把它当成轻量级的虚拟机吧(虽然一个是完全虚拟化,一个是操作系统层虚拟化),这个解释到位:
百科又说:Docker 使用客户端-服务器 (C/S) 架构模式 使用远程API来管理和创建Docker容器。Docker 容器(Container)通过 Docker 镜像(Image)来创建,二者之间的关系类似于面向对象编程中的对象与类
那Docker由什么组成呢, 包括三个基本概念:
仓库(Repository)
镜像(Image)
容器(Container)
打个比方:你如果想玩英雄联盟中骚气的亚索,你首先得有这个英雄(Docker的镜像),然后你得花金币去英雄商店(Docker的仓库)买,接着进游戏就会看到一个半蹲的发型飘逸的剑客(Docker的容器),所以:
1,其中Registry是Docker用于存放镜像文件的仓库,Docker 仓库的概念跟Git 类似(就像商店存放所有的英雄,只是更改英雄的权限在某些非程序员手里)。
2,所谓镜像就是构建容器的源代码,是一个只读的模板,由一层一层的文件系统组成的,类似于虚拟机的镜像(英雄也是只读的,有自己的技能被动,你也不能进行操作)。
3,那么容器就是由Docker镜像创建的运行实例,类似于虚拟机,容器之间是相互隔离的,包含特定的应用及其所需的依赖文件(好比每个英雄都是隔离的,都有自己的皮肤,技能以及走的路线)。
注:Docker Hub
是Docker公司提供的一个注册服务器(Register)来保存多个仓库,每个仓库又可以包含多个具备不同tag的镜像
二、Docker安装
我是虚拟机装的Centos7.8,linux 3.10 内核,docker官方说至少3.8以上,建议3.10以上(ubuntu下要linux内核3.8以上, RHEL/Centos 的内核修补过, centos6.5的版本就可以——这个可以试试)
一、Centos版本为7.8
二、内核版本为3.10
1,root账户登录,查看内核版本如下
输入uname -r
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]# uname -r
3.10.0-1127.13.1.el7.x86_64
或者uname -a
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]# uname -a
Linux iZ2vc2em3ma84cj1zfcwqfZ 3.10.0-1127.13.1.el7.x86_64 #1 SMP Tue Jun 23 15:46:38 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
2.把yum包更新到最新
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]# yum update
3.安装需要的软件包, yum-util
提供yum-config-manager功能,另外两个是devicemapper驱动依赖的(或者执行这个命令)
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
4.设置yum源
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]#
5.可以查看所有仓库中所有docker版本,并选择特定版本安装
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]# yum list docker-ce --showduplicates | sort -r
6.安装Docker,命令:yum install docker-ce-版本号,我选的是17.12.1.ce,如下
# yum install docker-ce-17.12.1.ce
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: mirrors.aliyun.com
* updates: centos.ustc.edu.cn
base | 3.6 kB 00:00
docker-ce-stable | 2.9 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
正在解决依赖关系
--> 正在检查事务
---> 软件包 docker-ce.x86_64.0.17.12.1.ce-1.el7.centos 将被 安装
--> 正在处理依赖关系 container-selinux >= 2.9,它被软件包 docker-ce-17.12.1.ce-1.el7.centos.x86_64 需要
7.启动Docker,命令:systemctl start docker,然后加入开机启动,如下
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]# systemctl start docker
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
8.验证安装是否成功(有client和service两部分表示docker安装启动都成功了)
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]# docker version
Client:
Version: 17.12.1-ce
API version: 1.35
Go version: go1.9.4
Git commit: 7390fc6
Built: Tue Feb 27 22:15:20 2018
OS/Arch: linux/amd64
Server:
Engine:
Version: 17.12.1-ce
API version: 1.35 (minimum version 1.12)
Go version: go1.9.4
Git commit: 7390fc6
Built: Tue Feb 27 22:17:54 2018
OS/Arch: linux/amd64
Experimental: false
9.http://blog.sina.com.cn/s/blog_1645e034e0102yflu.html
三、另一种方法
以下使用的阿里云公共镜像系统为centos7.8,64位,镜像为centos_7_8_x64_20G_alibase_20200717.vhd,所有操作以root
用户操作
2. 安装Docker官方源
2.1 安装yum工具集
yum install -y yum-utils
2.2 安装Docker源
yum-config-manager --add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
2.3 更新yum缓存
yum makecache fast
2.4. 安装Docker
yum install -y docker-ce
2.5. 启动Docker
systemctl start docker
2.6. 设置Docker开机自启
systemctl enable docker
2.7查看Docker版本
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]# docker version
2.8.链接地址 :https://www.cnblogs.com/anxminise/p/9690635.html
2.9.最终的代码是
Last login: Tue Sep 1 14:48:38 2020 from 110.185.39.96
Welcome to Alibaba Cloud Elastic Compute Service !
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]# ll
total 0
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]# yum install -y yum-utils
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package yum-utils-1.1.31-54.el7_8.noarch already installed and latest version
Nothing to do
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]# yum-config-manager --add-repo \
> https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]# yum makecache fast
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/2): docker-ce-stable/x86_64/primary_db | 45 kB 00:00:00
(2/2): docker-ce-stable/x86_64/updateinfo | 55 B 00:00:01
Metadata Cache Created
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]# yum install -y docker-ce
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:19.03.12-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: 3:docker-ce-19.03.12-3.el7.x86_64
--> Processing Dependency: containerd.io >= 1.2.2-3 for package: 3:docker-ce-19.03.12-3.el7.x86_64
--> Processing Dependency: docker-ce-cli for package: 3:docker-ce-19.03.12-3.el7.x86_64
--> Processing Dependency: libcgroup for package: 3:docker-ce-19.03.12-3.el7.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.119.2-1.911c772.el7_8 will be installed
--> Processing Dependency: policycoreutils-python for package: 2:container-selinux-2.119.2-1.911c772.el7_8.noarch
---> Package containerd.io.x86_64 0:1.2.13-3.2.el7 will be installed
---> Package docker-ce-cli.x86_64 1:19.03.12-3.el7 will be installed
---> Package libcgroup.x86_64 0:0.41-21.el7 will be installed
--> Running transaction check
---> Package policycoreutils-python.x86_64 0:2.5-34.el7 will be installed
--> Processing Dependency: setools-libs >= 3.3.8-4 for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libsemanage-python >= 2.5-14 for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Running transaction check
---> Package audit-libs-python.x86_64 0:2.8.5-4.el7 will be installed
---> Package checkpolicy.x86_64 0:2.5-8.el7 will be installed
---> Package libsemanage-python.x86_64 0:2.5-14.el7 will be installed
---> Package python-IPy.noarch 0:0.75-6.el7 will be installed
---> Package setools-libs.x86_64 0:3.3.8-4.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================================================================
Installing:
docker-ce x86_64 3:19.03.12-3.el7 docker-ce-stable 24 M
Installing for dependencies:
audit-libs-python x86_64 2.8.5-4.el7 base 76 k
checkpolicy x86_64 2.5-8.el7 base 295 k
container-selinux noarch 2:2.119.2-1.911c772.el7_8 extras 40 k
containerd.io x86_64 1.2.13-3.2.el7 docker-ce-stable 25 M
docker-ce-cli x86_64 1:19.03.12-3.el7 docker-ce-stable 38 M
libcgroup x86_64 0.41-21.el7 base 66 k
libsemanage-python x86_64 2.5-14.el7 base 113 k
policycoreutils-python x86_64 2.5-34.el7 base 457 k
python-IPy noarch 0.75-6.el7 base 32 k
setools-libs x86_64 3.3.8-4.el7 base 620 k
Transaction Summary
=============================================================================================================================================================================================
Install 1 Package (+10 Dependent packages)
Total download size: 89 M
Installed size: 365 M
Downloading packages:
(1/11): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm | 40 kB 00:00:00
(2/11): checkpolicy-2.5-8.el7.x86_64.rpm | 295 kB 00:00:00
(3/11): audit-libs-python-2.8.5-4.el7.x86_64.rpm | 76 kB 00:00:00
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-19.03.12-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY ] 3.8 MB/s | 22 MB 00:00:17 ETA
Public key for docker-ce-19.03.12-3.el7.x86_64.rpm is not installed
(4/11): docker-ce-19.03.12-3.el7.x86_64.rpm | 24 MB 00:00:03
(5/11): libcgroup-0.41-21.el7.x86_64.rpm | 66 kB 00:00:00
(6/11): policycoreutils-python-2.5-34.el7.x86_64.rpm | 457 kB 00:00:00
(7/11): python-IPy-0.75-6.el7.noarch.rpm | 32 kB 00:00:00
(8/11): setools-libs-3.3.8-4.el7.x86_64.rpm | 620 kB 00:00:00
(9/11): libsemanage-python-2.5-14.el7.x86_64.rpm | 113 kB 00:00:00
(10/11): docker-ce-cli-19.03.12-3.el7.x86_64.rpm | 38 MB 00:00:03
(11/11): containerd.io-1.2.13-3.2.el7.x86_64.rpm | 25 MB 00:11:41
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 131 kB/s | 89 MB 00:11:41
Retrieving key from https://download.docker.com/linux/centos/gpg
Importing GPG key 0x621E9F35:
Userid : "Docker Release (CE rpm) "
Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
From : https://download.docker.com/linux/centos/gpg
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libcgroup-0.41-21.el7.x86_64 1/11
Installing : audit-libs-python-2.8.5-4.el7.x86_64 2/11
Installing : setools-libs-3.3.8-4.el7.x86_64 3/11
Installing : 1:docker-ce-cli-19.03.12-3.el7.x86_64 4/11
Installing : python-IPy-0.75-6.el7.noarch 5/11
Installing : libsemanage-python-2.5-14.el7.x86_64 6/11
Installing : checkpolicy-2.5-8.el7.x86_64 7/11
Installing : policycoreutils-python-2.5-34.el7.x86_64 8/11
Installing : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 9/11
setsebool: SELinux is disabled.
Installing : containerd.io-1.2.13-3.2.el7.x86_64 10/11
Installing : 3:docker-ce-19.03.12-3.el7.x86_64 11/11
Verifying : checkpolicy-2.5-8.el7.x86_64 1/11
Verifying : libsemanage-python-2.5-14.el7.x86_64 2/11
Verifying : containerd.io-1.2.13-3.2.el7.x86_64 3/11
Verifying : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch 4/11
Verifying : python-IPy-0.75-6.el7.noarch 5/11
Verifying : policycoreutils-python-2.5-34.el7.x86_64 6/11
Verifying : 1:docker-ce-cli-19.03.12-3.el7.x86_64 7/11
Verifying : 3:docker-ce-19.03.12-3.el7.x86_64 8/11
Verifying : setools-libs-3.3.8-4.el7.x86_64 9/11
Verifying : audit-libs-python-2.8.5-4.el7.x86_64 10/11
Verifying : libcgroup-0.41-21.el7.x86_64 11/11
Installed:
docker-ce.x86_64 3:19.03.12-3.el7
Dependency Installed:
audit-libs-python.x86_64 0:2.8.5-4.el7 checkpolicy.x86_64 0:2.5-8.el7 container-selinux.noarch 2:2.119.2-1.911c772.el7_8 containerd.io.x86_64 0:1.2.13-3.2.el7
docker-ce-cli.x86_64 1:19.03.12-3.el7 libcgroup.x86_64 0:0.41-21.el7 libsemanage-python.x86_64 0:2.5-14.el7 policycoreutils-python.x86_64 0:2.5-34.el7
python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-4.el7
Complete!
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]#
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]# yum install -y docker-ce
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package 3:docker-ce-19.03.12-3.el7.x86_64 already installed and latest version
Nothing to do
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]# systemctl start docker
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]# docker version
Client: Docker Engine - Community
Version: 19.03.12
API version: 1.40
Go version: go1.13.10
Git commit: 48a66213fe
Built: Mon Jun 22 15:46:54 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.12
API version: 1.40 (minimum version 1.12)
Go version: go1.13.10
Git commit: 48a66213fe
Built: Mon Jun 22 15:45:28 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]#
[root@iZ2vc2em3ma84cj1zfcwqfZ ~]#
开启控制台
Centos8 开机后显示 Activate the web console with: systemctl enable --now cockpit.socke
systemctl start cockpit.socket # 运行Cockpit服务
systemctl enable –now cockpit.socket # 启动该服务,随系统启动一同启动
systemctl status cockpit.socket
centos重启后还是命令行界面:只是提示变了,类似下面的界面,提示:
Web console: https://localhost:9090/ or https://192.168.0.111:9090/
Last login: Wed Sep 2 14:51:54 2020 from 171.212.114.198
[root@VM-0-2-centos ~]#
怎么重回图形界面呢?
命令行下输入:systemctl get-default # 查看显示模式,结果是图形模式
运行下面两个命令后,再重启就ok了!重启系统进入图形化桌面
yum grouplist
yum groupinstall -y "Server with GUI"
https://www.cnblogs.com/ttrrpp/p/12109408.html
Activate the web console with: systemctl enable --now cockpit.socket
Last failed login: Wed Sep 2 13:59:16 CST 2020 from 45.148.10.28 on ssh:notty
There were 19 failed login attempts since the last successful login.
Last login: Wed Sep 2 11:43:12 2020 from 110.185.39.96
[root@VM-0-2-centos ~]#
[root@VM-0-2-centos ~]# systemctl start cockpit.socket
[root@VM-0-2-centos ~]# systemctl enable –now cockpit.socket
Invalid unit name "–now" was escaped as "\xe2\x80\x93now" (maybe you should use systemd-escape?)
Failed to enable unit: Unit file \xe2\x80\x93now.service does not exist.
[root@VM-0-2-centos ~]# systemctl status cockpit.socket
● cockpit.socket - Cockpit Web Service Socket
Loaded: loaded (/usr/lib/systemd/system/cockpit.socket; disabled; vendor preset: disabled)
Active: active (listening) since Wed 2020-09-02 14:54:11 CST; 52s ago
Docs: man:cockpit-ws(8)
Listen: [::]:9090 (Stream)
Process: 5027 ExecStartPost=/bin/ln -snf active.motd /run/cockpit/motd (code=exited, status=0/SUCCESS)
Process: 5020 ExecStartPost=/usr/share/cockpit/motd/update-motd localhost (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 11538)
Memory: 1.1M
CGroup: /system.slice/cockpit.socket
Sep 02 14:54:11 VM-0-2-centos systemd[1]: Starting Cockpit Web Service Socket.
Sep 02 14:54:11 VM-0-2-centos systemd[1]: Listening on Cockpit Web Service Socket.
[root@VM-0-2-centos ~]# systemctl enable –-now cockpit.socket
Invalid unit name "–-now" was escaped as "\xe2\x80\x93-now" (maybe you should use systemd-escape?)
Failed to enable unit: Unit file \xe2\x80\x93-now.service does not exist.
[root@VM-0-2-centos ~]# systemctl status cockpit.socket
● cockpit.socket - Cockpit Web Service Socket
Loaded: loaded (/usr/lib/systemd/system/cockpit.socket; disabled; vendor preset: disabled)
Active: active (listening) since Wed 2020-09-02 14:54:11 CST; 1min 21s ago
Docs: man:cockpit-ws(8)
Listen: [::]:9090 (Stream)
Process: 5027 ExecStartPost=/bin/ln -snf active.motd /run/cockpit/motd (code=exited, status=0/SUCCESS)
Process: 5020 ExecStartPost=/usr/share/cockpit/motd/update-motd localhost (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 11538)
Memory: 1.0M
CGroup: /system.slice/cockpit.socket
Sep 02 14:54:11 VM-0-2-centos systemd[1]: Starting Cockpit Web Service Socket.
Sep 02 14:54:11 VM-0-2-centos systemd[1]: Listening on Cockpit Web Service Socket.
[root@VM-0-2-centos ~]#
[root@VM-0-2-centos ~]#