龙空技术网

如何快速安装docker

IT小汤 165

前言:

今天咱们对“centos自启软件”可能比较关怀,看官们都需要剖析一些“centos自启软件”的相关知识。那么小编同时在网上收集了一些有关“centos自启软件””的相关内容,希望小伙伴们能喜欢,同学们一起来了解一下吧!

一、物理环境准备:

物理环境

说明:yum 安装是需要互联网的!!!这里我的系统是centos8, centos7也是同样的。

方式一:yum自动安装docker

1、添加docker yum源,这里采用是阿里源

 yum install -y yum-utils vim  // 安装基础工具 yum-config-manager --add-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-worldHello 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 bashShare images, automate workflows, and more with a free Docker ID:  more examples and ideas, visit: 

注意:直到出现“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 Packagesdocker-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-stabledocker-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 Packagesyum -y install docker-ce-[VERSION]  //安装指定的版本就可以了

4、配置docker镜像加速器

#因为docker默认是从国外服务器拉取镜像的,很慢的!!所以一定要配置镜像加速器!sudo mkdir -p /etc/dockersudo tee /etc/docker/daemon.json <<-'EOF'{  "registry-mirrors": [";]}EOFsudo systemctl daemon-reloadsudo systemctl restart docker

优点:安装简单,小白就可以操作。

缺点:需要连接互联网,报错比较多。

注意:这里是我的镜像加速地址,你也可以配置成你的地址,不会的私信我!!!

方式二 :二进制安装(推荐)

1、下载二进制安装包

你可以wget直接下载到服务器,也可以在自己电脑下载上传到服务器。(这里我直接wget)

#下载二进制安装包(因为我可以连接互联网,不能连接互联网的可以在自己电脑下载好在上传)[root@localhost ~]# wget 解压压缩包[root@localhost ~]# tar -zxvf docker-20.10.9.tgz[root@localhost ~]# lsanaconda-ks.cfg  docker  docker-20.10.9.tgz#将解压docker目录下的所有文件移动到/usr/bin下[root@localhost ~]# mv docker/* /usr/bin#以systemd的方式管理dockercat > /usr/lib/systemd/system/docker.service << EOF[Unit]Description=Docker Application Container EngineDocumentation= firewalld.serviceWants=network-online.target[Service]Type=notifyExecStart=/usr/bin/dockerdExecReload=/bin/kill -s HUP $MAINPIDLimitNOFILE=infinityLimitNPROC=infinityLimitCORE=infinityTimeoutStartSec=0Delegate=yesKillMode=processRestart=on-failureStartLimitBurst=3StartLimitInterval=60s[Install]WantedBy=multi-user.targetEOF#配置镜像加速器sudo mkdir -p /etc/dockersudo tee /etc/docker/daemon.json <<-'EOF'{  "registry-mirrors": [";]}EOF#启动docker并设置开机自启systemctl daemon-reloadsystemctl start dockersystemctl enable docker#检查docker是否安装成功[root@localhost ~]# docker run hello-worldHello 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 bashShare images, automate workflows, and more with a free Docker ID:  more examples and ideas, visit: 直到出现以上才证明安装成功!!

优点:二进制安装docker不会出现乱七八糟的报错,也可以不在联网的情况下安装!!!

缺点:稍微麻烦点。。

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

有问题私信我!!!

标签: #centos自启软件