Docker的基本安装HelloWorld

1、引擎的安装

Docker分为Client与Enginer两端,可以类比Mysql,一个服务端程序一个控制台程序

以CentOS为例,Enginer的安装分为以下步骤

  1. 卸载原有的版本:
    $ sudo yum remove docker \
                     docker-client \
                     docker-client-latest \
                     docker-common \
                     docker-latest \
                     docker-latest-logrotate \
                     docker-logrotate \
                     docker-engine
    
  2. 设置Docker仓库
    $ sudo yum install -y yum-utils
    # 使用阿里云国内镜像
    $ sudo yum-config-manager \
       --add-repo \
       https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    
    
  3. 安装Docker引擎、控制台
    $ sudo yum install docker-ce docker-ce-cli containerd.io
    
  4. 启动Docker服务
    $ sudo systemctl start docker
    
  5. 安装完毕,查看docker版本及相关信息
    $ docker version
    Client: Docker Engine - Community
    Version:           20.10.2
    API version:       1.41
    Go version:        go1.13.15
    Git commit:        2291f61
    Built:             Mon Dec 28 16:17:40 2020
    OS/Arch:           linux/amd64
    Context:           default
    Experimental:      true
    
    Server: Docker Engine - Community
    Engine:
     Version:          20.10.2
     API version:      1.41 (minimum version 1.12)
     Go version:       go1.13.15
     Git commit:       8891c58
     Built:            Mon Dec 28 16:15:09 2020
     OS/Arch:          linux/amd64
     Experimental:     false
    containerd:
     Version:          1.4.3
     GitCommit:        269548fa27e0089a8b8278fc4fc781d7f65a939b
    runc:
     Version:          1.0.0-rc92
     GitCommit:        ff819c7e9184c13b7c2607fe6c30ae19403a7aff
    docker-init:
     Version:          0.19.0
     GitCommit:        de40ad0
    

2、镜像下载与安装

  1. 官方给了以下图来说明整个Docker体系,分为客户端、主机、仓库

Docker Architecture Diagram

  • 客户端用于对整个Docker进行操作,类似Mysql的,可以是命令行终端,也可以是可视化界面;
  • 主机由Docker的守护进程(daemon)统一管理,管理的对象有容器、镜像、或与其他服务器的守护进程通信或协作,镜像与容器可以类比于类与对象的关系,通过镜像可以创建多个容器,容器是实例;
  • 仓库主要用于存储镜像,类似于Github这种代码仓库,思想是一样的。
  1. 官方还提供了一个hello-world的demo镜像,可以体验一下:

    搜索仓库中的镜像

    $ docker search hello-world
    NAME                                       DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
    hello-world                                Hello World! (an example of minimal Dockeriz…   1371      [OK]       
    kitematic/hello-world-nginx                A light-weight nginx container that demonstr…   148                  
    tutum/hello-world                          Image to test docker deployments. Has Apache…   77                   [OK]
    dockercloud/hello-world                    Hello World!                                    19                   [OK]
    crccheck/hello-world                       Hello World web server in under 2.5 MB          14                   [OK]
    vad1mo/hello-world-rest                    A simple REST Service that echoes back all t…   4                    [OK]
    ppc64le/hello-world                        Hello World! (an example of minimal Dockeriz…   2                    
    ansibleplaybookbundle/hello-world-db-apb   An APB which deploys a sample Hello World! a…   1                    [OK]
    ansibleplaybookbundle/hello-world-apb      An APB which deploys a sample Hello World! a…   1                    [OK]
    markmnei/hello-world-java-docker           Hello-World-Java-docker                         1                    [OK]
    souravpatnaik/hello-world-go               hello-world in Golang                           1                    
    rancher/hello-world                                                                        1                    
    datawire/hello-world                       Hello World! Simple Hello World implementati…   1                    [OK]
    strimzi/hello-world-consumer                                                               0                    
    strimzi/hello-world-streams                                                                0                    
    koudaiii/hello-world                                                                       0                    
    strimzi/hello-world-producer                                                               0                    
    burdz/hello-world-k8s                      To provide a simple webserver that can have …   0                    [OK]
    businessgeeks00/hello-world-nodejs                                                         0                    
    freddiedevops/hello-world-spring-boot                                                      0                    
    infrastructureascode/hello-world           A tiny "Hello World" web server with a healt…   0                    [OK]
    airwavetechio/hello-world                                                                  0                    
    kevindockercompany/hello-world                                                             0                    
    nirmata/hello-world                                                                        0                    [OK]
    okteto/hello-world  
    

    拉取镜像到本地,类似git的pull操作

    $ docker pull hello-world
    Using default tag: latest
    latest: Pulling from library/hello-world
    0e03bdcc26d7: Pull complete 
    Digest: sha256:31b9c7d48790f0d8c50ab433d9c3b7e17666d6993084c002c2ff1ca09b96391d
    Status: Downloaded newer image for hello-world:latest
    docker.io/library/hello-world:latest
    

    启动镜像

    $ docker run hello-world
    
    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/
    
  2. 到此为止,Docker的基本安装就已全部结束

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注