docker安装

docker 安装和镜像加速器配置

1、安装依赖

[root@192 ~]# yum -y install gcc gcc- c++

2、安装软件包

2.1 docker存储库安装
(1)设置存储库。
[root@192 ~]# yum install -y yum-utils 
[root@192 ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

也可以配置国内存储库(这里是阿里云库):

[root@192 ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
(2)若要安装最新版本,请运行:
[root@192 ~]# yum -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

如果系统提示您接受 GPG 密钥,请验证指纹是否匹配,如果匹配,请接受它。

060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35

此命令将安装 Docker,但不会启动 Docker。它还会创建一个 docker 组,但是,默认情况下它不会向该组添加任何用户。

(3)要安装特定版本,请首先列出 存储库:
[root@192 ~]# yum list docker-ce --showduplicates | sort -r
...
docker-ce.x86_64            18.06.0.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            18.03.0.ce-1.el7.centos             docker-ce-stable

返回的列表取决于启用了哪些软件库,并且特定于你的 CentOS 版本,按特定版本的完全限定包名称安装,该名称是包名称 (docker-ce)加上版本( 18.06.0.ce-3.el7 ),用连字符 (-) 分隔。如 docker-ce-cli-18.06.3.ce-3.el7

替换为所需的版本,然后运行以下命令 安装命令:

sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io docker-buildx-plugin docker-compose-plugin
2.2 从软件包安装

如果无法使用 Docker 的存储库安装 Docker Engine,可以 下载适用于您的版本的文件并手动安装。

1.转到https://download.docker.com/linux/centos/并选择你的 CentOS 版本。然后浏览并下载要安装的 Docker 版本的文件。x86_64/stable/Packages/.rpm

2.安装 Docker 引擎,将以下路径更改为 Docker 包下载路径。

[root@192 ~]# yum install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.09.0-3.el7.x86_64.rpm

3、启动 Docker

[root@192 ~]# systemctl start docker
[root@192 ~]# systemctl enable docker   

4、通过运行映像来验证 Docker 引擎安装是否成功。

[root@192 ~]# docker run hello-world

此命令下载测试映像并在容器中运行它。当 容器运行,它会打印一条确认消息并退出。

[root@192 ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete 
Digest: sha256:d000bc569937abbe195e20322a0bde6b2922d805332fd6d8a68b19f524b7d21d
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:

5、卸载 Docker 引擎

1.卸载 Docker 引擎、CLI、containerd 和 Docker Compose 软件包

sudo yum remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras

2.主机上的映像、容器、卷或自定义配置文件不会自动删除。要删除所有映像、容器和卷,请执行以下操作:

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

6、配置镜像加速器

执行如下命令,在Docker中配置阿里云镜像加速器。请将https://gwsabcw9.mirror.aliyuncs.com替换为您的加速器地址。

[root@192 ~]# mkdir -p /etc/docker                  #创建配置文件目录。
tee /etc/docker/daemon.json <<-'EOF'  #写入加速配置。
{
  "registry-mirrors": ["https://gwsabcw9.mirror.aliyuncs.com"]
}
EOF
[root@192 ~]# systemctl daemon-reload          #重新加载配置文件。
[root@192 ~]# systemctl restart docker          #重启Docker服务。
  • 这里的加速器地址 https://gwsabcw9.mirror.aliyuncs.com 需要从阿里云 >> 容器镜像服务里获取

在这里插入图片描述
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值