zoukankan      html  css  js  c++  java
  • Ubuntu安装Docker 适合Ubuntu17.04版本

    Docker介绍

    Docker是一个开源的容器引擎,它有助于更快地交付产品。Docker可将应用程序和基础设施层隔离,并且将基础设施当作程序一样进行管理。使用Docker,可以更快地打包,测试以及部署应用程序,并可以缩短从编程到部署运行代码的周期。

    Docker架构

    • Docker daemon

      守护进程,运行在宿主机(DOCKER_HOST)的后台进程,可通过Docker客户端与之通信。

    • Client
      Docker客户端时Docker的用户界面,可以接受用户命令和配置标识,并且Docker daemon通信

    • Images
      Docker镜像是一个只读模板,包含创建Docker容器的说明。Docker镜像可以运行Docker镜像中的程序。

    • Container
      容器是镜像的可运行实例。镜像与容器类似与面向对象中类与对象的关系。可通过Docker API或者CLI命令起停,移动,删除等。

    • Register
      Docker Register是一个集中存储与分发镜像的服务。构建完Docker镜像后,就可在当前宿主机上运行。但如果想在其他机器上运行这个镜像,就需要手动复制。此时可以借助Docker Register避免复制。
      一个Docker Register可以包含多个Docker仓库,每个仓库可包含多个镜像标签,每个标签对应一个Docker镜像。

    安装Docker

    其实开源的应用,官网都有正确的安装教程(英文版),本章按照官网的教程安装。

    1. 安装仓库

    安装Docker社区版仓库

    sudo apt-get -y install 
      apt-transport-https 
      ca-certificates 
      curl
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    sudo add-apt-repository 
           "deb [arch=amd64] https://download.docker.com/linux/ubuntu 
           $(lsb_release -cs) 
           stable"
    sudo apt-get update
    ××××××××××××××××××××××××××××××××××××××××××××××如果出现一下情况××××××××××××××××××××××××××××××××××××××××××××××××××

        出现这个问题可能是有另一个程序正在运行,导致资源被锁不可用。而导致资源被锁的原因可能是上次运行安装或更新没有正常完成,解决办法就是删掉。

        sudo rm /var/cache/apt/archives/lock

        sudo rm /var/lib/dpkg/lock

    ××××××××××××××××××××××××××××××××××××××××××××××××解决方案××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
    1. 获取Docker社区版

    在Ubuntu上安装最新的Docker社区版

    sudo apt-get -y install docker-ce
    1. 测试你的Docker社区版是否安装成功
    sudo docker run hello-world

    安装后可查看版本

    xq@xq-VPCEG17YC:/etc/apt/sources.list.d$ docker version
    Client:
     Version:      17.03.1-ce
     API version:  1.27
     Go version:   go1.7.5
     Git commit:   c6d412e
     Built:        Mon Mar 27 17:14:09 2017
     OS/Arch:      linux/amd64

    配置镜像加速

    sudo docker run hello-world的时候可能会出现timeout,应用国内访问Docker Hub不稳定。建议改成阿里云或者DaoCloud。本节以阿里云为例。

    注册阿里云账户

    访问https://cr.console.aliyun.com/#/accelerator

    可以获得自己的加速器 https://××××××.mirror.aliyuncs.com

    echo "DOCKER_OPTS="--registry-mirror=https://××××××.mirror.aliyuncs.com"" | sudo tee -a /etc/default/docker
    
    sudo service docker restart

    安装成功如下:

    xq@xq-VPCEG17YC:/etc/docker$ echo "DOCKER_OPTS="--registry-mirror=https://××××××.mirror.aliyuncs.com"" | sudo tee -a /etc/default/docker
    DOCKER_OPTS="--registry-mirror=https://bzf7wkv2.mirror.aliyuncs.com"
    xq@xq-VPCEG17YC:/etc/docker$ sudo service docker restart
    xq@xq-VPCEG17YC:/etc/docker$ sudo docker run hello-world
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    78445dd45222: Pull complete 
    Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
    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.
     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://cloud.docker.com/
    
    For more examples and ideas, visit:
     https://docs.docker.com/engine/userguide/
  • 相关阅读:
    巴比伦富翁的理财课:有史以来最完美的致富圣经读后感
    【数据结构与算法】爱吃香蕉的珂珂:二分法思想实现
    【数据结构与算法】有序数组查找:二分查找算法实现
    【数据结构与算法】找出最小的k个数:三路快速排序算法思想实现
    【数据结构与算法】第K大的元素:三路快速排序算法思路
    【数据结构与算法】颜色分类:三路快速排序算法思想实现
    页面轮播
    sh重启脚本
    关于mac自带的openssl和brew安装的openssl冲突
    vconsole使用
  • 原文地址:https://www.cnblogs.com/jyxbk/p/8297521.html
Copyright © 2011-2022 走看看