声明:本文乃“运维家”原创,转载请注明出处,更多内容请关注公众号“运维家”。
主旨
从今天开始,将持续半个月,主要更新docker相关内容,从入门到上手使用。后面还有什么想要看的都可以后台留言哦。快来关注我吧。
环境
linux服务器,需要关闭selinux和防火墙,以往文章有介绍具体方式能上外网
检查
[yunweijia@localhost ~]$ uname -r3.10.0-862.el7.x86_64[yunweijia@localhost ~]$
大于3.10的就可以安装docker。
移除旧版本
移除系统上的一些相关内容,不然安装起来容易遇到一些问题。
[yunweijia@localhost ~]$ sudo yum remove docker > docker-client > docker-client-latest > docker-common > docker-latest > docker-latest-logrotate > docker-logrotate > docker-selinux > docker-engine-selinux > docker-engine[sudo] yunweijia 的密码:已加载插件:fastestmirror, langpacks参数 docker 没有匹配参数 docker-client 没有匹配参数 docker-client-latest 没有匹配参数 docker-common 没有匹配参数 docker-latest 没有匹配参数 docker-latest-logrotate 没有匹配参数 docker-logrotate 没有匹配参数 docker-selinux 没有匹配参数 docker-engine-selinux 没有匹配参数 docker-engine 没有匹配不删除任何软件包[yunweijia@localhost ~]$
安装docker
安装必要的工具:
[yunweijia@localhost ~]$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
添加软件源信息:
[yunweijia@localhost ~]$ sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新软件源信息:
[yunweijia@localhost ~]$ yum clean all[yunweijia@localhost ~]$ yum makecache fast
安装docker-ce(docker-ce版本是社区版本,免费,docker-ee是企业版本,收费):
[yunweijia@localhost ~]$ sudo yum -y install docker-ce
解决报错:
如果报错如下信息:错误:软件包:containerd.io-1.4.12-3.1.el7.x86_64 (docker-ce-stable) 需要:container-selinux >= 2:2.74错误:软件包:docker-ce-rootless-extras-20.10.12-3.el7.x86_64 (docker-ce-stable) 需要:slirp4netns >= 0.4错误:软件包:docker-ce-rootless-extras-20.10.12-3.el7.x86_64 (docker-ce-stable) 需要:fuse-overlayfs >= 0.7错误:软件包:3:docker-ce-20.10.12-3.el7.x86_64 (docker-ce-stable) 需要:container-selinux >= 2:2.74解决:我们需要升级一下相关软件,下载container-selinux;[yunweijia@localhost ~]$ sudo wget -O /etc/yum.repos.d/CentOS-base.repo http://mirrors.aliyun.com/repo/Centos-7.repo[yunweijia@localhost ~]$ yum clean all[yunweijia@localhost ~]$ yum makecache fast[yunweijia@localhost ~]$ sudo yum install epel-release -y[yunweijia@localhost ~]$ sudo yum install container-selinux -
而后再次进行安装docker-ce:
[yunweijia@localhost ~]$ sudo yum -y install docker-ce
启动docker服务:
[yunweijia@localhost ~]$ sudo systemctl start docker[yunweijia@localhost ~]$ sudo systemctl status docker● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) Active: active (running) since 二 2022-02-08 15:37:14 CST; 7s ago Docs: https://docs.docker.com Main PID: 5688 (dockerd) Tasks: 7 Memory: 30.0M CGroup: /system.slice/docker.service └─5688 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock2月 08 15:37:14 localhost.localdomain dockerd[5688]: time="2022-02-08T15:37:14.371959365+08:00" level=info msg="scheme "unix" not registered, fallback to def...dule=grpc2月 08 15:37:14 localhost.localdomain dockerd[5688]: time="2022-02-08T15:37:14.371974573+08:00" level=info msg="ccResolverWrapper: sending update to cc: {[{uni...dule=grpc2月 08 15:37:14 localhost.localdomain dockerd[5688]: time="2022-02-08T15:37:14.371981256+08:00" level=info msg="ClientConn switching balancer to "pick_first"...dule=grpc2月 08 15:37:14 localhost.localdomain dockerd[5688]: time="2022-02-08T15:37:14.404169481+08:00" level=info msg="Loading containers: start."2月 08 15:37:14 localhost.localdomain dockerd[5688]: time="2022-02-08T15:37:14.496148517+08:00" level=info msg="Default bridge (docker0) is assigned with an IP..、address"2月 08 15:37:14 localhost.localdomain dockerd[5688]: time="2022-02-08T15:37:14.545353512+08:00" level=info msg="Loading containers: done."2月 08 15:37:14 localhost.localdomain dockerd[5688]: time="2022-02-08T15:37:14.559734496+08:00" level=info msg="Docker daemon" commit=459d0df graphdriver(s)=ov...=20.10.122月 08 15:37:14 localhost.localdomain dockerd[5688]: time="2022-02-08T15:37:14.560072640+08:00" level=info msg="Daemon has completed initialization"2月 08 15:37:14 localhost.localdomain systemd[1]: Started Docker Application Container Engine.2月 08 15:37:14 localhost.localdomain dockerd[5688]: time="2022-02-08T15:37:14.588758976+08:00" level=info msg="API listen on /var/run/docker.sock"Hint: Some lines were ellipsized, use -l to show in full.[yunweijia@localhost ~]$
测试运行hello-word:
[yunweijia@localhost ~]$ sudo docker run hello-worldUnable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-world2db29710123e: Pull complete Digest: sha256:507ecde44b8eb741278274653120c2bf793b174c06ff4eaa672b713b3263477bStatus: Downloaded newer image for hello-world:latestHello 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: https://hub.docker.com/For more examples and ideas, visit: https://docs.docker.com/get-started/[yunweijia@localhost ~]$
至此,linux中搭建docker完毕。
下一章:镜像分类以及操作(导入、导出、删除)