• Docker-简介,安装,测试


    1:什么是Docker

    在这里插入图片描述

    Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从 Apache2.0 协议开源。 Docker
    可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。
    容器是完全使用沙箱机制,相互之间不会有任何接口,更重要的是容器性能开销极低。

    Docker能干什么?

    1. Web 应用的自动化打包和发布。
    2. 自动化测试和持续集成、发布。
    3. 在服务型环境中部署和调整数据库或其他的后台应用。
    4. 从头编译或者扩展现有的 OpenShift 或 Cloud Foundry 平台来搭建自己的 PaaS 环境。

    2:镜像,容器,仓库

    在这里插入图片描述

    镜像:一个只读的模板,可以通过这个模板创建容器服务,一个镜像可以创建多个容器(最终服务运行或者项目运行就是在容器中)
    容器:

    • 容器是对进程进行封装隔离,属于操作系统层面的虚拟化技术。由于隔离的进程独立于宿主和其它的隔离的进程
    • 一个容器包括了完整的运行时环境:除了应用程序本身之外,还有这个应用程序所需的全部依赖、类库、其他二进制文件、配置文件等
    • 将应用程序本身和其依赖容器化,使其运行的环境和操作系统的基础环境造成的差异都被抽象掉
      仓库:集中存放镜像文件的场所。Docker用Registry来保存用户构建的镜像。Registry分为公有和私有两种

    3:安装Docker

    卸载之前的Dokcer:

    yum remove docker \
                      docker-client \
                      docker-client-latest \
                      docker-common \
                      docker-latest \
                      docker-latest-logrotate \
                      docker-logrotate \
                      docker-engine
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    安装Docker软件包:

    yum install -y yum-utils
    
    • 1

    使用阿里云镜像:

    yum-config-manager \
        --add-repo \
        http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    
    • 1
    • 2
    • 3

    安装DockerEngine和容器:

    yum makecache fast
    yum install docker-ce docker-ce-cli containerd.io
    
    • 1
    • 2

    启动Docker:

    systemctl start docker
    docker version#查看版本
    
    • 1
    • 2

    配置aliyun镜像(在/etc/docker下新建daemon.json文件):

    vi daemon.json
    #添加以下内容
    {
      "registry-mirrors": ["https://z117ufx7.mirror.aliyuncs.com"]
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5

    4:测试

    查看镜像:

    docker images
    
    • 1

    拉取hello-world镜像:

    docker pull hello-world
    
    • 1

    再次查看镜像:

    docker images
    #输入命令后应该有如下内容
    REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
    hello-world   latest    feb5d9fea6a5   9 months ago   13.3kB
    
    • 1
    • 2
    • 3
    • 4

    运行hello-world镜像:

    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/
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    查看容器:

    #因为hello-world镜像运行后会停止,所以需要-a参数才能查看所有的镜像
    docker ps -a 
    #执行命令后应该有如下内容
    CONTAINER ID   IMAGE         COMMAND    CREATED              STATUS                          PORTS     NAMES
    9df5d2e8d1fd   hello-world   "/hello"   About a minute ago   Exited (0) About a minute ago             condescending_cray
    
    • 1
    • 2
    • 3
    • 4
    • 5

    删除容器和镜像:

    #删除容器
    docker rm 9df5d2e8d1fd(此次填写docker ps -a查询到的CONTAINER ID的值)
    #删除镜像
    docker rmi hello-world:latest 
    
    • 1
    • 2
    • 3
    • 4
    1. 容器未停止需要-f参数强制删除
    2. 如果镜像有对应的容器,需要删除容器后再删除镜像
  • 相关阅读:
    网络安全(黑客)自学
    常回家看看之house_of_cat
    状态管理dva:Generator函数
    数据传输POST心法分享,做前端的你还解决不了这个bug?
    【Android】性能监控之帧率检测Tinydancer
    网络安全(黑客)自学
    ChatGPT WPS AI 一键核对两表数据差异
    MYSQL多表联查on和where的区别
    C#使用 AutoUpdater.NET 实现程序自动更新
    tictoc例子理解
  • 原文地址:https://blog.csdn.net/hd_cash/article/details/125629975