当前位置:首页 » 《关注互联网》 » 正文

Docker系列文-----我们为什么要使用Docker?以及Docker的安装与部署(1)_m0_55724788的博客

22 人参与  2021年08月12日 09:43  分类 : 《关注互联网》  评论

点击全文阅读


Docker系列文-----我们为什么要使用Docker?以及Docker的安装与部署(1)

  • 一.容器是什么?
  • 我们为什么要使用容器呢?容器有什么好处?
    • 容器有什么好处呢?
    • Docker和VMware同样是虚拟化,Docker优势在哪?
  • 二.在Centos8上安装Docker:
      • 一.预先操作:
      • 二.卸载之前的Docker:
      • 三.添加仓库文件:
      • 四.添加仓库文件:
      • 五.启动Docker服务,并且设置docker开机启动
      • 六.测试运行一个docker容器
  • 三.在Ubuntu系统上安装Docker
      • 一.卸载旧的docker
      • 二.更新
      • 三.添加docker官方的gpg密钥
      • 四.添加镜像源
      • 五.安装
      • 六.测试

一.容器是什么?

在这里插入图片描述

Use containers to Build, Share and Run your applications

使用容器构建、共享和运行应用程序

简单地说,一个容器包含了完整的运行时环境:除了应用程序本身之外,这个应用所需的全部依赖、类库、其他二进制文件、配置文件等,都统一被打入了一个称为容器镜像的包中。通过将应用程序本身,和其依赖容器化,操作系统发行版本和其他基础环境造成的差异,都不影响程序本身的运行。

我们为什么要使用容器呢?容器有什么好处?

大家都知道,在我们每个人的开发过程中,可能有一个代码文件(py或sh)在你的机器环境中无法运行,却在别人的机器上一路畅通。那么代码数据都是相同的,不同的就是机器的运行环境不同。而这一点在公司各部门之间的交接的时候,就会造成很大的问题。容器(Containers)便应运而生。

容器有什么好处呢?

一.灵活

同一个文件可以在Linux、Windows、开发或测试环境中都能运行

二.标准化

大多数容器实现技术基于开放标准,可以运行在所有主流 的Linux 发行版、Microsoft等操作系统上。
容器镜像提供版本控制,这样就可以追踪不同版本的容器,监控版本之间的差异。

三.安全性

一台虚拟机上可以运行多个容器,可以随时切换、开始、终止运行,但是容器之间互不影响,容器之间是相互隔离的。一个容器环境损坏并不影响其他容器。

Docker和VMware同样是虚拟化,Docker优势在哪?

在这里插入图片描述

如图,简单来说 Docker的启动速度更快、消耗资源更少、拓展更加的方便。更高、更快、更强

如果想知道更多 可以前往Docker的官方网站进行了解 Docker官方网站点击跳转

二.在Centos8上安装Docker:

一.预先操作:

1.设置自己用户名为docker 方便与其他机器分辨
2.确保自己的系统Centos为Centos 8系统

[root@localhost ~]# hostnamectl set-hostname sc-docker
[root@localhost ~]# su -
上一次登录:二 8月 10 23:33:43 CST 2021从 192.168.2.10pts/0 上
[root@sc-docker ~]# 
[root@sc-docker ~]# cat /etc/centos-release
CentOS Linux release 8.3.2011

二.卸载之前的Docker:

\是续航符号:继续到下一行

[root@sc-docker ~]# yum remove docker \
>                   docker-client \
>                   docker-client-latest \
>                   docker-common \
>                   docker-latest \
>                   docker-latest-logrotate \
>                   docker-logrotate \
>                   docker-engine
> --------------------------------------------------------
未找到匹配的参数: docker
未找到匹配的参数: docker-client
未找到匹配的参数: docker-client-latest
未找到匹配的参数: docker-common
未找到匹配的参数: docker-latest
未找到匹配的参数: docker-latest-logrotate
未找到匹配的参数: docker-logrotate
未找到匹配的参数: docker-engine
没有软件包需要移除。
依赖关系解决。
无需任何处理。
完毕!

三.添加仓库文件:

安装yum-utils包(它提供yum-config-manager实用程序)并设置稳定存储库。

yum install -y yum-utils

添加docker官方的yum仓库文件,一会儿我们需要去docker官方的yum仓库下载软件

> [root@sc-docker ~]# yum-config-manager \
>     --add-repo \
>     https://download.docker.com/linux/centos/docker-ce.repo
添加仓库自:https://download.docker.com/linux/centos/docker-ce.repo

我们可以选择添加阿里云的国内镜像docker仓库,这样下载速度会更快

> [root@sc-docker ~]# yum-config-manager \
>     --add-repo \
>     http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
添加仓库自:http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

四.添加仓库文件:

[root@sc-docker yum.repos.d]# yum install docker-ce docker-ce-cli containerd.io -y

五.启动Docker服务,并且设置docker开机启动

[root@sc-docker yum.repos.d]# systemctl start docker
[root@sc-docker yum.repos.d]# systemctl enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.

六.测试运行一个docker容器

[root@sc-docker yum.repos.d]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
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/

这一步结束后代表着Centos8的安装成功了



三.在Ubuntu系统上安装Docker

一.卸载旧的docker

sudo apt-get remove docker docker-engine docker.io containerd runc

二.更新

更新系统里的所有的能更新的软件

sudo apt-get update

安装相关的安装包

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

三.添加docker官方的gpg密钥

curl 是字符界面的浏览器、gpgkey 是用来验证软件的真伪—》防伪的

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

四.添加镜像源

xiaoxiong@root:~$ echo \
>   "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
>   $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

五.安装

添加镜像源之后的更新apt-get

 xiaoxiong@root:~$ sudo apt-get update

再安装docker-ce这个软件(下载过程可能比较慢)

sudo apt-get install docker-ce docker-ce-cli containerd.io -y

六.测试

xiaoxiong@root:~$ sudo docker run hello-world
[sudo] password for xiaoxiong: 
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
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/

这一步结束后代表着Ubuntu的安装成功了



感谢各位看官!!!

在这里插入图片描述


点击全文阅读


本文链接:http://zhangshiyu.com/post/25196.html

容器  添加  安装  
<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1