centos 7.x 安装docker最新版

发布时间:2023年12月19日

1、查看centos版本

[root@localhost ~]# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
[root@localhost ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

2、更新最新系统

sudo yum update -y

[root@localhost ~]# sudo yum update -y
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
No packages marked for update
[root@localhost ~]# 

3、安装所需的软件包以允许yum使用HTTPS存储库

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

4、添加Docker的官方GPG密钥

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
或使用aliyun速度更快
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

5、安装Docker Engine-Community

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

6、启动Docker服务 查看状态 开机启动服务

#启动Docker服务
sudo systemctl start docker

#设置Docker服务开机自启动
sudo systemctl enable docker

# 查看docker服务状态
sudo systemctl status docker

7、查看docker 版本信息

[root@localhost ~]# docker -v
Docker version 24.0.7, build afdd53b
[root@localhost ~]# docker --version
Docker version 24.0.7, build afdd53b
[root@localhost ~]# docker version
Client: Docker Engine - Community
 Version:           24.0.7
 API version:       1.43
 Go version:        go1.20.10
 Git commit:        afdd53b
 Built:             Thu Oct 26 09:11:35 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.7
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.10
  Git commit:       311b9ff
  Built:            Thu Oct 26 09:10:36 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.26
  GitCommit:        3dd1e886e55dd695541fdcd67420c2888645a495
 runc:
  Version:          1.1.10
  GitCommit:        v1.1.10-0-g18a0cb0
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[root@localhost ~]# 

8、docker 官方案例 验证Docker是否成功安装

sudo docker run hello-world

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

9、设置国内镜像,加速镜像拉取速度

打开 Docker 配置文件 /etc/docker/daemon.json,如果该文件不存在,则可以创建该文件。
在该配置文件中添加以下内容:
{
"registry-mirrors": ["http://hub-mirror.c.163.com","https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn"]
}

作者:啊布多
链接:https://www.jianshu.com/p/fb74dd78e92a
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
如果要使用多个镜像源,可以在 "registry-mirrors" 数组中添加多个镜像源地址,以英文逗号分隔。
保存配置文件,并重启 Docker 服务,以使配置生效。可以使用以下命令重启 Docker 服务:
sudo systemctl restart docker
如果使用的是 Ubuntu 14.04 等旧版系统,可以使用以下命令重启 Docker 服务:
sudo service docker restart
配置完成后,可以使用 docker pull 命令测试是否成功使用了国内镜像源。例如,可以使用以下命令拉取官方的 Ubuntu 镜像:
docker pull ubuntu
如果使用了正确的国内镜像源地址,镜像的下载速度应该比官方源快很多。

[root@localhost ~]# vim /etc/docker/daemon.json
[root@localhost ~]# systemctl restart docker 
[root@localhost ~]# docker info
Client: Docker Engine - Community
 Version:    24.0.7
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.2
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.21.0
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 1
  Running: 0
  Paused: 0
  Stopped: 1
 Images: 1
 Server Version: 24.0.7
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 3dd1e886e55dd695541fdcd67420c2888645a495
 runc version: v1.1.10-0-g18a0cb0
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 3.10.0-1160.105.1.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 1
 Total Memory: 972.1MiB
 Name: localhost.localdomain
 ID: 3aef30e8-073c-47a1-8c41-10cf608838ec
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:
  http://hub-mirror.c.163.com/
  https://registry.docker-cn.com/
  https://docker.mirrors.ustc.edu.cn/
 Live Restore Enabled: false

[root@localhost ~]# 

查看docker info 可以查看到

注意,这些命令需要以root用户或具有sudo权限的用户身份运行。

文章来源:https://blog.csdn.net/webrx/article/details/135091731
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。