CentOS 7.9 安装 Docker

CentOS 7.9 安装 Docker

一、相关博客

【Docker】002-Docker安装

https://blog.csdn.net/qq_29689343/article/details/115261766

这篇笔记不是 Markdown 写的,改起来不方便,重新开一片记录!

二、安装 Docker

1、安装 device-mapper-persistent-datalvm2 两个依赖

device-mapper-persistent-dataLinux 下的一个存储驱动, Linux 上的高级存储技术。 Lvm 的作用则是创建逻辑磁盘分区。

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

# 更新yum软件包索引
yum makecache fast

2、添加阿里云 Docker 镜像源

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

3、安装 Docker 社区版

yum install docker-ce -y

4、启动

systemctl start docker
systemctl enable docker

# 查看版本
docker -v
# Docker version 24.0.2, build cb74dfc

5、运行测试

先配置阿里云镜像加速器

docker run hello-world
 
# 显示“……Hello from Docker!……”代表运行成功!
[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
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/

三、配置阿里云镜像加速器

https://cr.console.aliyun.com/cn-hangzhou/instances

Docker 安装完毕后,之后我们去拉取 docker 镜像时,一般默认会去 docker 官方源拉取镜像。但是国内出海网速实在是太慢,所以选择我们更换为 阿里云镜像仓库 源进行镜像下载加速。

登录阿里云官网,打开 阿里云容器镜像服务。点击左侧菜单最下面的 镜像加速器 ,选择 CentOS (如下图)。按照官网的提示执行命令,即可更换 docker 镜像源地址。

image-20230622210412019

# CentOS
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://wgsbq2gq.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

猜你喜欢

转载自blog.csdn.net/qq_29689343/article/details/131344361