【Linux】Linux8安装docker图文详细步骤以及常用指令

Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的Linux或Windows操作系统的机器上,也可以实现虚拟化。

切换到源目录,备份原来的源

[root@localhost data]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# mv CentOS-Linux-* bak
[root@localhost yum.repos.d]# ls

 下载新的源文件,并用命令yum makecache建立新的元数据缓存

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
--2022-11-05 08:53:51--  https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 117.161.156.242, 117.161.156.239, 117.161.156.243, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|117.161.156.242|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2495 (2.4K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’

/etc/yum.repos.d/CentOS-Base.repo    100%[=====================================================================>]   2.44K  --.-KB/s    in 0.02s

2022-11-05 08:53:53 (133 KB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2495/2495]

[root@localhost yum.repos.d]# ls
bak  CentOS-Base.repo
[root@localhost yum.repos.d]# vim CentOS-Base.repo
[root@localhost yum.repos.d]# yum makecache
CentOS-8.5.2111 - Base - mirrors.aliyun.com                                                                        171 kB/s | 4.6 MB     00:27
CentOS-8.5.2111 - Extras - mirrors.aliyun.com                                                                       35 kB/s |  10 kB     00:00
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com                                                                   139 kB/s | 8.4 MB     01:02
Metadata cache created.

 测试源(用yum命令装个软件试试)

[root@localhost yum.repos.d]# yum install -y yum-utils
Last metadata expiration check: 0:08:11 ago on Sat 05 Nov 2022 08:55:50 AM CST.
Dependencies resolved.
===================================================================================================================================================
 Package                             Architecture                     Version                                 Repository                      Size
===================================================================================================================================================
Installing:
 yum-utils                           noarch                           4.0.21-3.el8                            base                            73 k

Transaction Summary
===================================================================================================================================================
Install  1 Package

Total download size: 73 k
Installed size: 22 k
Downloading Packages:
yum-utils-4.0.21-3.el8.noarch.rpm                                                                                   15 kB/s |  73 kB     00:04
---------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                               15 kB/s |  73 kB     00:04
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                           1/1
  Installing       : yum-utils-4.0.21-3.el8.noarch                                                                                             1/1
  Running scriptlet: yum-utils-4.0.21-3.el8.noarch                                                                                             1/1
  Verifying        : yum-utils-4.0.21-3.el8.noarch                                                                                             1/1

Installed:
  yum-utils-4.0.21-3.el8.noarch

Complete!

设置镜像仓库

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

[root@localhost yum.repos.d]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

安装 docker

[root@localhost ~]# sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

Docker CE Stable - x86_64                                                                                                                                     51 kB/s |  31 kB     00:00
Dependencies resolved.
=============================================================================================================================================================================================
 Package                                          Architecture                  Version                                                        Repository                               Size
=============================================================================================================================================================================================
Installing:
 containerd.io                                    x86_64                        1.6.9-3.1.el8                                                  docker-ce-stable                         33 M
 docker-ce                                        x86_64                        3:20.10.21-3.el8                                               docker-ce-stable                         21 M
 docker-ce-cli                                    x86_64                        1:20.10.21-3.el8                                               docker-ce-stable                         30 M
 docker-compose-plugin                            x86_64                        2.12.2-3.el8                                                   docker-ce-stable                         10 M
Installing dependencies:
 container-selinux                                noarch                        2:2.167.0-1.module_el8.5.0+911+f19012f9                        AppStream                                54 k
 docker-ce-rootless-extras                        x86_64                        20.10.21-3.el8                                                 docker-ce-stable                        4.6 M
 fuse-overlayfs                                   x86_64                        1.7.1-1.module_el8.5.0+890+6b136101                            AppStream                                73 k
 fuse3                                            x86_64                        3.2.1-12.el8                                                   base                                     50 k
 fuse3-libs                                       x86_64                        3.2.1-12.el8                                                   base                                     94 k
 libslirp                                         x86_64                        4.4.0-1.module_el8.5.0+890+6b136101                            AppStream                                70 k
 slirp4netns                                      x86_64                        1.1.8-1.module_el8.5.0+890+6b136101                            AppStream                                51 k
Installing weak dependencies:
 docker-scan-plugin                               x86_64                        0.21.0-3.el8                                                   docker-ce-stable                        3.8 M
Enabling module streams:
 container-tools                                                                rhel8

Transaction Summary
=============================================================================================================================================================================================
Install  12 Packages

Total download size: 103 M
Installed size: 394 M
Is this ok [y/N]: y
Downloading Packages:
(1/12): fuse3-3.2.1-12.el8.x86_64.rpm                                                                                                                         75 kB/s |  50 kB     00:00
(2/12): container-selinux-2.167.0-1.module_el8.5.0+911+f19012f9.noarch.rpm                                                                                    76 kB/s |  54 kB     00:00
(3/12): fuse3-libs-3.2.1-12.el8.x86_64.rpm                                                                                                                    82 kB/s |  94 kB     00:01
(4/12): libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64.rpm                                                                                               80 kB/s |  70 kB     00:00
(5/12): fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64.rpm                                                                                         78 kB/s |  73 kB     00:00
(6/12): slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_64.rpm                                                                                            86 kB/s |  51 kB     00:00
(7/12): docker-ce-20.10.21-3.el8.x86_64.rpm                                                                                                                   88 kB/s |  21 MB     04:05
(8/12): docker-ce-rootless-extras-20.10.21-3.el8.x86_64.rpm                                                                                                   86 kB/s | 4.6 MB     00:54
(9/12): docker-ce-cli-20.10.21-3.el8.x86_64.rpm                                                                                                               87 kB/s |  30 MB     05:48
(10/12): containerd.io-1.6.9-3.1.el8.x86_64.rpm                                                                                                               87 kB/s |  33 MB     06:26
(11/12): docker-scan-plugin-0.21.0-3.el8.x86_64.rpm                                                                                                           86 kB/s | 3.8 MB     00:45
(12/12): docker-compose-plugin-2.12.2-3.el8.x86_64.rpm                                                                                                        86 kB/s |  10 MB     02:02
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                        247 kB/s | 103 MB     07:05
Docker CE Stable - x86_64                                                                                                                                    3.7 kB/s | 1.6 kB     00:00
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) <docker@docker.com>"
 Fingerprint: 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
 From       : https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                     1/1
  Installing       : docker-scan-plugin-0.21.0-3.el8.x86_64                                                                                                                             1/12
  Running scriptlet: docker-scan-plugin-0.21.0-3.el8.x86_64                                                                                                                             1/12
  Running scriptlet: container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch                                                                                                   2/12
  Installing       : container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch                                                                                                   2/12
  Running scriptlet: container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch                                                                                                   2/12
  Installing       : containerd.io-1.6.9-3.1.el8.x86_64                                                                                                                                 3/12
  Running scriptlet: containerd.io-1.6.9-3.1.el8.x86_64                                                                                                                                 3/12
  Installing       : docker-ce-cli-1:20.10.21-3.el8.x86_64                                                                                                                              4/12
  Running scriptlet: docker-ce-cli-1:20.10.21-3.el8.x86_64                                                                                                                              4/12
  Installing       : libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64                                                                                                                5/12
  Installing       : slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_64                                                                                                             6/12
  Installing       : fuse3-libs-3.2.1-12.el8.x86_64                                                                                                                                     7/12
  Running scriptlet: fuse3-libs-3.2.1-12.el8.x86_64                                                                                                                                     7/12
  Installing       : fuse3-3.2.1-12.el8.x86_64                                                                                                                                          8/12
  Installing       : fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64                                                                                                          9/12
  Running scriptlet: fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64                                                                                                          9/12
  Installing       : docker-ce-3:20.10.21-3.el8.x86_64                                                                                                                                 10/12
  Running scriptlet: docker-ce-3:20.10.21-3.el8.x86_64                                                                                                                                 10/12
  Installing       : docker-ce-rootless-extras-20.10.21-3.el8.x86_64                                                                                                                   11/12
  Running scriptlet: docker-ce-rootless-extras-20.10.21-3.el8.x86_64                                                                                                                   11/12
  Installing       : docker-compose-plugin-2.12.2-3.el8.x86_64                                                                                                                         12/12
  Running scriptlet: docker-compose-plugin-2.12.2-3.el8.x86_64                                                                                                                         12/12
  Running scriptlet: container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch                                                                                                  12/12
  Running scriptlet: docker-compose-plugin-2.12.2-3.el8.x86_64                                                                                                                         12/12
  Verifying        : fuse3-3.2.1-12.el8.x86_64                                                                                                                                          1/12
  Verifying        : fuse3-libs-3.2.1-12.el8.x86_64                                                                                                                                     2/12
  Verifying        : container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch                                                                                                   3/12
  Verifying        : fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64                                                                                                          4/12
  Verifying        : libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64                                                                                                                5/12
  Verifying        : slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_64                                                                                                             6/12
  Verifying        : containerd.io-1.6.9-3.1.el8.x86_64                                                                                                                                 7/12
  Verifying        : docker-ce-3:20.10.21-3.el8.x86_64                                                                                                                                  8/12
  Verifying        : docker-ce-cli-1:20.10.21-3.el8.x86_64                                                                                                                              9/12
  Verifying        : docker-ce-rootless-extras-20.10.21-3.el8.x86_64                                                                                                                   10/12
  Verifying        : docker-compose-plugin-2.12.2-3.el8.x86_64                                                                                                                         11/12
  Verifying        : docker-scan-plugin-0.21.0-3.el8.x86_64                                                                                                                            12/12

Installed:
  container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch    containerd.io-1.6.9-3.1.el8.x86_64                           docker-ce-3:20.10.21-3.el8.x86_64
  docker-ce-cli-1:20.10.21-3.el8.x86_64                               docker-ce-rootless-extras-20.10.21-3.el8.x86_64              docker-compose-plugin-2.12.2-3.el8.x86_64
  docker-scan-plugin-0.21.0-3.el8.x86_64                              fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64    fuse3-3.2.1-12.el8.x86_64
  fuse3-libs-3.2.1-12.el8.x86_64                                      libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64          slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_64

Complete!

启动Docker

sudo systemctl start docker

测试

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

配置阿里云镜像加速器

登录阿里云

阿里云控制台首页 (aliyun.com)

打开控制台

 点击展开

 下滑找到容器镜像服务

 输入指令

 输入指令进行测试

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/

常用命令

启动docker

systemctl start docker

停止docker

systemctl stop docker

查看docker状态

systemctl status docker

重启

systemctl restart docker

开机启动

systemctl enable docker

查看信息

docker info

查看帮助文档

docker --help


 

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
Linux内网环境中安装Docker详细步骤如下: 1. 首先,确保你的Linux系统满足Docker的要求。通常,Docker要求使用64位的操作系统,并且内核版本要在3.10以上。 2. 下载Docker安装包。你可以从Docker官方网站上下载适用于你的Linux发行版的Docker安装包。例如,如果你使用的是Ubuntu,可以使用以下命令下载最新版本的Docker安装包: ```shell wget https://download.docker.com/linux/ubuntu/dists/focal/pool/stable/amd64/docker-ce-cli_20.10.6~3-0~ubuntu-focal_amd64.deb wget https://download.docker.com/linux/ubuntu/dists/focal/pool/stable/amd64/containerd.io_1.4.4-1_amd64.deb wget https://download.docker.com/linux/ubuntu/dists/focal/pool/stable/amd64/docker-ce_20.10.6~3-0~ubuntu-focal_amd64.deb ``` 这里使用了Ubuntu 20.04的示例,如果你使用其他版本的Ubuntu,请替换下载链接中的"focal"为你的版本代号。 3. 安装Docker依赖。执行以下命令安装Docker所需的依赖项: ```shell sudo apt update sudo apt install -y libltdl7 ``` 4. 安装Docker。使用以下命令安装下载的Docker安装包: ```shell sudo dpkg -i containerd.io_1.4.4-1_amd64.deb sudo dpkg -i docker-ce-cli_20.10.6~3-0~ubuntu-focal_amd64.deb sudo dpkg -i docker-ce_20.10.6~3-0~ubuntu-focal_amd64.deb ``` 如果在安装过程中遇到依赖问题,可以尝试使用`sudo apt --fix-broken install`命令修复依赖关系。 5. 启动Docker服务。执行以下命令启动Docker服务: ```shell sudo systemctl start docker ``` 6. 验证Docker是否正确安装。运行以下命令检查Docker版本信息: ```shell docker version ``` 如果成功显示Docker版本信息,则说明Docker已经安装成功。 请注意,由于内网环境的限制,可能需要解决网络访问问题或配置本地镜像仓库以获取Docker镜像。另外,确保在安装Docker之前,没有已存在的Docker安装或旧版本的Docker正在运行。 希望以上步骤对你有帮助。如果有任何问题,请随时提问。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

白鱼塘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值