Linux 下安装docker

Linux 下安装docker

本机是centos 7 非root 用户安装 如果是root用户安装则以下所有命令去掉 sudo

安装gcc
  1. 查看虚拟机是否安装
    1. 这是安装好了的
命令
gcc --version

[null@Docker module]$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright ? 2015 Free Software Foundation, Inc.
本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
包括没有适销性和某一专用目的下的适用性担保。
[null@Docker module]$
  1. 什么都没有显示的就输入以下命令
  sudo yum -y install gcc  
  sudo yum -y install gcc-c++
# 命令
sudo yum -y install gcc
# 命令
sudo yum -y install gcc-c++

[null@Docker module]$ sudo yum -y install gcc
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.nju.edu.cn
 * extras: mirrors.nju.edu.cn
 * updates: mirrors.nju.edu.cn
base                                                                                                    | 3.6 kB  00:00:00     
extras                                                                                                  | 2.9 kB  00:00:00     
updates                                                                                                 | 2.9 kB  00:00:00     
updates/7/x86_64/primary_db                                                                             |  27 MB  00:00:04     
软件包 gcc-4.8.5-44.el7.x86_64 已安装并且是最新版本
无须任何处理
[null@Docker module]$ sudo yum -y install gcc-c++
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.nju.edu.cn
 * extras: mirrors.nju.edu.cn
 * updates: mirrors.nju.edu.cn
软件包 gcc-c++-4.8.5-44.el7.x86_64 已安装并且是最新版本
无须任何处理
  1. 安装完成后再次输入查看版本是否和之前一样
# 命令
gcc --version

[null@Docker module]$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright ? 2015 Free Software Foundation, Inc.
本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
包括没有适销性和某一专用目的下的适用性担保。
[null@Docker module]$
安装utils
# 命令
sudo yum install -y yum-utils

[null@Docker module]$ sudo yum install -y yum-utils
[sudo] null 的密码:
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.nju.edu.cn
 * extras: mirrors.nju.edu.cn
 * updates: mirrors.nju.edu.cn
软件包 yum-utils-1.1.31-54.el7_8.noarch 已安装并且是最新版本
无须任何处理


设置stable镜像仓库
# 命令
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

[null@Docker module]$ sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加载插件:fastestmirror, langpacks
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://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
[null@Docker module]$ 


更新yum 软件索引
# 命令
sudo yum makecache fast

[null@Docker module]$ sudo yum makecache fast
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.nju.edu.cn
 * extras: mirrors.nju.edu.cn
 * updates: mirrors.nju.edu.cn
base                                                                                                    | 3.6 kB  00:00:00     
docker-ce-stable                                                                                        | 3.5 kB  00:00:00     
extras                                                                                                  | 2.9 kB  00:00:00     
updates                                                                                                 | 2.9 kB  00:00:00     
元数据缓存已建立
[null@Docker module]$ 

安装docker engin
# 命令
sudo yum -y install docker-ce docker-ce-cli containerd.io

[null@Docker module]$ sudo yum -y install docker-ce docker-ce-cli containerd.io
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.nju.edu.cn
 * extras: mirrors.nju.edu.cn
 * updates: mirrors.nju.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 containerd.io.x86_64.0.1.6.32-3.1.el7 将被 安装
--> 正在处理依赖关系 container-selinux >= 2:2.74,它被软件包 containerd.io-1.6.32-3.1.el7.x86_64 需要
---> 软件包 docker-ce.x86_64.3.26.1.3-1.el7 将被 安装
--> 正在处理依赖关系 docker-ce-rootless-extras,它被软件包 3:docker-ce-26.1.3-1.el7.x86_64 需要
---> 软件包 docker-ce-cli.x86_64.1.26.1.3-1.el7 将被 安装
--> 正在处理依赖关系 docker-buildx-plugin,它被软件包 1:docker-ce-cli-26.1.3-1.el7.x86_64 需要
--> 正在处理依赖关系 docker-compose-plugin,它被软件包 1:docker-ce-cli-26.1.3-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 container-selinux.noarch.2.2.119.2-1.911c772.el7_8 将被 安装
---> 软件包 docker-buildx-plugin.x86_64.0.0.14.0-1.el7 将被 安装
---> 软件包 docker-ce-rootless-extras.x86_64.0.26.1.3-1.el7 将被 安装
--> 正在处理依赖关系 fuse-overlayfs >= 0.7,它被软件包 docker-ce-rootless-extras-26.1.3-1.el7.x86_64 需要
--> 正在处理依赖关系 slirp4netns >= 0.4,它被软件包 docker-ce-rootless-extras-26.1.3-1.el7.x86_64 需要
---> 软件包 docker-compose-plugin.x86_64.0.2.27.0-1.el7 将被 安装
--> 正在检查事务
---> 软件包 fuse-overlayfs.x86_64.0.0.7.2-6.el7_8 将被 安装
--> 正在处理依赖关系 libfuse3.so.3(FUSE_3.2)(64bit),它被软件包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
--> 正在处理依赖关系 libfuse3.so.3(FUSE_3.0)(64bit),它被软件包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
--> 正在处理依赖关系 libfuse3.so.3()(64bit),它被软件包 fuse-overlayfs-0.7.2-6.el7_8.x86_64 需要
---> 软件包 slirp4netns.x86_64.0.0.4.3-4.el7_8 将被 安装
--> 正在检查事务
---> 软件包 fuse3-libs.x86_64.0.3.6.1-4.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

===============================================================================================================================
 Package                              架构              版本                                 源                           大小
===============================================================================================================================
正在安装:
 containerd.io                        x86_64            1.6.32-3.1.el7                       docker-ce-stable             35 M
 docker-ce                            x86_64            3:26.1.3-1.el7                       docker-ce-stable             27 M
 docker-ce-cli                        x86_64            1:26.1.3-1.el7                       docker-ce-stable             15 M
为依赖而安装:
 container-selinux                    noarch            2:2.119.2-1.911c772.el7_8            extras                       40 k
 docker-buildx-plugin                 x86_64            0.14.0-1.el7                         docker-ce-stable             14 M
 docker-ce-rootless-extras            x86_64            26.1.3-1.el7                         docker-ce-stable            9.4 M
 docker-compose-plugin                x86_64            2.27.0-1.el7                         docker-ce-stable             13 M
 fuse-overlayfs                       x86_64            0.7.2-6.el7_8                        extras                       54 k
 fuse3-libs                           x86_64            3.6.1-4.el7                          extras                       82 k
 slirp4netns                          x86_64            0.4.3-4.el7_8                        extras                       81 k

事务概要
===============================================================================================================================
安装  3 软件包 (+7 依赖软件包)

总下载量:114 M
安装大小:401 M
Downloading packages:
警告:/var/cache/yum/x86_64/7/extras/packages/container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm 的公钥尚未安装
(1/10): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm                                            |  40 kB  00:00:00     
警告:/var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-buildx-plugin-0.14.0-1.el7.x86_64.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID 621e9f35: NOKEY
docker-buildx-plugin-0.14.0-1.el7.x86_64.rpm 的公钥尚未安装
(2/10): docker-buildx-plugin-0.14.0-1.el7.x86_64.rpm                                                    |  14 MB  00:00:29     
(3/10): containerd.io-1.6.32-3.1.el7.x86_64.rpm                                                         |  35 MB  00:01:11     
(4/10): docker-ce-26.1.3-1.el7.x86_64.rpm                                                               |  27 MB  00:00:55     
(5/10): docker-ce-cli-26.1.3-1.el7.x86_64.rpm                                                           |  15 MB  00:00:30     
(6/10): slirp4netns-0.4.3-4.el7_8.x86_64.rpm                                                            |  81 kB  00:00:00     
(7/10): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm                                                         |  54 kB  00:00:00     
(8/10): fuse3-libs-3.6.1-4.el7.x86_64.rpm                                                               |  82 kB  00:00:00     
(9/10): docker-ce-rootless-extras-26.1.3-1.el7.x86_64.rpm                                               | 9.4 MB  00:00:20     
(10/10): docker-compose-plugin-2.27.0-1.el7.x86_64.rpm                                                  |  13 MB  00:00:28     
-------------------------------------------------------------------------------------------------------------------------------
总计                                                                                           898 kB/s | 114 MB  00:02:09     
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 检索密钥
导入 GPG key 0xF4A80EB5:
 用户ID     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 指纹       : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 软件包     : centos-release-7-9.2009.1.el7.centos.x86_64 (@anaconda)
 来自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
从 https://mirrors.aliyun.com/docker-ce/linux/centos/gpg 检索密钥
导入 GPG key 0x621E9F35:
 用户ID     : "Docker Release (CE rpm) <docker@docker.com>"
 指纹       : 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 来自       : https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch                                                        1/10 
  正在安装    : containerd.io-1.6.32-3.1.el7.x86_64                                                                       2/10 
  正在安装    : docker-compose-plugin-2.27.0-1.el7.x86_64                                                                 3/10 
  正在安装    : slirp4netns-0.4.3-4.el7_8.x86_64                                                                          4/10 
  正在安装    : docker-buildx-plugin-0.14.0-1.el7.x86_64                                                                  5/10 
  正在安装    : 1:docker-ce-cli-26.1.3-1.el7.x86_64                                                                       6/10 
  正在安装    : fuse3-libs-3.6.1-4.el7.x86_64                                                                             7/10 
  正在安装    : fuse-overlayfs-0.7.2-6.el7_8.x86_64                                                                       8/10 
  正在安装    : 3:docker-ce-26.1.3-1.el7.x86_64                                                                           9/10 
  正在安装    : docker-ce-rootless-extras-26.1.3-1.el7.x86_64                                                            10/10 
  验证中      : fuse3-libs-3.6.1-4.el7.x86_64                                                                             1/10 
  验证中      : fuse-overlayfs-0.7.2-6.el7_8.x86_64                                                                       2/10 
  验证中      : docker-buildx-plugin-0.14.0-1.el7.x86_64                                                                  3/10 
  验证中      : containerd.io-1.6.32-3.1.el7.x86_64                                                                       4/10 
  验证中      : slirp4netns-0.4.3-4.el7_8.x86_64                                                                          5/10 
  验证中      : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch                                                        6/10 
  验证中      : docker-ce-rootless-extras-26.1.3-1.el7.x86_64                                                             7/10 
  验证中      : docker-compose-plugin-2.27.0-1.el7.x86_64                                                                 8/10 
  验证中      : 3:docker-ce-26.1.3-1.el7.x86_64                                                                           9/10 
  验证中      : 1:docker-ce-cli-26.1.3-1.el7.x86_64                                                                      10/10 

已安装:
  containerd.io.x86_64 0:1.6.32-3.1.el7       docker-ce.x86_64 3:26.1.3-1.el7       docker-ce-cli.x86_64 1:26.1.3-1.el7      

作为依赖被安装:
  container-selinux.noarch 2:2.119.2-1.911c772.el7_8                docker-buildx-plugin.x86_64 0:0.14.0-1.el7                
  docker-ce-rootless-extras.x86_64 0:26.1.3-1.el7                   docker-compose-plugin.x86_64 0:2.27.0-1.el7               
  fuse-overlayfs.x86_64 0:0.7.2-6.el7_8                             fuse3-libs.x86_64 0:3.6.1-4.el7                           
  slirp4netns.x86_64 0:0.4.3-4.el7_8                               

完毕!
[null@Docker module]$ 
启动docker
# 启动的时候什么都不会显示
sudo systemctl start docker

[null@Docker module]$ sudo systemctl start docker
[sudo] null 的密码:
[null@Docker module]$ ps -ef|grep docker
root       3598      1  4 13:59 ?        00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
null       3793   2952  0 13:59 pts/0    00:00:00 grep --color=auto docker
[null@Docker module]$ 

docker version

sudo docker version

[null@Docker module]$ sudo docker version
Client: Docker Engine - Community
 Version:           26.1.3
 API version:       1.45
 Go version:        go1.21.10
 Git commit:        b72abbb
 Built:             Thu May 16 08:36:24 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          26.1.3
  API version:      1.45 (minimum version 1.24)
  Go version:       go1.21.10
  Git commit:       8e96db1
  Built:            Thu May 16 08:35:20 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.32
  GitCommit:        8b3b7ca2e5ce38e8f31a34f35b2b68ceb8470d89
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[null@Docker module]$ 


Hello World
  1. 正常情况
[null@Docker module]$ sudo docker run hello-world
[sudo] null 的密码:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete 
Digest: sha256:266b191e926f65542fa8daaec01a192c4d292bff79426f47300a046e1bc576fd
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/

[null@Docker module]$ 

  1. 如果出现了这个问题
[null@Docker module]$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": dial tcp: lookup registry-1.docker.io on 192.168.70.2:53: server misbehaving.
See 'docker run --help'.
[null@Docker module]$ 

  1. 解决方法
# 修改文件 resolv.conf
vim /etc/resolv.conf

#添加以下内容 
---------------------------
# Generated by NetworkManager
search localdomain
# nameserver 192.168.70.2
nameserver 114.114.114.114 
nameserver 8.8.8.8
------------------------------
  1. 修改后再次拉取就正常了
[null@Docker module]$ sudo docker run hello-world
[sudo] null 的密码:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete 
Digest: sha256:266b191e926f65542fa8daaec01a192c4d292bff79426f47300a046e1bc576fd
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/

[null@Docker module]$ 

添加阿里云镜像加速

执行以下命令

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://你d的阿里云.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
[null@Docker module]$ sudo mkdir -p /etc/docker
[null@Docker module]$ sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://你的阿里云.mirror.aliyuncs.com"]
}
EOF
# 重新加载
[null@Docker module]$ sudo systemctl daemon-reload
# 重启
[null@Docker module]$ sudo systemctl restart docker
  1. 再次运行
[null@Docker module]$ sudo docker run hello-world

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/

[null@Docker module]$ 

相关推荐

  1. Linux 安装docker

    2024-06-06 11:24:03       7 阅读
  2. LinuxDocker Compose安装指南

    2024-06-06 11:24:03       41 阅读
  3. LinuxDocker安装流程

    2024-06-06 11:24:03       35 阅读
  4. docker安装-在linux安装步骤

    2024-06-06 11:24:03       38 阅读
  5. LinuxDocker Engine安装后的一些配置步骤

    2024-06-06 11:24:03       45 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-06 11:24:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-06 11:24:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-06 11:24:03       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-06 11:24:03       20 阅读

热门阅读

  1. 力扣904.水果成篮

    2024-06-06 11:24:03       8 阅读
  2. NLP(21)--任务型对话机器人

    2024-06-06 11:24:03       6 阅读
  3. 讲解机器学习中的 K-均值聚类算法及其优缺点。

    2024-06-06 11:24:03       8 阅读
  4. Opencv cuda版本编译

    2024-06-06 11:24:03       7 阅读
  5. WHAT - 常见的前端工具库

    2024-06-06 11:24:03       7 阅读
  6. Frequently used Docker commands on Ubuntu

    2024-06-06 11:24:03       8 阅读
  7. LeetCode.55 跳跃游戏

    2024-06-06 11:24:03       8 阅读
  8. Liunx登录时相关bash配置文件(登录脚本)

    2024-06-06 11:24:03       8 阅读