1.安装Docker
1.1在linux系统中下载前置环境
1.安装wget命令(wget命令是Linux系统用于从Web下载文件的命令行工具)
2.安装依赖环境
3.设置Docker镜像源,因为默认的服务器很慢所以我选择国内镜像源,这里我使用阿里镜像源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
1.2开始安装docker
安装docker社区版(docker-ce)
yum install docker-ce docker-ce-cli containerd.io
这个地方输入y然后回车,它会继续下载安装
下载完成后又会遇到Is this ok [y/d/N],这里继续输入y回车,然后它会自动执行安装
注意:这里它会检测你的安全状态,所以会停顿一下耐心等待
2.启动Docker
2.1启动docker服务
systemctl start docker
2.2设置开机自启动
systemctl enable docker
2.3查看版本,验证是否安装成功
docker -v
验证结果
docker run hello-world
出现以下代码成功!
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:ffb13da98453e0f04d33a6eee5bb8e46ee50d08ebe17735fc0779d0349e889e9
Status: Downloaded newer image for hello-world:latest
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/
3.额外的镜像加速
配置镜像加速在下载镜像的时候提高效率
3.1修改文件添加镜像加速
找到etc/docker/daemon.json文件
如果发现没有这个文件,可以自己在etc/docker下创建daemon.json文件并加入镜像加速地址保存
注意看!这个地址要在阿里云登陆后搜索容器镜像服务,找到镜像加速服务开通后会给你一个地址
{
"registry-mirrors": ["https://自己在阿里云上获取的地址名.mirror.aliyuncs.com"]
}
这里通过学习后,了解到docker在中国的镜像加速地址,将任意一个加入即可
例:
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}
{
"registry-mirrors": [
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com",
"https://registry.docker-cn.com",
"https://reg-mirror.qiniu.com",
"https://dockerhub.azk8s.cn",
"https://docker.mirrors.ustc.edu.cn"
]
}
完成后重启镜像,重启docker
systemctl daemon-reload
systemctl restart docker