centos7安装docker

在cenos7上安装docker和docker-compose

1. 安装docker

  1. 确认内核版本符合要求(docker官方说至少3.8以上,建议3.10以上)

    1
    2
    3
    [root@zmr-service ~]# uname -a
    Linux zmr-service 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
    [root@zmr-service ~]#
  2. 安装需要的软件包

    1
    2
    3
    [root@zmr-service ~]#  yum install -y yum-utils device-mapper-persistent-data lvm2

    yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
  3. 设置docker安装的yum源

    1
    2
    # 阿里仓库
    [root@zmr-service ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  4. 查看所有仓库中所有docker版本

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    [root@localhost ~]# yum list docker-ce --showduplicates | sort -r
    已加载插件:fastestmirror
    可安装的软件包
    * updates: mirrors.cn99.com
    Loading mirror speeds from cached hostfile
    * extras: mirrors.aliyun.com
    docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-stable
    docker-ce.x86_64 3:19.03.1-3.el7
    ... ...


  5. 安装Docker,

    1
    2
    3
    [root@localhost ~]# yum install docker-ce  -y

    表示直接安装最新的docker
  6. 验证安装是否成功

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    [root@zmr-service ~]# docker version
    Client: Docker Engine - Community
    Version: 23.0.3
    API version: 1.42
    Go version: go1.19.7
    Git commit: 3e7cbfd
    Built: Tue Apr 4 22:04:18 2023
    OS/Arch: linux/amd64
    Context: default

    Server: Docker Engine - Community
    Engine:
    Version: 23.0.3
    API version: 1.42 (minimum version 1.12)
    Go version: go1.19.7
    Git commit: 59118bf
    Built: Tue Apr 4 22:02:01 2023
    OS/Arch: linux/amd64
    Experimental: false
    containerd:
    Version: 1.6.20
    GitCommit: 2806fc1057397dbaeefbea0e4e17bddfbd388f38
    runc:
    Version: 1.1.5
    GitCommit: v1.1.5-0-gf19387a
    docker-init:
    Version: 0.19.0
    GitCommit: de40ad0


  7. 启动并加入开机启动

    1
    2
    [root@localhost ~]# systemctl start docker
    [root@localhost ~]# systemctl enable docker

2.安装docker-compose

  1. 下载最新版本的 docker-compose 到 /usr/bin 目录下

    1
    2
    3
    4
    curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/bin/docker-compose

    #
    chmod +x /usr/bin/docker-compose
  2. 给 docker-compose 授权

    1
    chmod +x /usr/local/bin/docker-compose
  3. 检查docker compose版本

    1
    2
    [root@zmr-service ~]# docker-compose -v
    docker-compose version 1.25.0, build 0a186604

3.配置及优化

docker配置及优化