Linux安装Docker(CentOS 8)与docker-compose套装

Linux安装Docker(CentOS 8)

1.操作系统

查看版本

lsb_release -a

这里是

[root@aliyun ~]# lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch
Distributor ID:	CentOS
Description:	CentOS Linux release 8.1.1911 (Core) 
Release:	8.1.1911
Codename:	Core

2.卸载旧版本

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

3.使用存储库安装

3.1 安装yum-utils软件包

$ sudo yum install -y yum-utils

$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

3.2 安装DOCKER引擎

$ sudo yum install docker-ce docker-ce-cli containerd.io

报错,error

Error: 
 Problem: package docker-ce-3:19.03.9-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
  - cannot install the best candidate for the job
  - package containerd.io-1.2.10-3.2.el7.x86_64 is excluded
  - package containerd.io-1.2.13-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.13-3.2.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.el7.x86_64 is excluded
  - package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.6-3.3.el7.x86_64 is excluded
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

手动安装最新的可用containerd.io软件包

$ sudo dnf install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm

ps:因为containerd.io软件包未作为docker-ce的依赖项安装,因此从系统卸载docker-ce时,不会自动将其删除
解决了报错后继续执行上面的安装语句
然后会出现提示您接受GPG密钥,选 y

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://download.docker.com/linux/centos/gpg
Is this ok [y/N]: y

输出如下,安装完毕

Running transaction
  Preparing        :                                                                                                                                                                   1/1 
  Installing       : docker-ce-cli-1:19.03.9-3.el7.x86_64                                                                                                                              1/3 
  Running scriptlet: docker-ce-cli-1:19.03.9-3.el7.x86_64                                                                                                                              1/3 
  Running scriptlet: libcgroup-0.41-19.el8.x86_64                                                                                                                                      2/3 
  Installing       : libcgroup-0.41-19.el8.x86_64                                                                                                                                      2/3 
  Running scriptlet: libcgroup-0.41-19.el8.x86_64                                                                                                                                      2/3 
  Installing       : docker-ce-3:19.03.9-3.el7.x86_64                                                                                                                                  3/3 
  Running scriptlet: docker-ce-3:19.03.9-3.el7.x86_64                                                                                                                                  3/3 
  Verifying        : libcgroup-0.41-19.el8.x86_64                                                                                                                                      1/3 
  Verifying        : docker-ce-3:19.03.9-3.el7.x86_64                                                                                                                                  2/3 
  Verifying        : docker-ce-cli-1:19.03.9-3.el7.x86_64                                                                                                                              3/3 

Installed:
  docker-ce-3:19.03.9-3.el7.x86_64                              docker-ce-cli-1:19.03.9-3.el7.x86_64                              libcgroup-0.41-19.el8.x86_64                             

Complete!

4.启动Docker

$ sudo systemctl start docker

5.运行hello world 测试

# 通过运行hello-world 映像来验证是否正确安装了Docker Engine
$ sudo docker run hello-world

输出

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

安装 docker-compose

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

执行以后,等待下载完成

[root@aliyun ~]# sudo curl -L "https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   638  100   638    0     0    661      0 --:--:-- --:--:-- --:--:--   660
100 11.6M  100 11.6M    0     0  82494      0  0:02:28  0:02:28 --:--:-- 77758
[root@aliyun ~]# 

继续执行

sudo chmod +x /usr/local/bin/docker-compose

测试

[root@aliyun ~]# sudo chmod +x /usr/local/bin/docker-compose
[root@aliyun ~]# docker-compose --version
docker-compose version 1.26.0, build d4451659

输出,代表成功 – OK,到此安装完毕哦~

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

程序员鱼丸

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

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

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

打赏作者

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

抵扣说明:

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

余额充值