目录
Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上。CentOS 7 的内核一般都是3.10的,而CentOS 6.X的内核一般都是2.6,在2.6的内核下,Docker运行会比较卡,所以一般会选择升级到3.10版本。
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
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce docker-ce-cli containerd.io
若执行报错,则配置yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
或一键安装Docker:
curl -fsSL get.docker.com -o get-docker.sh
sh get-docker.sh
systemctl start docker
systemctl status docker
docker version
docker info
[root@lhrdocker ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@lhrdocker ~]# docker ps
bash: docker: command not found...
[root@lhrdocker ~]# 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
Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
No Match for argument: docker
No Match for argument: docker-client
No Match for argument: docker-client-latest
No Match for argument: docker-common
No Match for argument: docker-latest
No Match for argument: docker-latest-logrotate
No Match for argument: docker-logrotate
No Match for argument: docker-selinux
No Match for argument: docker-engine-selinux
No Match for argument: docker-engine
No Packages marked for removal
[root@lhrdocker ~]# yum install -y yum-utils device-mapper-persistent-data lvvm2
Loaded plugins: fastestmirror, langpacks
base | 3.6 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/7): base/7/x86_64/group_gz | 153 kB 00:00:00
(2/7): epel/x86_64/group_gz | 95 kB 00:00:00
(3/7): epel/x86_64/updateinfo | 1.0 MB 00:00:00
(4/7): extras/7/x86_64/primary_db | 194 kB 00:00:01
(5/7): epel/x86_64/primary_db | 6.8 MB 00:00:01
(6/7): updates/7/x86_64/primary_db | 2.9 MB 00:00:02
base/7/x86_64/primary_db FAILED
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/f09552edffa70f49f553e411c2282fbccfffbeafa21e81e32622b103038b8bae-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
Trying other mirror.
base/7/x86_64/primary_db FAILED
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/f09552edffa70f49f553e411c2282fbccfffbeafa21e81e32622b103038b8bae-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
Trying other mirror.
(7/7): base/7/x86_64/primary_db | 6.1 MB 00:00:00
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
... ...
Transaction Summary
========================================================================================================================
Upgrade 3 Packages (+6 Dependent packages)
Total download size: 4.1 M
Downloading packages:
...
Dependency Updated:
device-mapper.x86_64 7:1.02.164-7.el7_8.2 device-mapper-event.x86_64 7:1.02.164-7.el7_8.2
device-mapper-event-libs.x86_64 7:1.02.164-7.el7_8.2 device-mapper-libs.x86_64 7:1.02.164-7.el7_8.2
lvm2-libs.x86_64 7:2.02.186-7.el7_8.2 lvm2-python-libs.x86_64 7:2.02.186-7.el7_8.2
Complete!
[root@lhrdocker yum.repos.d]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.reepo
Loaded plugins: fastestmirror, langpacks
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@lhrdocker yum.repos.d]# yum -y install docker-ce docker-ce-cli containerd.io
Loaded plugins: fastestmirror, langpacks
docker-ce-stable | 3.5 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:00
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
....
Dependencies Resolved
========================================================================================================================
Package Arch Version Repository Size
========================================================================================================================
Installing:
containerd.io x86_64 1.2.13-3.2.el7 docker-ce-stable 25 M
docker-ce x86_64 3:19.03.12-3.el7 docker-ce-stable 24 M
docker-ce-cli x86_64 1:19.03.12-3.el7 docker-ce-stable 38 M
Installing for dependencies:
container-selinux noarch 2:2.119.1-1.c57a6f9.el7 extras 40 k
... ...
Transaction Summary
========================================================================================================================
Install 3 Packages (+ 1 Dependent package)
Upgrade ( 11 Dependent packages)
Total download size: 98 M
Downloading packages:
....
Installed:
containerd.io.x86_64 0:1.2.13-3.2.el7 docker-ce.x86_64 3:19.03.12-3.el7 docker-ce-cli.x86_64 1:19.03.12-3.el7
Dependency Installed:
container-selinux.noarch 2:2.119.1-1.c57a6f9.el7
... ...
Complete!
[root@lhrdocker yum.repos.d]# docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[root@lhrdocker yum.repos.d]# systemctl start docker
systemctl status dockcker[root@lhrdocker yum.repos.d]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2020-06-24 12:47:51 CST; 2s ago
Docs: https://docs.docker.com
Main PID: 9438 (dockerd)
Memory: 38.3M
CGroup: /system.slice/docker.service
└─9438 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
... ...
[root@lhrdocker yum.repos.d]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@lhrdocker yum.repos.d]#
[root@lhrdocker yum.repos.d]# 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@lhrdocker yum.repos.d]# docker info
Client:
Debug Mode: false
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 19.03.12
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-514.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 3.695GiB
Name: lhrdocker
ID: YBFL:WNPR:Y2XV:RPJQ:JYGA:XOXN:YXJL:EO2J:UFFO:JVBW:AZHF:TYME
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
[root@lhrdocker ~]# docker ps
bash: docker: command not found...
[root@lhrdocker ~]# curl -fsSL get.docker.com -o get-docker.sh
[root@lhrdocker ~]# ll
total 56
-rw-------. 1 root root 2152 Sep 13 2018 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 Sep 12 2018 Desktop
drwxr-xr-x. 2 root root 4096 Sep 12 2018 Documents
drwxr-xr-x. 2 root root 4096 Sep 12 2018 Downloads
-rw-r--r-- 1 root root 13857 Jun 24 12:57 get-docker.sh
-rw-r--r--. 1 root root 2256 Sep 13 2018 initial-setup-ks.cfg
drwxr-xr-x. 2 root root 4096 Sep 12 2018 Music
drwxr-xr-x. 2 root root 4096 Sep 12 2018 Pictures
drwxr-xr-x. 2 root root 4096 Sep 12 2018 Public
drwxr-xr-x. 2 root root 4096 Sep 12 2018 Templates
drwxr-xr-x. 2 root root 4096 Sep 12 2018 Videos
[root@lhrdocker ~]# sh get-docker.sh
# Executing docker install script, commit: 26ff363bcf3b3f5a00498ac43694bf1c7d9ce16c
+ sh -c 'yum install -y -q yum-utils'
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/f09552edffa70f49f553e411c2282fbccfffbeafa21e81e32622b103038b8bae-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
Trying other mirror.
No Presto metadata available for updates
Warning: RPMDB altered outside of yum.
** Found 3 pre-existing rpmdb problem(s), 'yum check' output follows:
ipa-client-4.4.0-12.el7.centos.x86_64 has installed conflicts freeipa-client: ipa-client-4.4.0-12.el7.centos.x86_64
ipa-client-common-4.4.0-12.el7.centos.noarch has installed conflicts freeipa-client-common: ipa-client-common-4.4.0-12.el7.centos.noarch
ipa-common-4.4.0-12.el7.centos.noarch has installed conflicts freeipa-common: ipa-common-4.4.0-12.el7.centos.noarch
+ sh -c 'yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo'
Loaded plugins: fastestmirror, langpacks
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
+ '[' stable '!=' stable ']'
+ sh -c 'yum makecache'
Loaded plugins: fastestmirror, langpacks
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/9): epel/x86_64/prestodelta | 2.0 kB 00:00:00
(2/9): base/7/x86_64/other_db | 2.6 MB 00:00:00
(3/9): extras/7/x86_64/filelists_db | 205 kB 00:00:00
(4/9): extras/7/x86_64/other_db | 122 kB 00:00:00
(5/9): updates/7/x86_64/other_db | 238 kB 00:00:00
(6/9): updates/7/x86_64/filelists_db | 1.6 MB 00:00:02
(7/9): epel/x86_64/other_db | 3.3 MB 00:00:05
(8/9): base/7/x86_64/filelists_db | 7.1 MB 00:00:06
(9/9): epel/x86_64/filelists_db | 12 MB 00:00:07
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Metadata Cache Created
+ '[' -n '' ']'
+ sh -c 'yum install -y -q docker-ce'
No Presto metadata available for base
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
Public key for docker-ce-19.03.12-3.el7.x86_64.rpm is not installed
Importing GPG key 0x621E9F35:
Userid : "Docker Release (CE rpm) <docker@docker.com>"
Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
From : https://download.docker.com/linux/centos/gpg
setsebool: SELinux is disabled.
If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:
sudo usermod -aG docker your-user
Remember that you will have to log out and back in for this to take effect!
WARNING: Adding a user to the "docker" group will grant the ability to run
containers which can be used to obtain root privileges on the
docker host.
Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
for more information.
[root@lhrdocker ~]# If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:
sudo usermod -aG docker your-user
Remember that you will have to log out and back in for this to take effect!
WARNING: Adding a user to the "docker" group will grant the ability to run
containers which can be used to obtain root privileges on the
docker host.
Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
for more information.
[root@lhrdocker ~]# d
[root@lhrdocker ~]# docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[root@lhrdocker ~]# systemctl start docker
systemctl status docker[root@lhrdocker ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2020-06-24 13:12:56 CST; 1s ago
Docs: https://docs.docker.com
Main PID: 9348 (dockerd)
Memory: 38.4M
CGroup: /system.slice/docker.service
└─9348 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
... ...
[root@lhrdocker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@lhrdocker ~]#
到此为止,Docker软件安装完成。
欢迎关注我的博客《Jackin's Blog - 知识改变命运》学习分享更多知识