Docker 笔记(一)--安装

Docker 笔记(一)–安装

记录Docker 安装操作记录,便于查询。

参考

  1. 链接: Docker 入门到实战教程(二)安装Docker
  2. 链接: docker入门(利用docker部署web应用)
  3. 链接: 阿里云容器镜像服务/镜像加速器/操作文档
  4. 链接: 网易镜像中心
  5. 链接: 阿里云镜像站
  6. 链接: Warning: Stopping docker.service, but it can still be activated by: docker.socket解决方案

环境

Centos 7.9

安装

1.检查操作系统环境和版本

Docker 要求 CentOS 系统的内核版本高于 3.10,系统为64位

[root@centos7-18 ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)
Red Hat Enterprise Linux Server release 4.5 (Tikanga)
[root@centos7-18 ~]# 
[root@centos7-18 ~]# uname -r
3.10.0-1160.6.1.el7.x86_64
[root@centos7-18 ~]# 

2.如果安装过,需要先卸载

yum remove docker \
           docker-client \
           docker-client-latest \
           docker-common \
           docker-latest \
           docker-latest-logrotate \
           docker-logrotate \
           docker-engine

3.安装Docker

3.1 安装依赖

[root@centos7-18 ~]# yum install -y yum-utils  device-mapper-persistent-data  lvm2

3.2 添加Docker源
使用阿里云的Docker源

[root@centos7-18 yum.repos.d]#yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
 
 已加载插件:fastestmirror, langpacks
adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@centos7-18 yum.repos.d]#  ll  /etc/yum.repos.d/
总用量 60
-rw-r--r--. 1 root root 2523 616 2018 CentOS-Base.repo
-rw-r--r--. 1 root root 1664 1130 2016 CentOS-Base.repo.bak
-rw-r--r--. 1 root root 1309 1023 2020 CentOS-CR.repo
-rw-r--r--. 1 root root  649 1023 2020 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 1023 2020 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 1023 2020 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 1023 2020 CentOS-Sources.repo
-rw-r--r--. 1 root root 8515 1023 2020 CentOS-Vault.repo
-rw-r--r--. 1 root root  616 1023 2020 CentOS-x86_64-kernel.repo
// Docker源
-rw-r--r--  1 root root 2081 1115 2023 docker-ce.repo
-rw-r--r--. 1 root root 1050 111 2020 epel.repo
-rw-r--r--. 1 root root 1149 111 2020 epel-testing.repo

3.3 安装最新版

[root@centos7-18 yum.repos.d]# sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

安装说明: 摘自《功能解释:containerd.io、docker-ce、docker-ce-cli、docker-buildx-plugin、docker-compose-plugin、docker.io》

  • docker containerd.io
    是Docker容器运行时的核心组件之一,它负责管理和运行容器。它提供了容器的生命周期管理、镜像管理、网络管理等功能。

  • docker-ce
    是Docker Community Edition的缩写,是Docker的社区版本。它是一个开源的容器化平台,提供了构建、发布和运行容器的工具和服务。广义来说,docker-ce包含了dockerd(Docker守护进程)、docker命令行工具、docker-compose等组件;狭义上来讲,docker-ce 是与 docker containerd.io、docker-ce-cli 并列的服务组件。

  • docker-ce-cli
    是Docker Community Edition的命令行工具(command line)。它提供了与Docker守护进程进行交互的命令行接口,可以用于管理和操作Docker容器、镜像、网络等。

  • docker-buildx-plugin
    是Docker的一个插件,用于构建多平台的容器镜像。它可以在一个构建过程中同时构建多个不同平台的镜像,例如x86、ARM等。这样可以方便地为不同平台的设备提供适配的容器镜像。

  • docker-compose-plugin
    是Docker的一个插件,用于管理和编排多个容器的运行。它可以通过一个单独的配置文件定义多个容器之间的关系和依赖,然后通过简单的命令就可以启动、停止、删除这些容器。

3.4 查看版本

[root@centos7-18 yum.repos.d]# 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
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

3.5 启动Docker

[root@centos7-18 yum.repos.d]# systemctl start docker
// 添加开机自启动
//[root@centos7-18 yum.repos.d]# systemctl enable docker
[root@centos7-18 yum.repos.d]# ps -ef | grep docker
root     12338     1  0 13:43 ?        00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root     12792  9696  0 13:49 pts/0    00:00:00 grep --color=auto docker
[root@centos7-18 yum.repos.d]# 

3.6 配置国内镜像源

// 如果没有,就创建daemon.json 
[root@centos7-18 docker]# vim /etc/docker/daemon.json 
// 输入镜像源
{
    
    
  "registry-mirrors": [
        // 阿里云的配置详见“容器镜像服务”-“镜像加速器”-“对应的操作系统”
        "https://xxxxxxx.mirror.aliyuncs.com",
        "http://hub-mirror.c.163.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://registry.docker-cn.com"
  ]
}
[root@centos7-18 docker]# systemctl daemon-reload
[root@centos7-18 docker]# systemctl restart docker
[root@centos7-18 docker]# 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: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 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: 61f9fd88f79f081d64d6fa3bb1a0dc71ec870523
 runc version: v1.1.9-0-gccaecfc
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 3.10.0-1160.6.1.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 1.791GiB
 Name: centos7-18.localdomain
 ID: ff9448d2-60cd-4dfb-8d41-26afa972b45b
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:
  https://xxxxxxxx.mirror.aliyuncs.com/
  http://hub-mirror.c.163.com/
  https://docker.mirrors.ustc.edu.cn/
  https://registry.docker-cn.com/
 Live Restore Enabled: false

3.7 停止Docker

[root@centos7-18 yum.repos.d]# systemctl stop docker

注意出现以下警告,此时无法停止服务,需要先停止 docker.socket

[root@centos7-18 ~]# systemctl -f stop docker
Warning: Stopping docker.service, but it can still be activated by:
  docker.socket
[root@centos7-18 ~]# systemctl stop docker.socket
[root@centos7-18 ~]# systemctl stop docker
[root@centos7-18 ~]# 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
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[root@centos7-18 ~]# 

镜像源

网易:http://hub-mirror.c.163.com
中科大镜像地址:http://mirrors.ustc.edu.cn/
中科大github地址:https://github.com/ustclug/mirrorrequest
Azure中国镜像地址:http://mirror.azure.cn/
Azure中国github地址:https://github.com/Azure/container-service-for-azure-china
DockerHub镜像仓库: https://hub.docker.com/ 
阿里云镜像仓库: https://cr.console.aliyun.com 
google镜像仓库: https://console.cloud.google.com/gcr/images/google-containers/GLOBAL (如果你本地可以翻墙的话是可以连上去的 )
coreos镜像仓库: https://quay.io/repository/ 
RedHat镜像仓库: https://access.redhat.com/containers

猜你喜欢

转载自blog.csdn.net/shijin741231/article/details/134416186