目录
1.内核版本要求高于 3.10
uname -r
[root@localhost vagrant]# uname -r
3.10.0-957.27.2.el7.x86_64
2. yum包更新
yum -y update
使用root权限登录Centos,更新yum包更新到最新。
root@localhost vagrant]# yum -y update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.cn99.com
No packages marked for update
3.卸载旧版本docker
yum remove docker docker-common docker-selinux docker-engine
[root@localhost vagrant]# yum remove docker docker-common docker-selinux docker-engine
Loaded plugins: fastestmirror
No Match for argument: docker
No Match for argument: docker-common
No Match for argument: docker-selinux
No Match for argument: docker-engine
No Packages marked for removal
4.安装需要依赖的软件包
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-util提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
[root@localhost /]# yum install -y yum-utils device-mapper-persistent-data lvm2
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Package yum-utils-1.1.31-50.el7.noarch already installed and latest version
Package device-mapper-persistent-data-0.7.3-3.el7.x86_64 already installed and latest version
Package 7:lvm2-2.02.180-10.el7_6.8.x86_64 already installed and latest version
Nothing to do
5.设置yum源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@localhost /]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
发现报错
failure: repodata/repomd.xml from mirrors.aliyun.com_docker-: [Errno 256] No more mirrors to try. http://mirrors.aliyun.com/docker-/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
解决
6.更新yum包索引
yum makecache fast
[root@localhost vagrant]# yum makecache fast
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.cn99.com
base | 3.6 kB 00:00:00
docker-ce-stable
...
(2/2): docker-ce-stable/x86_64/primary_db | 32 kB 00:00:00
Metadata Cache Created
7.查看yum源
yum repolist enabled
[root@localhost vagrant]# yum repolist enabled
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.cn99.com
repo id repo name status
base/7/x86_64 CentOS-7 - Base
... 2,500
repolist: 13,006
8.查看仓库docker版本
[root@localhost vagrant]# yum list docker-ce --showduplicates | sort -r
* updates: mirrors.cn99.com
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
* extras: mirrors.aliyun.com
docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-stable
...
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
* base: mirrors.aliyun.com
Available Packages
9.安装docker ce
一路默认y
[root@localhost vagrant]# yum install docker-ce
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
...
Installed:
docker-ce.x86_64 3:19.03.1-3.el7
Dependency Installed:
audit-libs-python.x86_64 0:2.8.4-4.el7 checkpolicy.x86_64 0:2.5-8.el7 container-selinux.noarch 2:2.107-1.el7_6 containerd.io.x86_64 0:1.2.6-3.3.el7
docker-ce-cli.x86_64 1:19.03.1-3.el7 libcgroup.x86_64 0:0.41-20.el7 libsemanage-python.x86_64 0:2.5-14.el7 policycoreutils-python.x86_64 0:2.5-29.el7_6.1
python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-4.el7
Complete!
10.加入开机启动
[root@localhost vagrant]# systemctl start docker
[root@localhost vagrant]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
11.验证是否安装成功
主要查看Client和Server是否成功安装
[root@localhost vagrant]# docker version
Client: Docker Engine - Community
Version: 19.03.1
API version: 1.40
Go version: go1.12.5
Git commit: 74b1e89
Built: Thu Jul 25 21:21:07 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.1
API version: 1.40 (minimum version 1.12)
Go version: go1.12.5
Git commit: 74b1e89
Built: Thu Jul 25 21:19:36 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.6
GitCommit: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
runc:
Version: 1.0.0-rc8
GitCommit: 425e105d5a03fabd737a126ad93d62a9eeede87f
docker-init:
Version: 0.18.0
GitCommit: fec3683
12.卸载docker
[root@localhost vagrant]# yum -y remove docker-engine
13.修改docker为阿里镜像加速器
14.查看docker默认配置文件
在/etc/docker下查看有没有daemon.json,这是docker默认的配置文件
[root@localhost vagrant]# cd /etc/docker/
[root@localhost docker]# ls
key.json
15.创建配置文件
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://xxxxx.mirror.aliyuncs.com"]
}
EOF
16.重启docker服务
[root@localhost docker]# service docker restart
Redirecting to /bin/systemctl restart docker.service
17.搜索docker镜像
[root@localhost docker]# docker search java
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
node Node.js is a JavaScript-based platform for s… 7791 [OK]
tomcat Apache Tomcat is an open source implementati… 2504 [OK]
java Java is a concurrent, class-based, and objec… 1976 [OK]
openjdk OpenJDK is an open-source implementation of … 1858 [OK]
ghost Ghost is a free and open source blogging pla… 1019 [OK]
18.安装nginx
搜索仓库
docker search nginx
[root@node-192 vagrant]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 11880 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1646 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 739 [OK]
linuxserver/nginx An Nginx container, brought to you by LinuxS… 74
安装
docker pull nginx
[root@node-192 vagrant]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
Digest: sha256:53ddb41e46de3d63376579acf46f9a41a8d7de33645db47a486de9769201fec9
Status: Image is up to date for nginx:latest
docker.io/library/nginx:latest
19.启动nginx
[root@node-192 vagrant]# docker run -d -p 91:80 nginx
44ba94d2d7e130c1166f1c24703f4f8896f3ffc86960abccf8ee83d888710cc8