全网最新最全最详细 linux安装docker方式

一、物理环境准备:

 说明: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不会出现乱七八糟的报错,也可以不在联网的情况下安装!!!

缺点:稍微麻烦点。。

总结:两种方式都可以安装docker,各有优缺点,大家可以根据自己喜好和需求选择,本人更推荐二进制方式安装!!!

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

&小汤

大家共同学习

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值