一、物理环境准备:
说明:yum 安装是需要互联网的!!!这里我的系统是centos8, centos7也是同样的。
方式一:yum自动安装docker
1、添加docker yum源,这里采用是阿里源
yum install -y yum-utils vim // 安装基础工具
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo //添加软件源信息
yum -y install docker-ce --allowerasing //必须添加--allowerasing不然会报错,是因为centos8中的默认podman和docker冲突不能共存,要先卸载podman才能安装docker,centos7就不存在这个问题
systemctl enable docker --now //启动docker并设置为开机自启
[root@localhost ~]# docker --version //查看docker版本 yum默认安装是最新版本
Docker version 20.10.12, build e91ed57
2、docker 报错处理 “runc: symbol lookup error: runc: undefined symbol: seccomp_api_get
docker: Error response from daemon: cannot start a stopped process: unknown.”
centos8运行docker可能会出现以上报错,解决方法如下:
yum install libseccomp-devel //安装所需的库就可以了
#安装完所需库就可以正常运行!!
[root@localhost ~]# docker run hello-world
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/
注意:直到出现“Hello from Docker!” 才证明你的docker安装是成功的!!!
3、安装指定的docker版本:
[root@localhost ~]# yum list docker-ce.x86_64 --showduplicates | sort -r //查找所有版本
Last metadata expiration check: 0:17:55 ago on Wed 15 Dec 2021 07:17:39 PM CST.
Installed Packages
docker-ce.x86_64 3:20.10.9-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.8-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.7-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.6-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.5-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.4-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.3-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.2-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.1-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.12-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.12-3.el8 @docker-ce-stable
docker-ce.x86_64 3:20.10.11-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.10-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.0-3.el8 docker-ce-stable
docker-ce.x86_64 3:19.03.15-3.el8 docker-ce-stable
docker-ce.x86_64 3:19.03.14-3.el8 docker-ce-stable
docker-ce.x86_64 3:19.03.13-3.el8 docker-ce-stable
Available Packages
yum -y install docker-ce-[VERSION] //安装指定的版本就可以了
4、配置docker镜像加速器
#因为docker默认是从国外服务器拉取镜像的,很慢的!!所以一定要配置镜像加速器!
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://x31x8hjg.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
优点:安装简单,小白就可以操作。
缺点:需要连接互联网,报错比较多。
注意:这里是我的镜像加速地址,你也可以配置成你的地址,不会的私信我!!!
方式二 :二进制安装(推荐)
1、下载二进制安装包 https://download.docker.com/linux/static/stable/x86_64/docker-20.10.9.tgz
你可以wget直接下载到服务器,也可以在自己电脑下载上传到服务器。(这里我直接wget)
#下载二进制安装包(因为我可以连接互联网,不能连接互联网的可以在自己电脑下载好在上传)
[root@localhost ~]# wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.9.tgz
#解压压缩包
[root@localhost ~]# tar -zxvf docker-20.10.9.tgz
[root@localhost ~]# ls
anaconda-ks.cfg docker docker-20.10.9.tgz
#将解压docker目录下的所有文件移动到/usr/bin下
[root@localhost ~]# mv docker/* /usr/bin
#以systemd的方式管理docker
cat > /usr/lib/systemd/system/docker.service << EOF
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
EOF
#配置镜像加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://x31x8hjg.mirror.aliyuncs.com"]
}
EOF
#启动docker并设置开机自启
systemctl daemon-reload
systemctl start docker
systemctl enable docker
#检查docker是否安装成功
[root@localhost ~]# docker run hello-world
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/
#直到出现以上才证明安装成功!!
优点:二进制安装docker不会出现乱七八糟的报错,也可以不在联网的情况下安装!!!
缺点:稍微麻烦点。。