当前位置 博文首页 > 文章内容

    docker安装

    作者: 栏目:未分类 时间:2020-09-16 18:00:52

    本站于2023年9月4日。收到“大连君*****咨询有限公司”通知
    说我们IIS7站长博客,有一篇博文用了他们的图片。
    要求我们给他们一张图片6000元。要不然法院告我们

    为避免不必要的麻烦,IIS7站长博客,全站内容图片下架、并积极应诉
    博文内容全部不再显示,请需要相关资讯的站长朋友到必应搜索。谢谢!

    另祝:版权碰瓷诈骗团伙,早日弃暗投明。

    相关新闻:借版权之名、行诈骗之实,周某因犯诈骗罪被判处有期徒刑十一年六个月

    叹!百花齐放的时代,渐行渐远!



    docker安装

    docker的基本组件

    docker的架构图

    image-20200909165754515

    镜像(images)

    Docker 镜像好比是一个模板 eg nginx 镜像 -----> run --------> nginx 容器(提供服务)

    容器(containers)

    Docker 通过容器技术 独立一个或者一个组的应用 通过镜像来创建的

    启动 停止 删除 等基本命令!

    可以将容器理解为一个简易的linux 系统

    仓库(registray)

    仓库就是存储镜像的!

    • 共有仓库

      dockerhub

      阿里云

    • 私有仓库

    安装docker

    环境准备

    1.准备一台centos7

    环境查看

    # 系统内核必须是3.0 以上的
    [root@localhost ~]# uname -r 
    3.10.0-862.el7.x86_64
    
    #查看系统版本
    [root@localhost ~]# uname -r 
    3.10.0-862.el7.x86_64
    [root@localhost ~]# 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"
    

    安装

    查看官方的帮助文档

    # 1. 卸载旧的版本
    $ sudo yum remove docker \
                      docker-client \
                      docker-client-latest \
                      docker-common \
                      docker-latest \
                      docker-latest-logrotate \
                      docker-logrotate \
                      docker-engine
                      
    # 2.需要的一些安装包
    $ sudo yum install -y yum-utils
    # 3.配置阿里云的镜像源
    $ sudo yum-config-manager \
        --add-repo \
        https://download.docker.com/linux/centos/docker-ce.repo   #(默认是国外的  非常慢)
        
    $ sudo yum-config-manager \
        --add-repo \
      	http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo  #推荐使用阿里云的
    # 4. 安装 docker 相关的包   docker-ce是社区版(一般安装社区版)  ee是企业版
    $ sudo yum install docker-ce docker-ce-cli containerd.io -y
    
    
    #默认是安装最新的版本
    $ yum list docker-ce --showduplicates | sort -r  #可以查看可用的版本
    docker-ce.x86_64            3:19.03.12-3.el7                   @docker-ce-stable
    docker-ce.x86_64            3:19.03.11-3.el7                   docker-ce-stable 
    docker-ce.x86_64            3:19.03.10-3.el7                   docker-ce-stable 
    docker-ce.x86_64            3:19.03.0-3.el7                    docker-ce-stable 
    docker-ce.x86_64            3:18.09.9-3.el7                    docker-ce-stable 
    $ sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
    
    
    
    # 5. 启动
    
    [root@localhost ~]# systemctl start docker    # 启动服务
    [root@localhost ~]# systemctl enable docker   #开机自启动 避免重启服务器时 服务起不来
    Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
    
    # 6. 测试 hello-world
    [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:7f0a9f93b4aa3022c3a4c147a449bf11e0941a1fd0bf4a8e6c9408b2600777c5
    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/
    
    # 7.查看hello-world镜像
    

    image-20200909175638691

    # 8.查看hello-world容器
    

    image-20200909175808416

    #9.卸载docker
    $ sudo yum remove docker-ce docker-ce-cli containerd.io
    $ sudo rm -rf /var/lib/docker
    

    配置阿里云的镜像加速

    1、登录阿里云

    2、产品和服务

    image-20200910152301374

    Run 的流程和docker底层原理

    1.docker的run流程

    image-20200910153926801

    2.docker的底层原理

    Dokcer 是一个C/S 架构系统 docker守护进程是运行在宿主机上,通过socket从客户端访问

    DockerServer 通过DockerClient 指令会执行这个命令

    image-20200910155930871

    docker为什么比我们的VM快?

    1.docker比虚拟机更少抽象层

    image-20200910160700290

    2.新建一个docker不会像虚拟机一样重新加载一次内核能更好的避免引导所花费时间

    由此就能看出 传统虚拟机是分钟级 而docker是秒级的

    image-20200910161227745