您当前所在位置:首页安装教程Docker实践之Linux安装Docker

Docker实践之Linux安装Docker

更新:2023-08-11 19:23:53编辑:tooool归类:安装教程人气:120

说到Docker,便要回溯到近几年,布季谢子公司的模版间接从k8s+kubesphere就干出来了,不过,用了那么十多年的k8s,却对Docker一无所知,这便想著,得抽空从最此基础已经开始课堂教学两遍。

Docker实践之Linux安装Docker

这四节就从Docker课堂教学之Linux加装Docker已经开始,我的Linux是版是CentOS 8.2,

1234
[root@VM-12-3-centos ~]cat/proc/versionLinuxversion4.18.0-305.3.1.el8.x86_64(mockbuild@kbuilder.bsys.centos.org) (gcc version8.4.120200928(Red Hat8.4.1-1) (GCC))1SMPTueJun116:14:33UTC2021[root@VM-12-3-centos ~]cat/etc/redhat-releaseCentOSLinuxrelease8.2.2004(Core)

配置yum源地址

为什么要配置yum源地址呢,因为yum源地址在国外,不利于我们访问,所以,我们需要找一个国内的代理镜像地址来加速我们访问,如:

  • (阿里巴巴)http://mirrors.aliyun.com/centos/
  • (网易)http://mirrors.163.com/
  • (清华大学)https://mirrors.tuna.tsinghua.edu.cn/在配置之前,我们先加装一个工具yum-utils,在Linux执行yum即可,yum install -y yum-utils[root@VM-12-3-centos ~] yum install -y yum-utilsLast metadata expiration check: 2:17:09 ago on Fri 17 Dec 2021 10:36:25 AM CST.Dependencies resolved.=================================================================================================================================================================================================================Package Architecture Version Repository Size=================================================================================================================================================================================================================Installing:yum-utils noarch 4.0.21-3.el8 BaseOS 73 kUpgrading:dnf-plugins-core noarch 4.0.21-3.el8 BaseOS 70 kpython3-dnf-plugins-core noarch 4.0.21-3.el8 BaseOS 234 kTransaction Summary=================================================================================================================================================================================================================Install 1 PackageUpgrade 2 PackagesTotal download size: 377 kDownloading Packages:(1/3): dnf-plugins-core-4.0.21-3.el8.noarch.rpm 523 kB/s | 70 kB 00:00(2/3): yum-utils-4.0.21-3.el8.noarch.rpm 319 kB/s | 73 kB 00:00(3/3): python3-dnf-plugins-core-4.0.21-3.el8.noarch.rpm 1.0 MB/s | 234 kB 00:00-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Total 1.6 MB/s | 377 kB 00:00Running transaction checkTransaction check succeeded.Running transaction testTransaction test succeeded.Running transactionPreparing : 1/1Upgrading : python3-dnf-plugins-core-4.0.21-3.el8.noarch 1/5Upgrading : dnf-plugins-core-4.0.21-3.el8.noarch 2/5Installing : yum-utils-4.0.21-3.el8.noarch 3/5Cleanup : dnf-plugins-core-4.0.18-4.el8.noarch 4/5Cleanup : python3-dnf-plugins-core-4.0.18-4.el8.noarch 5/5Running scriptlet: python3-dnf-plugins-core-4.0.18-4.el8.noarch 5/5Verifying : yum-utils-4.0.21-3.el8.noarch 1/5Verifying : dnf-plugins-core-4.0.21-3.el8.noarch 2/5Verifying : dnf-plugins-core-4.0.18-4.el8.noarch 3/5Verifying : python3-dnf-plugins-core-4.0.21-3.el8.noarch 4/5Verifying : python3-dnf-plugins-core-4.0.18-4.el8.noarch 5/5Upgraded:dnf-plugins-core-4.0.21-3.el8.noarch python3-dnf-plugins-core-4.0.21-3.el8.noarchInstalled:yum-utils-4.0.21-3.el8.noarchComplete!

这里我们配置阿里的yum源

123
[root@VM-12-3-centos ~]yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repoAdding repofrom: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

加装Docker

目前Docker分ce(社区版)和ee(企业版),这里当然是加装Docker-ce(社区版)了,执行加装命令yum install docker-ce docker-ce-cli containerd.io

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
[root@VM-12-3-centos~]yuminstall-yyum-utilsLast metadata expiration check:2:17:09agoonFri17Dec202110:36:25AMCST.Dependenciesresolved.=================================================================================================================================================================================================================PackageArchitectureVersionRepositorySize=================================================================================================================================================================================================================Installing:yum-utilsnoarch4.0.21-3.el8BaseOS73kUpgrading:dnf-plugins-corenoarch4.0.21-3.el8BaseOS70kpython3-dnf-plugins-corenoarch4.0.21-3.el8BaseOS234kTransactionSummary=================================================================================================================================================================================================================Install1PackageUpgrade2PackagesTotal download size:377kDownloading Packages:(1/3):dnf-plugins-core-4.0.21-3.el8.noarch.rpm523kB/s|70kB00:00(2/3):yum-utils-4.0.21-3.el8.noarch.rpm319kB/s|73kB00:00(3/3):python3-dnf-plugins-core-4.0.21-3.el8.noarch.rpm1.0MB/s|234kB00:00-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Total1.6MB/s|377kB00:00RunningtransactioncheckTransactionchecksucceeded.RunningtransactiontestTransactiontestsucceeded.RunningtransactionPreparing        :1/1Upgrading        :python3-dnf-plugins-core-4.0.21-3.el8.noarch1/5Upgrading        :dnf-plugins-core-4.0.21-3.el8.noarch2/5Installing       :yum-utils-4.0.21-3.el8.noarch3/5Cleanup          :dnf-plugins-core-4.0.18-4.el8.noarch4/5Cleanup          :python3-dnf-plugins-core-4.0.18-4.el8.noarch5/5Running scriptlet:python3-dnf-plugins-core-4.0.18-4.el8.noarch5/5Verifying        :yum-utils-4.0.21-3.el8.noarch1/5Verifying        :dnf-plugins-core-4.0.21-3.el8.noarch2/5Verifying        :dnf-plugins-core-4.0.18-4.el8.noarch3/5Verifying        :python3-dnf-plugins-core-4.0.21-3.el8.noarch4/5Verifying        :python3-dnf-plugins-core-4.0.18-4.el8.noarch5/5Upgraded:dnf-plugins-core-4.0.21-3.el8.noarchpython3-dnf-plugins-core-4.0.21-3.el8.noarchInstalled:yum-utils-4.0.21-3.el8.noarchComplete![root@VM-12-3-centos~]yum-config-manager--add-repohttps://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repoAdding repo from:https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo[root@VM-12-3-centos~]yuminstalldocker-cedocker-ce-clicontainerd.ioDockerCEStable-x86_64278kB/s|19kB00:00Last metadata expiration check:0:00:01agoonFri17Dec202101:32:08PMCST.Dependenciesresolved.=================================================================================================================================================================================================================PackageArchitectureVersionRepositorySize=================================================================================================================================================================================================================Installing:containerd.iox86_641.4.12-3.1.el8docker-ce-stable28Mdocker-cex86_643:20.10.12-3.el8docker-ce-stable22Mdocker-ce-clix86_641:20.10.12-3.el8docker-ce-stable30MInstalling dependencies:container-selinuxnoarch2:2.167.0-1.module_el8.5.0+911+f19012f9AppStream54kdocker-ce-rootless-extrasx86_6420.10.12-3.el8docker-ce-stable4.6Mdocker-scan-pluginx86_640.12.0-3.el8docker-ce-stable3.7Mfuse-commonx86_643.2.1-12.el8BaseOS21kfuse-overlayfsx86_641.7.1-1.module_el8.5.0+890+6b136101AppStream73kfuse3x86_643.2.1-12.el8BaseOS50kfuse3-libsx86_643.2.1-12.el8BaseOS94klibcgroupx86_640.41-19.el8BaseOS70klibslirpx86_644.4.0-1.module_el8.5.0+890+6b136101AppStream70kslirp4netnsx86_641.1.8-1.module_el8.5.0+890+6b136101AppStream51kEnabling module streams:container-toolsrhel8TransactionSummary=================================================================================================================================================================================================================Install13PackagesTotal download size:90MInstalled size:378MIsthisok[y/N]:yDownloading Packages:(1/13):libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64.rpm415kB/s|70kB00:00(2/13):container-selinux-2.167.0-1.module_el8.5.0+911+f19012f9.noarch.rpm235kB/s|54kB00:00(3/13):fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64.rpm303kB/s|73kB00:00(4/13):slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_64.rpm681kB/s|51kB00:00(5/13):fuse3-libs-3.2.1-12.el8.x86_64.rpm916kB/s|94kB00:00(6/13):fuse-common-3.2.1-12.el8.x86_64.rpm174kB/s|21kB00:00(7/13):fuse3-3.2.1-12.el8.x86_64.rpm275kB/s|50kB00:00(8/13):libcgroup-0.41-19.el8.x86_64.rpm916kB/s|70kB00:00(9/13):docker-ce-20.10.12-3.el8.x86_64.rpm8.0MB/s|22MB00:02(10/13):docker-ce-cli-20.10.12-3.el8.x86_64.rpm7.2MB/s|30MB00:04(11/13):docker-ce-rootless-extras-20.10.12-3.el8.x86_64.rpm3.1MB/s|4.6MB00:01(12/13):docker-scan-plugin-0.12.0-3.el8.x86_64.rpm10MB/s|3.7MB00:00(13/13):containerd.io-1.4.12-3.1.el8.x86_64.rpm5.1MB/s|28MB00:05-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Total15MB/s|90MB00:05warning: /var/cache/dnf/docker-ce-stable-ab4061364e2cf0db/packages/containerd.io-1.4.12-3.1.el8.x86_64.rpm:HeaderV4RSA/SHA512Signature,key ID 621e9f35:NOKEYDockerCEStable-x86_6459kB/s|1.6kB00:00Importing GPG key 0x621E9F35:Userid     :"Docker Release (CE rpm) "Fingerprint:060A61C51B558A7F742B77AAC52FEB6B621E9F35From       :https://mirrors.aliyun.com/docker-ce/linux/centos/gpgIsthisok[y/N]:yKeyimportedsuccessfullyRunningtransactioncheckTransactionchecksucceeded.RunningtransactiontestTransactiontestsucceeded.RunningtransactionPreparing        :1/1Installing       :docker-scan-plugin-0.12.0-3.el8.x86_641/13Running scriptlet:docker-scan-plugin-0.12.0-3.el8.x86_641/13Installing       :docker-ce-cli-1:20.10.12-3.el8.x86_642/13Running scriptlet:docker-ce-cli-1:20.10.12-3.el8.x86_642/13Running scriptlet:container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch3/13Installing       :container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch3/13Running scriptlet:container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch3/13Installing       :containerd.io-1.4.12-3.1.el8.x86_644/13Running scriptlet:containerd.io-1.4.12-3.1.el8.x86_644/13Running scriptlet:libcgroup-0.41-19.el8.x86_645/13Installing       :libcgroup-0.41-19.el8.x86_645/13Running scriptlet:libcgroup-0.41-19.el8.x86_645/13Installing       :fuse3-libs-3.2.1-12.el8.x86_646/13Running scriptlet:fuse3-libs-3.2.1-12.el8.x86_646/13Installing       :fuse-common-3.2.1-12.el8.x86_647/13Installing       :fuse3-3.2.1-12.el8.x86_648/13Installing       :fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_649/13Running scriptlet:fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_649/13Installing       :libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_6410/13Installing       :slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_6411/13Installing       :docker-ce-rootless-extras-20.10.12-3.el8.x86_6412/13Running scriptlet:docker-ce-rootless-extras-20.10.12-3.el8.x86_6412/13Installing       :docker-ce-3:20.10.12-3.el8.x86_6413/13Running scriptlet:docker-ce-3:20.10.12-3.el8.x86_6413/13Running scriptlet:container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch13/13Running scriptlet:docker-ce-3:20.10.12-3.el8.x86_6413/13Verifying        :container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch1/13Verifying        :fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_642/13Verifying        :libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_643/13Verifying        :slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_644/13Verifying        :fuse-common-3.2.1-12.el8.x86_645/13Verifying        :fuse3-3.2.1-12.el8.x86_646/13Verifying        :fuse3-libs-3.2.1-12.el8.x86_647/13Verifying        :libcgroup-0.41-19.el8.x86_648/13Verifying        :containerd.io-1.4.12-3.1.el8.x86_649/13Verifying        :docker-ce-3:20.10.12-3.el8.x86_6410/13Verifying        :docker-ce-cli-1:20.10.12-3.el8.x86_6411/13Verifying        :docker-ce-rootless-extras-20.10.12-3.el8.x86_6412/13Verifying        :docker-scan-plugin-0.12.0-3.el8.x86_6413/13Installed:container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarchcontainerd.io-1.4.12-3.1.el8.x86_64docker-ce-3:20.10.12-3.el8.x86_64docker-ce-cli-1:20.10.12-3.el8.x86_64docker-ce-rootless-extras-20.10.12-3.el8.x86_64docker-scan-plugin-0.12.0-3.el8.x86_64fuse-common-3.2.1-12.el8.x86_64fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64fuse3-3.2.1-12.el8.x86_64fuse3-libs-3.2.1-12.el8.x86_64libcgroup-0.41-19.el8.x86_64libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_64Complete!

至此,Docker便轻松加装完成,我们来看看docker的基本信息docker version

123456789101112
[root@VM-12-3-centos~]dockerversionClient:DockerEngine-CommunityVersion:20.10.12API version:1.41Go version:go1.16.12Git commit:e91ed57Built:MonDec1311:45:222021OS/Arch:linux/amd64Context:defaultExperimental:trueCannotconnecttotheDockerdaemonatunix:///var/run/docker.sock.Isthedockerdaemonrunning?

可以看到Cannot connect to the Docker daemon atunix:///var/run/docker.sock.这样的提示,这是因为刚才加装了,还未启动,这里执行命令启动出来systemctl start docker,此时再来看看Docker信息

123456789101112131415161718192021222324252627282930
[root@VM-12-3-centos~]dockerversionClient:DockerEngine-CommunityVersion:20.10.12API version:1.41Go version:go1.16.12Git commit:e91ed57Built:MonDec1311:45:222021OS/Arch:linux/amd64Context:defaultExperimental:trueServer:DockerEngine-CommunityEngine:Version:20.10.12API version:1.41(minimumversion1.12)Go version:go1.16.12Git commit:459d0dfBuilt:MonDec1311:43:442021OS/Arch:linux/amd64Experimental:falsecontainerd:Version:1.4.12GitCommit:7b11cfaabd73bb80907dd23182b9347b4245eb5drunc:Version:1.0.2GitCommit:v1.0.2-0-g52b36a2docker-init:Version:0.19.0GitCommit:de40ad0

这里我们还需要将Docker服务设置为开机启动,因为一旦重启系统,Docker服务就被停止了,执行systemctl enable docker设置开机自动启动

12
[root@VM-12-3-centos ~]systemctl enable dockerCreatedsymlink/etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.

卸载Docker

如果我们不想要Docker,想把它卸载掉,怎么搞呢?这也很方便,执行删除命令

1
yumremovedocker-ce docker-ce-cli containerd.io

然后再删除Docker的目录

12
rm -rf /var/lib/containerd
rm -rf /var/lib/docker

设置Docker镜像地址

和yun源一样,Docker镜像仓库在国外,这里我们需要配置为国内的代理镜像地址,这里例举几个:

  • https://hub-mirror.c.163.com/
  • https://reg-mirror.qiniu.com/其次还有阿里,只不过需要结合自己的ID,这里我就设置为七牛云的吧,先进入到/etc/docker目录,此时,该目录只有一个key.json这个文件,我们需要新建一个daemon.json文件,然后加入如下配置{"registry-mirrors": ["https://reg-mirror.qiniu.com"]},保存重启Docker即可12systemctl daemon-reloadsystemctl restart docker

我告诉你msdn版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

远程重装系统奔浪精减优化纯净极速版winxp—7—10—11+系统优化加速 WZor:下个Win10一周年更新预览版可能为14376