0
点赞
收藏
分享

微信扫一扫

Cloud ❀ Docker的安装与部署

他说Python 2022-06-24 阅读 52


文章目录

  • ​​1、CentOS 6安装Docker​​
  • ​​2、CentOS 7/8安装Docker​​
  • ​​(1)卸载旧版本Docker与其依赖关系,如果没有安装过Docker则无需卸载就版本与其依赖包​​
  • ​​(2)安装Docker​​
  • ​​3、升级Docker​​
  • ​​4、配置Docker镜像加速器​​


Docker:是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可以移植的镜像中,然后发布到任意系统中,实现虚拟化;
一个完整的Docker由四个部分组成:

  • Client客户端
  • Daemon守护进程
  • Image镜像
  • Container容器

Docker有着比虚拟机更少的抽象层,由于Docker不需要Hypervisor实现硬件资源虚拟化,运行在Docker容器上的程序直接使用宿主机的硬件资源,因此在资源的占用上Docker有明显的优势;
Cloud ❀ Docker的安装与部署_git

Docker利用的是宿主机的内核,不需要虚拟机系统,因此当创建一个容器时,Docker不需要和虚拟机一样重新加载一个操作系统内核,因此创建一个Docker容器的操作是秒级;
Cloud ❀ Docker的安装与部署_git_02

Docker部署前准备操作,宿主机需要访问网络,从网络中下载对应的Docker包(也可以通过本地Yum源安装,此处不做赘述);

[root@localhost ~]# yum clean all     /清理Yum仓库
[root@localhost ~]# yum makecache /建立Yum缓存,将服务器包信息下载到本地
[root@localhost ~]# yum update -y /更新Yum仓库(更新时间较长)

1、CentOS 6安装Docker

此处不再赘述Yum源的配置与使用,参考以上内容;

[root@localhost ~]# yum install -y epel-release   /安装依赖
[root@localhost ~]# yum install -y docker-io /安装Docker
[root@localhost ~]# cat /etc/sysconfig/docker /查看配置文件
~
other_args= /填写阿里云镜像加速器链接;
~
[root@localhost ~]# service docker start /重启服务
[root@localhost ~]# docker version /查看版本信息

2、CentOS 7/8安装Docker

此处不再赘述Yum源的配置与使用,参考以上内容;

(1)卸载旧版本Docker与其依赖关系,如果没有安装过Docker则无需卸载就版本与其依赖包

[root@localhost ~]# sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine

(2)安装Docker

设置Docker仓库

[root@localhost ~]# sudo yum install yum-utils -y

设置稳定Docker仓库

[root@localhost ~]# sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo /官方源仓库
Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
部分仓库内容默认被禁用,可以使用下面的命令进行启用,如果不需要可以忽略此步骤
[root@localhost ~]# sudo yum-config-manager --enable docker-ce-nightly /开启夜间存储库
[root@localhost ~]# sudo yum-config-manager --enable docker-ce-test /开启测试通道
[root@localhost ~]# sudo yum-config-manager --disable docker-ce-nightly /关闭夜间存储库

安装最新版本Docker引擎和容器

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

安装特定版本的Docker引擎和容器
列出并排序可用的Docker版本,返回的列表取决于启用了哪些存储库,并且特定于系统版本;

[root@localhost ~]# yum list docker-ce --showduplicates | sort -r
Last metadata expiration check: 0:00:45 ago on Wed 03 Mar 2021 01:02:22 AM PST.
Installed Packages
docker-ce.x86_64 3:20.10.5-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.5-3.el8 @docker-ce-stable
docker-ce.x86_64 3:20.10.4-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.3-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.2-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.1-3.el8 docker-ce-stable
docker-ce.x86_64 3:20.10.0-3.el8 docker-ce-stable
docker-ce.x86_64 3:19.03.15-3.el8 docker-ce-stable
docker-ce.x86_64 3:19.03.14-3.el8 docker-ce-stable
docker-ce.x86_64 3:19.03.13-3.el8 docker-ce-stable
Available Packages

通过完全合格的包名安装一个特定的版本

[root@localhost ~]# sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
[root@localhost ~]# sudo yum install docker-ce-20.10.2 docker-ce-cli-20.10.2 containerd.io

启动Docker

[root@localhost ~]# sudo systemctl start docker

查看Docker版本信息

[root@localhost ~]# docker version
Client: Docker Engine - Community
Version: 20.10.5
API version: 1.41
Go version: go1.13.15
Git commit: 55c4c88
Built: Tue Mar 2 20:17:04 2021
OS/Arch: linux/amd64
Context: default
Experimental: true

Server: Docker Engine - Community
Engine:
Version: 20.10.5
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: 363e9a8
Built: Tue Mar 2 20:15:27 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.3
GitCommit: 269548fa27e0089a8b8278fc4fc781d7f65a939b
runc:
Version: 1.0.0-rc92
GitCommit: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
docker-init:
Version: 0.19.0
GitCommit: de40ad0

验证Dokcer是否成功安装

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

3、升级Docker

安装最新版本即可完成升级

4、配置Docker镜像加速器

默认Docker仓库使用国外的服务器,鉴于后续下载内容的网速,推荐使用国内的源进行下载,此处更新为阿里云的镜像加速器,每一个镜像加速器都是不同的,需要自行去阿里云镜像服务官网获取,URL链接如下:
​​​ https://cr.console.aliyun.com/cn-qingdao/instances/mirrors​​Cloud ❀ Docker的安装与部署_git_03

镜像加速器配置方式

[root@localhost ~]# mkdir -pv /etc/docker/
[root@localhost ~]# vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://sta7qavr.mirror.aliyuncs.com"]
}
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker

检测是否成功配置镜像加速器

[root@localhost ~]# docker info | grep aliyun
https://sta7qavr.mirror.aliyuncs.com/


举报

相关推荐

0 条评论