Docker我目前的理解就相当于现在Windows上使用的VMware,只不过还是有很大区别的,主要在于VMware包括硬件一起虚拟化了,Docker并没有,所以更精简灵活吧。但这个理解肯定是特别片面的,不管如何,Linux运维学习过程中Docker是不可缺少的一部分。
对比之前的zabbix安装,虽然安装步骤少了几步,但是入手起来要麻烦一下,主要是官网没有中文界面支持的原因吧,所以略显麻烦。但是不能怕麻烦,因为英语也是必过的一关吧。
Get Started
点击“View Linux Engine”会跳转到docker hub网站,类似于GitHub吧,或者理解为应用商店?AppStore?目前我是这样理解的。这个界面有不同Linux系统对应的docker版本,对应进去就可以了。
对于docker有一个简单的描述,然后进入文档说明安装。
我使用的环境是centos8,尝试使用dnf替换yum试一试(可以按照官网使用yum直接运行的),如果使用的是root用户不用sudo。注意$符号后面的才是命令,其它属于执行后出现的内容。
$ sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
添加仓库自:https://download.docker.com/linux/centos/docker-ce.repo
$ dnf info docker-ce
可安装的软件包
名称 : docker-ce
时期 : 3
版本 : 19.03.11
发布 : 3.el7
架构 : x86_64
大小 : 24 M
源 : docker-ce-19.03.11-3.el7.src.rpm
仓库 : docker-ce-stable
概况 : The open-source application container engine
URL : https://www.docker.com
协议 : ASL 2.0
描述 : Docker is a product for you to build, ship and run any
: application as a lightweight container.
:
: Docker containers are both hardware-agnostic and
: platform-agnostic. This means they can run anywhere, from your
: laptop to the largest cloud compute instance and everything in
: between - and they don't require you to use a particular
: language, framework or packaging system. That makes them great
: building blocks for deploying and scaling web apps, databases,
: and backend services without depending on a particular stack or
: provider.
$ sudo dnf install docker-ce docker-ce-cli containerd.io
错误:
问题: package docker-ce-3:19.03.11-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
- cannot install the best candidate for the job
- package containerd.io-1.2.10-3.2.el7.x86_64 is excluded
- package containerd.io-1.2.13-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.13-3.2.el7.x86_64 is excluded
- package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
- package containerd.io-1.2.2-3.el7.x86_64 is excluded
- package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.6-3.3.el7.x86_64 is excluded
(尝试添加 '--skip-broken' 来跳过无法安装的软件包 或 '--nobest' 来不只使用最佳选择的软件包)
这里出现一个错误,意思是containerd.io的版本太低了,我晕,这是官方提供的repo,为什么里面的containerd.io版本还是1.2.0呢?这里的解决办法大概就是另外单独安装containerd.io的高版本,或者指定docker版本来降低一下安装版本。
$ sudo dnf -y install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
依赖关系解决。
================================================================================
软件包 架构 版本 仓库 大小
================================================================================
安装:
containerd.io x86_64 1.2.6-3.3.el7 @commandline 26 M
升级:
audit x86_64 3.0-0.13.20190507gitf58ec40.el8 base 252 k
audit-libs x86_64 3.0-0.13.20190507gitf58ec40.el8 base 116 k
policycoreutils x86_64 2.9-3.el8_1.1 base 377 k
安装依赖关系:
container-selinux noarch 2:2.124.0-1.module_el8.1.0+298+41f9343a
AppStream 47 k
checkpolicy x86_64 2.9-1.el8 base 348 k
policycoreutils-python-utils
noarch 2.9-3.el8_1.1 base 250 k
python3-audit x86_64 3.0-0.13.20190507gitf58ec40.el8 base 85 k
python3-libsemanage x86_64 2.9-1.el8 base 127 k
python3-policycoreutils
noarch 2.9-3.el8_1.1 base 2.2 M
python3-setools x86_64 4.2.2-1.el8 base 600 k
启用模块流:
container-tools rhel8
事务概要
================================================================================
安装 8 软件包
升级 3 软件包
总计:30 M
总下载:4.4 M
下载软件包:
(1/10): policycoreutils-python-utils-2.9-3.el8_ 1.6 MB/s | 250 kB 00:00
(2/10): checkpolicy-2.9-1.el8.x86_64.rpm 1.8 MB/s | 348 kB 00:00
(3/10): container-selinux-2.124.0-1.module_el8. 242 kB/s | 47 kB 00:00
(4/10): python3-audit-3.0-0.13.20190507gitf58ec 1.2 MB/s | 85 kB 00:00
(5/10): python3-setools-4.2.2-1.el8.x86_64.rpm 8.3 MB/s | 600 kB 00:00
(6/10): python3-libsemanage-2.9-1.el8.x86_64.rp 832 kB/s | 127 kB 00:00
(7/10): python3-policycoreutils-2.9-3.el8_1.1.n 9.7 MB/s | 2.2 MB 00:00
(8/10): audit-3.0-0.13.20190507gitf58ec40.el8.x 1.4 MB/s | 252 kB 00:00
(9/10): audit-libs-3.0-0.13.20190507gitf58ec40. 843 kB/s | 116 kB 00:00
(10/10): policycoreutils-2.9-3.el8_1.1.x86_64.r 3.4 MB/s | 377 kB 00:00
--------------------------------------------------------------------------------
总计 3.4 MB/s | 4.4 MB 00:01
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
运行脚本: audit-libs-3.0-0.13.20190507gitf58ec40.el8.x86_64 1/1
升级 : audit-libs-3.0-0.13.20190507gitf58ec40.el8.x86_64 1/14
升级 : policycoreutils-2.9-3.el8_1.1.x86_64 2/14
运行脚本: policycoreutils-2.9-3.el8_1.1.x86_64 2/14
安装 : python3-audit-3.0-0.13.20190507gitf58ec40.el8.x86_64 3/14
安装 : python3-setools-4.2.2-1.el8.x86_64 4/14
安装 : python3-libsemanage-2.9-1.el8.x86_64 5/14
安装 : checkpolicy-2.9-1.el8.x86_64 6/14
安装 : python3-policycoreutils-2.9-3.el8_1.1.noarch 7/14
安装 : policycoreutils-python-utils-2.9-3.el8_1.1.noarch 8/14
运行脚本: container-selinux-2:2.124.0-1.module_el8.1.0+298+41f9343a.n 9/14
安装 : container-selinux-2:2.124.0-1.module_el8.1.0+298+41f9343a.n 9/14
运行脚本: container-selinux-2:2.124.0-1.module_el8.1.0+298+41f9343a.n 9/14
安装 : containerd.io-1.2.6-3.3.el7.x86_64 10/14
运行脚本: containerd.io-1.2.6-3.3.el7.x86_64 10/14
升级 : audit-3.0-0.13.20190507gitf58ec40.el8.x86_64 11/14
运行脚本: audit-3.0-0.13.20190507gitf58ec40.el8.x86_64 11/14
运行脚本: audit-3.0-0.10.20180831git0047a6c.el8.x86_64 12/14
清理 : audit-3.0-0.10.20180831git0047a6c.el8.x86_64 12/14
运行脚本: audit-3.0-0.10.20180831git0047a6c.el8.x86_64 12/14
运行脚本: policycoreutils-2.9-3.el8.x86_64 13/14
清理 : policycoreutils-2.9-3.el8.x86_64 13/14
清理 : audit-libs-3.0-0.10.20180831git0047a6c.el8.x86_64 14/14
运行脚本: container-selinux-2:2.124.0-1.module_el8.1.0+298+41f9343a.n 14/14
运行脚本: audit-libs-3.0-0.10.20180831git0047a6c.el8.x86_64 14/14
验证 : container-selinux-2:2.124.0-1.module_el8.1.0+298+41f9343a.n 1/14
验证 : checkpolicy-2.9-1.el8.x86_64 2/14
验证 : policycoreutils-python-utils-2.9-3.el8_1.1.noarch 3/14
验证 : python3-audit-3.0-0.13.20190507gitf58ec40.el8.x86_64 4/14
验证 : python3-libsemanage-2.9-1.el8.x86_64 5/14
验证 : python3-policycoreutils-2.9-3.el8_1.1.noarch 6/14
验证 : python3-setools-4.2.2-1.el8.x86_64 7/14
验证 : containerd.io-1.2.6-3.3.el7.x86_64 8/14
验证 : audit-3.0-0.13.20190507gitf58ec40.el8.x86_64 9/14
验证 : audit-3.0-0.10.20180831git0047a6c.el8.x86_64 10/14
验证 : audit-libs-3.0-0.13.20190507gitf58ec40.el8.x86_64 11/14
验证 : audit-libs-3.0-0.10.20180831git0047a6c.el8.x86_64 12/14
验证 : policycoreutils-2.9-3.el8_1.1.x86_64 13/14
验证 : policycoreutils-2.9-3.el8.x86_64 14/14
已升级:
audit-3.0-0.13.20190507gitf58ec40.el8.x86_64
audit-libs-3.0-0.13.20190507gitf58ec40.el8.x86_64
policycoreutils-2.9-3.el8_1.1.x86_64
已安装:
containerd.io-1.2.6-3.3.el7.x86_64
container-selinux-2:2.124.0-1.module_el8.1.0+298+41f9343a.noarch
checkpolicy-2.9-1.el8.x86_64
policycoreutils-python-utils-2.9-3.el8_1.1.noarch
python3-audit-3.0-0.13.20190507gitf58ec40.el8.x86_64
python3-libsemanage-2.9-1.el8.x86_64
python3-policycoreutils-2.9-3.el8_1.1.noarch
python3-setools-4.2.2-1.el8.x86_64
完毕!
$ containerd -v
containerd containerd.io 1.2.6 894b81a4b802e4eb2a91d1ce216b8817763c29fb
$ sudo dnf install -y docker-ce docker-ce-cli
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
上次元数据过期检查:0:03:36 前,执行于 2020年06月11日 星期四 00时42分55秒。
依赖关系解决。
================================================================================
软件包 架构 版本 仓库 大小
================================================================================
安装:
docker-ce x86_64 3:19.03.11-3.el7 docker-ce-stable 24 M
docker-ce-cli x86_64 1:19.03.11-3.el7 docker-ce-stable 38 M
安装依赖关系:
libcgroup x86_64 0.41-19.el8 base 70 k
事务概要
================================================================================
安装 3 软件包
总下载:62 M
安装大小:263 M
确定吗?[y/N]: y
下载软件包:
(1/3): libcgroup-0.41-19.el8.x86_64.rpm 408 kB/s | 70 kB 00:00
(2/3): docker-ce-19.03.11-3.el7.x86_64.rpm 1.6 MB/s | 24 MB 00:14
(3/3): docker-ce-cli-19.03.11-3.el7.x86_64.rpm 418 kB/s | 38 MB 01:33
--------------------------------------------------------------------------------
总计 682 kB/s | 62 MB 01:33
警告:/var/cache/dnf/docker-ce-stable-091d8a9c23201250/packages/docker-ce-19.03.11-3.el7.x86_64.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID 621e9f35: NOKEY
Docker CE Stable - x86_64 647 B/s | 1.6 kB 00:02
导入 GPG 公钥 0x621E9F35:
Userid: "Docker Release (CE rpm) <docker@docker.com>"
指纹: 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
来自: https://download.docker.com/linux/centos/gpg
确定吗?[y/N]: y
导入公钥成功
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
安装 : docker-ce-cli-1:19.03.11-3.el7.x86_64 1/3
运行脚本: docker-ce-cli-1:19.03.11-3.el7.x86_64 1/3
运行脚本: libcgroup-0.41-19.el8.x86_64 2/3
安装 : libcgroup-0.41-19.el8.x86_64 2/3
运行脚本: libcgroup-0.41-19.el8.x86_64 2/3
安装 : docker-ce-3:19.03.11-3.el7.x86_64 3/3
运行脚本: docker-ce-3:19.03.11-3.el7.x86_64 3/3
验证 : libcgroup-0.41-19.el8.x86_64 1/3
验证 : docker-ce-3:19.03.11-3.el7.x86_64 2/3
验证 : docker-ce-cli-1:19.03.11-3.el7.x86_64 3/3
已安装:
docker-ce-3:19.03.11-3.el7.x86_64 docker-ce-cli-1:19.03.11-3.el7.x86_64
libcgroup-0.41-19.el8.x86_64
完毕!
$ sudo systemctl start docker
$ systemctl status docker
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/library/hello-world/manifests/latest: Get https://auth.docker.io/token?scope=repository%3Alibrary%2Fhello-world%3Apull&service=registry.docker.io: net/http: request canceled (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.
安装完毕,拉取hello world镜像失败。注意看错误提示,这里应该是国外网络不稳定得原因吧,再试一次就可以了。
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:d58e752213a51785838f9eed2b7a498ffa1cb3aa7f946dda11af39286c3db9a9
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
或者改为使用阿里云镜像加速服务后再试,因篇幅过长单独写了一篇:centos8中docker使用阿里云镜像加速服务
另外阿里云还有repo仓库的镜像源可以设置。可以跳过。
$ cd /etc/yum.repos.d/
$ sudo mv docker-ce.repo docker-ce.repo.bak
$ sudo dnf config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
$ dnf clean all
$ dnf makecache
$ sudo systemctl restart docker
其它错误(如下)解析:这里因为是非root用户,所以必须加sudo,不然会出现如下错误。
$ docker images
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/images/json: dial unix /var/run/docker.sock: connect: permission denied
最后,据了解centos8开始默认用podman替代docker,大致了解了一下,目前可能docker还是主流吧。学会了docker,podman应该也差不多吧。
国外这些logo还是挺有意思的,挺形象的。podman的优势可能就是连docker中的鲸鱼船都省略了,直接是一只只的海豹在海里。那直接就把大海当容器咯。看起来是不是就更厉害。
$ dnf info podman
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
上次元数据过期检查:0:53:00 前,执行于 2020年06月11日 星期四 04时14分11秒。
可安装的软件包
名称 : podman
版本 : 1.6.4
发布 : 4.module_el8.1.0+298+41f9343a
架构 : x86_64
大小 : 12 M
源 : podman-1.6.4-4.module_el8.1.0+298+41f9343a.src.rpm
仓库 : AppStream
概况 : Manage Pods, Containers and Container Images
URL : https://podman.io/
协议 : ASL 2.0
描述 : podman (Pod Manager) is a fully featured container engine that is a simple
: daemonless tool. podman provides a Docker-CLI comparable command line that eases
: the transition from other container engines and allows the management of pods,
: containers and images. Simply put: alias docker=podman. Most podman commands
: can be run as a regular user, without requiring additional privileges.
:
: podman uses Buildah(1) internally to create container images. Both tools share
: image (not container) storage, hence each can use or manipulate images (but not
: containers) created by the other.
:
: Manage Pods, Containers and Container Images
: libpod Simple management tool for pods, containers and images
发表回复