zoukankan      html  css  js  c++  java
  • docker简介以及windows安装&linux离线安装docker

      docker官网:https://www.docker.com/

      docker官网图标如下:

        

      docker命令大全参考菜鸟教程:https://www.runoob.com/docker/docker-command-manual.html

    docker镜像仓库地址:

    (1)DaoCloud 道客网络: https://hub.daocloud.io/

    (2)网易(需要登陆):https://c.163yun.com/hub#/m/home/ 

    (3)阿里云(需要登陆):https://cr.console.aliyun.com/cn-beijing/instances/images

    1.docker简介

      Docker 是一个开源的应用容器引擎,可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app),更重要的是容器性能开销极低。

    1.什么是docker

    1.docker是一个容器平台软件;

    2.Docker公司开发、开源、托管在github上

    3.跨平台,支持linux、windows、macos 

    2.应用场景

    Web 应用的自动化打包和发布。
    自动化测试和持续集成、发布。
    在服务型环境中部署和调整数据库或其他的后台应用。

    3.优点

      Docker 是一个用于开发,交付和运行应用程序的开放平台。Docker 使您能够将应用程序与基础架构分开,从而可以快速交付软件。借助 Docker,您可以与管理应用程序相同的方式来管理基础架构。通过利用 Docker 的方法来快速交付,测试和部署代码,您可以大大减少编写代码和在生产环境中运行代码之间的延迟。

    4.解决问题

    1.环境不一致:经常看到java依赖外部环境,经常见到的程序员说的我本地没问题啊。比如说JDK8编译的程序放到另一台机器,机器上面的JDK是7就会报最低版本错误。docker把操作系统,jdk,tomcat,代码,配置全部放到集装箱里.再打包放到鲸鱼上,由鲸鱼给我们送到服务器上,在我的机器上怎么运行,在别的机器上也怎么运行.不会有任何的问题.一句话就是docker解决了运行环境不一致所带来的问题。

    2.不同程序直接依赖性太强,容易受其他程序影响

      docker每个容器都是一个进程,都可以看做一个虚拟的主机。docker在启动的时候就限定好一个容器最大使用的CPU硬盘,如果超过了,就会杀掉对应进程。

    2.docker标准化可以快速扩展、弹性伸缩。

    5.docker核心技术

       “镜像”就好比是面向对象中的“类”,“容器”就好比“类”创建的“对象”。在面向对象中,“类”定义了各种属性,“类”可以实例化出多个“对象”;而在Docker中,“镜像”定义了各种配置信息,它可以实例化出多个“容器”。“容器”就是一台可以运行的“虚拟机”。

    1.docker镜像Image

      docker镜像实际上是文件,文件就肯定存在本地。docker文件机制依赖于linux的联合文件系统(Union File System):它可以把多个目录(也叫分支)内容联合挂载到同一个目录下,而目录的物理位置是分开的。UnionFS允许只读和可读写目录并存,就是说可同时删除和增加内容。如下:(test1看做第一层、test2看做第二层,test就可以看到两个目录的所有文件)

      docker的镜像分层如下,Image层是镜像文件,可以是tomcat、jdk、我们的应用程序等等,镜像层是只读的。

    2.docker容器

      docker的容器实际上就是一个进程,为了便于理解可以将容器想象为一个虚拟机。docker的容器层(最上层)是可读可写的,但是镜像层是只读的,如果我们需要需要镜像层文件的时候,我们实际上是将文件拷贝到容器层,每次找的时候都是从顶层开始找的。由于容器的最上一层是可以修改的,镜像是不能修改的,这样就能保证镜像可以生成多个容器独立运行,没有任何干扰。

    3.docker仓库

      我们构建镜像的目的是为了将应用在其他机器运行,所以就需要将镜像推到仓库。这有点类似于git的仓库,可以将代码推到仓库,其他机子随意拉下来。

      docker自己提供了仓库,网速比较慢。所以需要用到镜像加速器。

      网易仓库地址:https://c.163.com/hub#/home

    2.windows安装docker

      windows下安装的docker实际上是虚拟了一个linux环境,建议还是linux上直接使用docker。

    1.下载安装包

    win7、win8 等需要利用 docker toolbox 来安装,下载地址

     2.运行安装

       直接全部下一步即可。下载完成桌面出现三个快捷方式。

     3.初始化docker工具

      【此时还未进行注册和启动虚拟机,若直接采用系统CMD命令窗口执行docker命令会产生错误。】

    打开Docker Quickstart Terminal。然后等待其初始化完成即可(可以关闭窗口)。

    补充:我在打开的时候报错windows 正在查找bash.exe。如果想亲自查找文件,请点击“浏览”

      原因是我在之前已经安装了git。解决办法:修改下面目标为自己的git地址

     补充:我在再次点击的时候cmd窗口提示looks like something went wrong in step ‘looking for vboxmanage.exe’

      原因是DOCKER_TOOLBOX_INStALL_PATH和VBOX_MSI_INSTALL_PATH这两个环境变量并没有生效,虽然你能看到它们,但是程序却看不到它们。你可以打开cmd然后输入set DOCKER_TOOLBOX_INStALL_PATH和set VBOX_MSI_INSTALL_PATH命令查看一下(我查看的时候有值)。解决办法:重启机器。

    4.查看版本

    C:UsersAdministrator>docker version
    Client:
     Version:       18.03.0-ce
     API version:   1.37
     Go version:    go1.9.4
     Git commit:    0520e24302
     Built: Fri Mar 23 08:31:36 2018
     OS/Arch:       windows/amd64
     Experimental:  false
     Orchestrator:  swarm
    
    Server: Docker Engine - Community
     Engine:
      Version:      19.03.5
      API version:  1.40 (minimum version 1.12)
      Go version:   go1.12.12
      Git commit:   633a0ea838
      Built:        Wed Nov 13 07:28:45 2019
      OS/Arch:      linux/amd64
      Experimental: false
     containerd:
      Version:      v1.2.10
      GitCommit:            b34a5c8af56e510852c35414db4c1f4fa6172339
     runc:
      Version:      1.0.0-rc8+dev
      GitCommit:            3e425f80a8c931f88e6d94a8c831b9d5aa481657
     docker-init:
      Version:      0.18.0
      GitCommit:            fec3683

    也可以使用docker查看支持id命令,如下:

    C:UsersAdministrator>docker
    
    Usage:  docker COMMAND
    
    A self-sufficient runtime for containers
    
    Options:
          --config string      Location of client config files (default
                               "C:\Users\Administrator\.docker")
      -D, --debug              Enable debug mode
      -H, --host list          Daemon socket(s) to connect to
      -l, --log-level string   Set the logging level
                               ("debug"|"info"|"warn"|"error"|"fatal")
                               (default "info")
          --tls                Use TLS; implied by --tlsverify
          --tlscacert string   Trust certs signed only by this CA (default
                               "C:\Users\Administrator\.docker\machine\machines\default\ca.pem")
          --tlscert string     Path to TLS certificate file (default
                               "C:\Users\Administrator\.docker\machine\machines\default\cert.pem")
          --tlskey string      Path to TLS key file (default
                               "C:\Users\Administrator\.docker\machine\machines\default\key.pem")
          --tlsverify          Use TLS and verify the remote (default true)
      -v, --version            Print version information and quit
    
    Management Commands:
      config      Manage Docker configs
      container   Manage containers
      image       Manage images
      network     Manage networks
      node        Manage Swarm nodes
      plugin      Manage plugins
      secret      Manage Docker secrets
      service     Manage services
      swarm       Manage Swarm
      system      Manage Docker
      trust       Manage trust on Docker images
      volume      Manage volumes
    
    Commands:
      attach      Attach local standard input, output, and error streams to a running container
      build       Build an image from a Dockerfile
      commit      Create a new image from a container's changes
      cp          Copy files/folders between a container and the local filesystem
      create      Create a new container
      diff        Inspect changes to files or directories on a container's filesystem
      events      Get real time events from the server
      exec        Run a command in a running container
      export      Export a container's filesystem as a tar archive
      history     Show the history of an image
      images      List images
      import      Import the contents from a tarball to create a filesystem image
      info        Display system-wide information
      inspect     Return low-level information on Docker objects
      kill        Kill one or more running containers
      load        Load an image from a tar archive or STDIN
      login       Log in to a Docker registry
      logout      Log out from a Docker registry
      logs        Fetch the logs of a container
      pause       Pause all processes within one or more containers
      port        List port mappings or a specific mapping for the container
      ps          List containers
      pull        Pull an image or a repository from a registry
      push        Push an image or a repository to a registry
      rename      Rename a container
      restart     Restart one or more containers
      rm          Remove one or more containers
      rmi         Remove one or more images
      run         Run a command in a new container
      save        Save one or more images to a tar archive (streamed to STDOUT by default)
      search      Search the Docker Hub for images
      start       Start one or more stopped containers
      stats       Display a live stream of container(s) resource usage statistics
      stop        Stop one or more running containers
      tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
      top         Display the running processes of a container
      unpause     Unpause all processes within one or more containers
      update      Update configuration of one or more containers
      version     Show the Docker version information
      wait        Block until one or more containers stop, then print their exit codes
    
    Run 'docker COMMAND --help' for more information on a command.

      到此docker安装成功。

    总结:

      再次查看docker官网的图标,如下:

    (1)镜像可以看做上面集装箱,仓库就是超级码头,容器就是我们运行程序的地方。docker运行程序的过程就是去仓库把镜像拉到(pull)本地,然后用一条命令把镜像运行(run)起来变成容器。

    (2)docker中有3个重要概念:

    build:构建,就是构建镜像.

    ship:运输,运输镜像,从仓库和主机运输.

    run:运行的镜像就是一个容器.

    build,ship,run和镜像,仓库,容器是一一对应的.

    补充:windows上面的docker是基于虚拟的linux环境的,所以每次启动都需要打开Oracle VM VirtualBox

    补充:windows镜像存在C盘,下载的镜像多了 之后会造成C盘内存不足。解决办法:

      默认情况下,docker-machine创建的虚拟机文件,是保存在C盘的C:Users用户名.dockermachinemachinesdefault 目录下的,如果下载和使用的镜像过多,那么必然导致该文件夹膨胀过大,如果C盘比较吃紧,那么我们就得考虑把该虚拟机移到另一个盘上

    (1)停止default虚拟机器

    $ docker-machine stop default
    Stopping "default"...
    Machine "default" was stopped.

    (2)打开VirtualBox,选择“管理”菜单下的“虚拟介质管理”,我们可以看到Docker虚拟机用的虚拟硬盘的文件disk。

    (3)选中“disk”,然后点击菜单中的“移动”命令,根据向导,把当前的disk移动到另一个盘上面去。

      移走只会可以看到C盘空间瞬间变大了。

    (4)选中default机器,然后设置-》存储可以查看disk的位置,如下:

    3.linux下离线安装docker

      centos78离线安装可以用docker 1.8或者1.91.81.9要求内核为3.10.0以上。如果内核是3.10.0以下,需要手动下载rpm包进行安装。

    (1)查看内核方式:

    [root@localhost ocrtemplate]# cat /proc/version 
    Linux version 2.6.32-696.el6.x86_64 (mockbuild@x86-027.build.eng.bos.redhat.com) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) ) #1 SMP Tue Feb 21 00:53:17 EST 2017

    或者:

    [root@localhost ocrtemplate]# uname -a
    Linux localhost.localdomain 2.6.32-696.el6.x86_64 #1 SMP Tue Feb 21 00:53:17 EST 2017 x86_64 x86_64 x86_64 GNU/Linux

    (2)查看发行版方式:

    [root@localhost ocrtemplate]# cat /etc/issue
    Red Hat Enterprise Linux Server release 6.9 (Santiago)
    Kernel 
     on an m

    或者:(只适用于redhat系列的linux)

    [root@f7744ac1467d /]# cat /etc/redhat-release
    CentOS Linux release 7.3.1611 (Core)

     

    ====centos78离线安装docker (内核在3.10.0以上)======

    1.准备文件

    下载gz包,https://download.docker.com/linux/static/stable/x86_64/ 

    2.上传到linux服务器进行解压安装

    1.解压

    docker-18.03.1-ce.tgz  zdtesseract.tar
    [root@localhost docker]# ls
    docker-18.03.1-ce.tgz  zdtesseract.tar
    [root@localhost docker]# tar -zxvf ./docker-18.03.1-ce.tgz 
    docker/
    docker/dockerd
    docker/docker-proxy
    docker/docker-containerd
    docker/docker-runc
    docker/docker-init
    docker/docker-containerd-shim
    docker/docker
    docker/docker-containerd-ctr

    2.将文件复制到 /usr/bin/

    cp docker/* /usr/bin/

    3.使用命令来开启docker守护进程:

    sudo dockerd &

      & 放在命令后面表示设置此进程为后台进程。默认情况下,进程是前台进程,这时此进程(命令执行相当于本质是开启一个进程)就把Shell给占据了,我们无法进行其他操作,对于那些没有交互的进程,很多时候,我们希望将其在后台启动,可以在启动参数的时候加一个'&'实现这个目的。
      出现下面证明dockerd启动成功,可以ctrl+c:

     4.查看docker版本:

    [root@localhost docker]# docker -v
    Docker version 18.03.1-ce, build 9ee9f40

    5.运行docker run hello-world (直接运行会查找镜像,不存在会自动下载)

    [root@localhost docker]# docker run hello-world
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    0e03bdcc26d7: Pull complete 
    Digest: sha256:6a65f928fb91fcfbc963f7aa6d57c8eeb426ad9a20c7ee045538ef34847f44f1
    Status: Downloaded newer image for hello-world:latest
    INFO[0240] shim docker-containerd-shim started           address="/containerd-shim/moby/49512a9df6f3d3fce6d954ce3fa99bf6dc9f368bb4bbafc714dd4f383a57a4d5/shim.sock" debug=false module="containerd/tasks" pid=6349
    
    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/
    
    INFO[0241] shim reaped                                   id=49512a9df6f3d3fce6d954ce3fa99bf6dc9f368bb4bbafc714dd4f383a57a4d5 module="containerd/tasks"
    INFO[2020-06-02T04:22:11.127666142-04:00] ignoring event                                module=libcontainerd namespace=moby topic=/tasks/delete type="*events.TaskDelete"

      上面亲测,centos8和7中可以安装。

     

      redhat6.9内核为3.10.0以下无法使用:

    [root@localhost docker]# cat /etc/redhat-release   #查看服务器版本
    Red Hat Enterprise Linux Server release 6.9 (Santiago)
    [root@localhost docker]# cat /proc/version   #查看内核版本
    Linux version 2.6.32-696.el6.x86_64 (mockbuild@x86-027.build.eng.bos.redhat.com) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) ) #1 SMP Tue Feb 21 00:53:17 EST 2017
    [root@localhost docker]# uname -a
    Linux localhost.localdomain 2.6.32-696.el6.x86_64 #1 SMP Tue Feb 21 00:53:17 EST 2017 x86_64 x86_64 x86_64 GNU/Linux

    ====redhat6.9安装docker(内核3.10.0以下)======

    1.依赖的rpm

     lxc-libs-1.0.9-1.el6.x86_64.rpm
     lua-alt-getopt-0.7.0-1.el6.noarch.rpm
     lua-filesystem-1.4.2-1.el6.x86_64.rpm
     lua-lxc-1.0.9-1.el6.x86_64.rpm  
     lxc-1.0.9-1.el6.x86_64.rpm  
     docker-io-1.7.1-2.el6.x86_64.rpm
    
     device-mapper-libs-1.02.117-12.el6.i686.rpm
     device-mapper-libs-1.02.117-12.el6.x86_64.rpm

    2.可以将依赖打成gz包,如下:

     3.将docker.tar.gz上传到服务器

    4. 解压

    tar -zxvf ./docker.tar.gz

    5.执行如下命令安装:

    rpm -ivh lxc-libs-1.0.9-1.el6.x86_64.rpm
    rpm -ivh lua-alt-getopt-0.7.0-1.el6.noarch.rpm
    rpm -ivh lua-filesystem-1.4.2-1.el6.x86_64.rpm
    rpm -ivh lua-lxc-1.0.9-1.el6.x86_64.rpm 
    rpm -ivh lxc-1.0.9-1.el6.x86_64.rpm 
    rpm -ivh docker-io-1.7.1-2.el6.x86_64.rpm
    
    rpm -ivh device-mapper-libs-1.02.117-12.el6.i686.rpm --force --nodeps
    rpm -ivh device-mapper-libs-1.02.117-12.el6.x86_64.rpm --force --nodeps

    6. 启动docker

    service docker start(用来生成cgroup隔离环境)
    docker -d &

    7. 测试

    [root@localhost ocrtemplate]# docker -v
    Docker version 1.7.1, build 786b29d/1.7.1
    [root@localhost ocrtemplate]# docker ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
  • 相关阅读:
    深入理解 JavaScript(五)
    深入理解 JavaScript(四)
    深入理解 JavaScript(三)
    opecv官网接口查询
    一个python-opencv博客
    Python中range和xrange的区别
    【转载】opencv 二值化函数——cv2.threshold
    python-opencv中的cv2.inRange函数
    anaconda conda install wxpython4 安装包 python3环境(GUI)
    python之assert
  • 原文地址:https://www.cnblogs.com/qlqwjy/p/12299411.html
Copyright © 2011-2022 走看看