二、Docker的安装

二、Docker的安装

一、Docker的基本组成

在这里插入图片描述

镜像(images)

Docker镜像就好比是一个模板,可以通过这个模板来创建容器服务,tomcat镜像===>run tomcat01容器(提供服务) ,通过这个镜像可以创建多个容器 ,【最终服务的运行或者是项目的运行就是在这个容器中的】这里可以暂时理解为JAVA 中 类与对象的关系

容器(container)

Docker利用容器技术,独立运行一个或者一组应用,通过镜像来创建。

启动,停止,删除基本命令

仓库(repository)

仓库就是存放镜像的地方!

仓库分为公有仓库和私有仓库

Dcoker Hub(默认是国外的),国内也有很多公有仓库,例如 阿里云…(可以配置镜像加速)

二、安装Docker

环境准备

  1. 需要有一定的linux的基础
  2. Linux系统最好使用CentOS7
  3. Win系统可以使用Xshell去连接,MAC 系统可以使用 终端 连接
  4. 跟着官方文档一步一步来!!! 官方文档非常的详细

环境查看

# 系统的内核是3.10+
[root@iZhp3do4qhzu84445osa3sZ ~]# uname -r
3.10.0-1062.18.1.el7.x86_64
# 系统版本
[root@iZhp3do4qhzu84445osa3sZ ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

Docker 帮助文档

  1. 官方文档: https://www.docker.com/
  2. 选择Linux版本的Docker
  3. 选择安装到CentOS 需要CentOS的版本在7+才可以支持
# 1. 卸载旧的版本
yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

# 2. 需要的安装包
yum install -y yum-utils

# 3. 设置镜像的仓库
yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo  # 默认是国外的  不推荐
    
yum-config-manager \
    --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo  # 阿里云镜像地址   推荐 
    
# 4. 更新yum !!! 不然后面可能会报错
yum makecache fase
    
# 5. 安装Docker相关的内容(这里是最新版本,如果想安装其他版本版本参考官方文档)   ce-社区版   ee-企业版
yum install docker-ce docker-ce-cli containerd.io

# 6. 启动docker
systemctl start docker

# 7. 使用docker version 查看docker是否启动成功
[root@iZhp3do4qhzu84445osa3sZ ~]# docker version
Client:
 Version:         1.13.1
 API version:     1.26
 Package version: docker-1.13.1-109.gitcccb291.el7.centos.x86_64
 Go version:      go1.10.3
 Git commit:      cccb291/1.13.1
 Built:           Tue Mar  3 17:21:24 2020
 OS/Arch:         linux/amd64

Server:
 Version:         1.13.1
 API version:     1.26 (minimum version 1.12)
 Package version: docker-1.13.1-109.gitcccb291.el7.centos.x86_64
 Go version:      go1.10.3
 Git commit:      cccb291/1.13.1
 Built:           Tue Mar  3 17:21:24 2020
 OS/Arch:         linux/amd64
 Experimental:    false
 
 # 8. 测试 hello-world
 [root@iZhp3do4qhzu84445osa3sZ ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally  # 没有寻找到hello-world镜像
Trying to pull repository docker.io/library/hello-world ... #尝试从远程仓库中寻找hello-world镜像
latest: Pulling from docker.io/library/hello-world #在远程仓库寻找到了该镜像,并且正在pull
0e03bdcc26d7: Pull complete 
Digest: sha256:d58e752213a51785838f9eed2b7a498ffa1cb3aa7f946dda11af39286c3db9a9
Status: Downloaded newer image for docker.io/hello-world:latest

Hello from Docker!  #运行成功显示   相当于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/
 
 # 9. 通过docker images 查看存在的镜像
[root@iZhp3do4qhzu84445osa3sZ ~]# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
docker.io/rabbitmq          latest              7e50c60f7e3e        3 days ago          156 MB
docker.io/redis             latest              235592615444        10 days ago         104 MB
docker.io/nginx             latest              2622e6cca7eb        10 days ago         132 MB
docker.io/sonatype/nexus3   latest              57a6261043b9        2 months ago        644 MB
docker.io/hello-world       latest              bf756fb1ae65        5 months ago        13.3 kB
docker.io/mysql             5.7.25              98455b9624a9        15 months ago       372 MB 
# 卸载Docker

# 1. 卸载依赖
yum remove docker-ce docker-ce-cli containerd.io

# 2. 删除资源文件
rm -rf /var/lib/docker

# 3. Docker的默认工作路径
/var/lib/docker

三、阿里云镜像加速

  1. 登录自己的阿里云 搜索 “容器镜像服务”
    在这里插入图片描述

  2. 找到镜像加速地址
    在这里插入图片描述

  3. 配置使用

# 1.在docker目录中新建文件夹
sudo mkdir -p /etc/docker

# 2.配置了一个阿里云的地址 (只有当前的服务器可以用,内网地址)
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://14ukbbwv.mirror.aliyuncs.com"]
}
EOF

# 3.重启镜像
sudo systemctl daemon-reload

# 4.重启docker
sudo systemctl restart docker

# 5. 配置完毕
[root@iZhp3do4qhzu84445osa3sZ ~]# sudo mkdir -p /etc/docker
[root@iZhp3do4qhzu84445osa3sZ ~]# sudo tee /etc/docker/daemon.json <<-'EOF'
> {
>   "registry-mirrors": ["https://14ukbbwv.mirror.aliyuncs.com"]
> }
> EOF
{
  "registry-mirrors": ["https://14ukbbwv.mirror.aliyuncs.com"]
}
[root@iZhp3do4qhzu84445osa3sZ ~]# sudo systemctl daemon-reload
[root@iZhp3do4qhzu84445osa3sZ ~]# sudo systemctl restart docker
[root@iZhp3do4qhzu84445osa3sZ ~]# 

四、Docker的执行流程

执行 docker run hello-world 后的执行流程分析

 [root@iZhp3do4qhzu84445osa3sZ ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally  # 没有寻找到hello-world镜像
Trying to pull repository docker.io/library/hello-world ... #尝试从远程仓库中寻找hello-world镜像
latest: Pulling from docker.io/library/hello-world #在远程仓库寻找到了该镜像,并且正在pull
0e03bdcc26d7: Pull complete 
Digest: sha256:d58e752213a51785838f9eed2b7a498ffa1cb3aa7f946dda11af39286c3db9a9
Status: Downloaded newer image for docker.io/hello-world:latest

Hello from Docker!  #运行成功显示   相当于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 在执行 docker run 这个命令的流程图

在这里插入图片描述

Docker 未找到镜像示例

[root@iZhp3do4qhzu84445osa3sZ ~]# docker run hzbs66666666666666
Unable to find image 'hzbs66666666666666:latest' locally
Trying to pull repository docker.io/library/hzbs66666666666666 ... 
/usr/bin/docker-current: repository docker.io/hzbs66666666666666 not found: does not exist or no pull access.
See '/usr/bin/docker-current run --help'.
[root@iZhp3do4qhzu84445osa3sZ ~]# 

五、底层原理

Dcoker是如何工作的

Docker是C/S Client-Server 结构的系统 ,Docker的守护进程一直在宿主机上运行,通过Socket 从客户端访问!

DcoekrServer在接收到Docker-Client 的指令,就会执行这个命令!

在这里插入图片描述

每一个容器都是独立的环境 可以同时开启8080端口 互不影响!

Docker为什么比VM块

  1. Docker 有着比虚拟机更少的抽象层
  2. Dcoker利用的是宿主机的内核,vm需要的是Guest OS 。
  3. 虚拟化技术数据对比:
dockerLXCVM
虚拟化类型OS虚拟化OS虚拟化硬件虚拟化
性能=物理机性能=物理机性能5%-20%的性能损耗
隔离性NS隔离NS隔离
QosGgroup弱Ggroup弱
安全性
GuestOS只支持Linux只支持Linux全部
可迁移
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值