centos7安装docker(包含yum配置阿里云镜像源)

发布时间:2024年01月05日

yum配置阿里云镜像源

1.备份源repo文件

cd /etc/yum.repos.d
mkdir bak
mv *.repo bak/

2.获取阿里云镜像源文件

cd /etc/yum.repos.d
wget http://mirrors.aliyun.com/repo/Centos-7.repo
如果wget命令不存在,执行yum install wget,重新执行以上命令。
也可以使用浏览器访问http://mirrors.aliyun.com/repo/Centos-7.repo网址手动下载,然后上传至服务器的/etc/yum.repos.d目录下。

3.使用镜像文件

yum clean all
yum makecache

docker安装

1.卸载旧版本docker

sudo yum remove docker \
docker-common \
docker-selinux \
docker-engine

2.安装依赖包

sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2

3.鉴于国内网络问题,强烈建议使用国内源

sudo yum-config-manager \
--add-repo \
https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo

4.安装docker

sudo yum-config-manager --enable docker-ce-edge
yum makecache fast
sudo yum install docker-ce

5.配置国内镜像源

vi /etc/docker/daemon.json 

如果/etc/docker/daemon.json不存在,手动创建,将以下内容写入文件中。

{
"registry-mirrors": ["https://registry.docker-cn.com"]
}

6.启动docker

sudo systemctl enable docker
sudo systemctl start docker

7.检查是否安装成功

docker run hello-world

如果打印如下信息,便安装成功。

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c
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://cloud.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
文章来源:https://blog.csdn.net/pp1981002445/article/details/135409883
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。