Day 02 Docker安装(华为云)

Day 02 Docker安装

一、华为云的CentOS7中安装Docker

1.备份配置文件:

cp -a /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

2.安装华为镜像源

方案一

wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo # 获取华为源镜像

方案二

修改CentOS-Base.repo文件,取消baseurl开头的行的注释,并增加mirrorlist开头的行的注释。将文件中的http://mirror.centos.org替换成https://repo.huaweicloud.com,可以参考如下命令:

sed -i "s/#baseurl/baseurl/g" /etc/yum.repos.d/CentOS-Base.repo
sed -i "s/mirrorlist=http/#mirrorlist=http/g" /etc/yum.repos.d/CentOS-Base.repo
sed -i "s@http://mirror.centos.org@https://repo.huaweicloud.com@g" /etc/yum.repos.d/CentOS-Base.repo

3、执行yum clean all清除原有yum缓存。

4、执行yum makecache(刷新缓存)或者yum repolist all(查看所有配置可以使用的文件,会自动刷新缓存)

5、安装Docker

yum install docker -y

systemctl start docker #启动docker
systemctl enable docker #开机启动docker
systemctl status docker #查看docker状态

二、卸载重装

1.老版本的docker的命名为“docker”或 “docker-engine”,如果安装了这些版本,需要先卸载掉。

保存在“/var/lib/docker/”中的内容,包括图片、磁盘和网络配置等都会保留下来。

sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate

2.配置软件仓库。

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

yum-config-manager: command not found

这个是因为系统默认没有安装这个命令,这个命令在yum-utils 包里,可以通过命令yum -y install yum-utils 安装就可以了。

3. 安装docker-ce。

sudo yum install docker-ce docker-ce-cli containerd.io

这个命令总是会安装最新版本的docker-ce,如果需要安装指定版本的可以参考下面的操作:

sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

4下载软件包进行安装

1)通过https://download.docker.com/linux/centos/7/aarch64/stable/Packages/,下载指定版本的软件包。

C3V6NzUcJT8XbMs

2)执行命令安装软件包及依赖。

“package.rpm”为下载的软件包。

sudo yum install /path/to/package.rpm

3. 启动软件

1)启动Docker。

sudo systemctl start docker

2)使用一个hello-world镜像验证Docker是否正常。

sudo docker run hello-world

SFZsOqUWY8RL9P3

扫描二维码关注公众号,回复: 12218575 查看本文章

回显内容如下:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
3b4173355427: Pull complete 
Digest: sha256:41a65640635299bab090f783209c1e3a3f11934cf7756b09cb2f1e02147c6ed8
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.(arm64v8)
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/

三、华为云镜像加速

1.访问自己控制中心

jO8sJPR3ySwuE59

2.找到镜像加速地址

q4dcomYCaKD7Igv

3.配置文件

打开docker的daemon.json配置文件/etc/dobcker/daemon.json,添加相关镜像加速地址

输入以下命令

vim /etc/dobcker/daemon.json

{
    
    
"exec-opts":["native.cgroupdriver=systemd"],
"registry-mirrors":["https://08c97a9b4300263b0fc6c013d6e65880.mirror.swr.myhuaweicloud.com"]
}

4.重启docker

systemctl restart docker

IGeEUcgHqQzhjDo

猜你喜欢

转载自blog.csdn.net/A1L__/article/details/110388607