yyz notes yyz notes
首页
  • RBAC权限设计
  • 架构图标设计
  • 账号体系
  • python基础
  • python高级
  • python模块
  • python设计模式
  • python数据结构与算法
  • django
  • django-DRF
  • flask
  • 直接设计开源pip包
  • 直接设计开源项目
  • python示例题/脚本
  • python面试题
  • golang基础
  • golang高级
  • golang常用组件
  • gin框架
  • es6
  • javascript
  • react
  • vue
  • TypeScript
  • mysql
  • redis
  • minio
  • elasticsearch
  • mongodb
  • 消息队列
  • 自动化测试
  • 操作系统

    • linux
    • windows
  • nginx
  • docker
  • k8s
  • git
  • ldap
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

益章

可乐鸡翅
首页
  • RBAC权限设计
  • 架构图标设计
  • 账号体系
  • python基础
  • python高级
  • python模块
  • python设计模式
  • python数据结构与算法
  • django
  • django-DRF
  • flask
  • 直接设计开源pip包
  • 直接设计开源项目
  • python示例题/脚本
  • python面试题
  • golang基础
  • golang高级
  • golang常用组件
  • gin框架
  • es6
  • javascript
  • react
  • vue
  • TypeScript
  • mysql
  • redis
  • minio
  • elasticsearch
  • mongodb
  • 消息队列
  • 自动化测试
  • 操作系统

    • linux
    • windows
  • nginx
  • docker
  • k8s
  • git
  • ldap
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • k8s

  • 操作系统

  • nginx

  • docker

    • docker基础
      • Docker 安装 MongoDB
      • win安装docker
      • 容器制作成基础镜像方式
    • 运维部署
    • docker
    YiZhang-You
    2023-05-24
    目录
    相关资料
    _1、docker介绍_
    1.1 _docker三大概念_
    _2、安装_
    _2.1 官方安装_
    _2.2 标准安装_
    _3、docker基础命令注释_
    _4、镜像images_
    _4.1 列出所有镜像_
    _4.2 查找镜像_
    _4.3 拖取镜像_
    _4.4 删除镜像_
    _4.5 创建镜像-获取镜像_
    _1、更新镜像-创建自定义镜像_

    docker基础

    # docker基础

    # 相关资料

    博客园:https://www.cnblogs.com/pyyu/tag/docker/
    菜鸟教程:https://www.runoob.com/docker/docker-tutorial.html
    c语言中文网:http://c.biancheng.net/view/3121.html
    菜鸟教程信息:https://www.runoob.com/docker/docker-container-connection.html
    docker官方文档:https://yeasy.gitbook.io/docker_practice/repository/registry
    
    1
    2
    3
    4
    5

    # 1、docker介绍

    https://www.cnblogs.com/pyyu/p/9485268.html
    
    1

    # 1.1 docker三大概念

    容器三大基本概念
    镜像 image
    容器 container
        隔离的进程独立与宿主机和其他隔离的进程,也被称之为容器。
    仓库 repository
    docker整个生命周期就是这三个概念。
    
    1
    2
    3
    4
    5
    6

    docker可以实现开发、测试和生产环境的统一化和标准化。

    程序员,在代码写好之后,还会开发dockerfile脚本,完成之后就是,将代码和环境依赖,全部打包为一个镜像文件(docker image),有了docker之后,只需要将程序打包为镜像,就可以发给其他机器,其他机器只需要运行该镜像,这个程序就快压直接运行
    
    1

    docker组件介绍

    • image镜像,构建容器(我们讲应用程序运行所需的环境,打包为镜像文件)

    • Container,容器(你的应用程序,就跑在容器中)

    • 镜像仓库(dockerhub)(保存镜像文件,提供上传,下载镜像)作用好比github

    • dockerfile,将你部署项目的操作,写成一个脚本,这就是dockerfile,且该脚本还能够构建出镜像文件

    # 2、安装

    看需求选择那个安装

    # 2.1 官方安装

    https://docs.docker.com/install/linux/docker-ce/centos/#upgrade-docker-after-using-the-convenience-script (opens new window)

    1.卸载旧版本
    sudo yum remove docker \
                      docker-client \
                      docker-client-latest \
                      docker-common \
                      docker-latest \
                      docker-latest-logrotate \
                      docker-logrotate \
                      docker-selinux \
                      docker-engine-selinux \
                      docker-engine
    
    2.设置存储库
    sudo yum install -y yum-utils \
      device-mapper-persistent-data \
      lvm2
    
    sudo yum-config-manager \
        --add-repo \
        https://download.docker.com/linux/centos/docker-ce.repo
    
    3.安装docker社区版
    sudo yum install docker-ce
    4.启动关闭docker
    systemctl start docker
    5.配置镜像源(参照2.2)
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26

    # 2.2 标准安装

    centos7安装docker

    1、查看linux发行版,内核

    [root@docker~]# cat /etc/redhat-release  #查看版本号
    CentOS Linux release 7.1.1503 (Core)
    [root@docker ~]# uname -r  #查看Linux内核
    c3.10.0-229.el7.x86_64
    
    1
    2
    3
    4

    2、替换阿里云yum源

    第一步: wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo #下载阿里yum源2
    
    第二步: yum makecache  #生成仓库缓存
    
    1
    2
    3

    3、安装docker

    yum install docker -y
    
    1

    4、启动docker

    systemctl start docker  #启动docker
    systemctl enable docker #开机启动docker
    systemctl status docker #查看docker状态
    
    1
    2
    3

    5、查看docker 版本

    docker version
    # 出现客户端和服务端信息就表示安装成功
    
    1
    2

    6、docker加速器

    DaoCloud 加速器 是广受欢迎的 Docker 工具,解决了国内用户访问 Docker Hub 缓慢的问题。DaoCloud 加速器结合国内的 CDN 服务与协议层优化,成倍的提升了下载速度。

    使用前请先确保您的 Docker 版本在 1.8 或更高版本,否则无法使用加速。

    http://guide.daocloud.io/dcs/daocloud-9153151.html (opens new window) 教程官网

     # 方法一
     cat /etc/docker/daemon.json
    {
     "registry-mirrors": ["https://registry.docker-cn.com"]
    }
    
    # 方法二:或者用这条命令
    curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://95822026.m.daocloud.io
    
    #事后重启docker
    systemctl restart docker
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11

    # 3、docker基础命令注释

    [root@docker ~]# docker --help
    Options:
      --config=~/.docker              Location of client config files  #客户端配置文件的位置
      -D, --debug=false               Enable debug mode  #启用Debug调试模式
      -H, --host=[]                   Daemon socket(s) to connect to  #守护进程的套接字(Socket)连接
      -h, --help=false                Print usage  #打印使用
      -l, --log-level=info            Set the logging level  #设置日志级别
      --tls=false                     Use TLS; implied by--tlsverify  #
      --tlscacert=~/.docker/ca.pem    Trust certs signed only by this CA  #信任证书签名CA
      --tlscert=~/.docker/cert.pem    Path to TLS certificate file  #TLS证书文件路径
      --tlskey=~/.docker/key.pem      Path to TLS key file  #TLS密钥文件路径
      --tlsverify=false               Use TLS and verify the remote  #使用TLS验证远程
      -v, --version=false             Print version information and quit  #打印版本信息并退出
    Commands:
        attach    Attach to a running container  #当前shell下attach连接指定运行镜像
        build     Build an image from a Dockerfile  #通过Dockerfile定制镜像
        commit    Create a new image from a container's changes  #提交当前容器为新的镜像
        cp    Copy files/folders from a container to a HOSTDIR or to STDOUT  #从容器中拷贝指定文件或者目录到宿主机中
        create    Create a new container  #创建一个新的容器,同run 但不启动容器
        diff    Inspect changes on a container's filesystem  #查看docker容器变化
        events    Get real time events from the server#从docker服务获取容器实时事件
        exec    Run a command in a running container#在已存在的容器上运行命令
        export    Export a container's filesystem as a tar archive  #导出容器的内容流作为一个tar归档文件(对应import)
        history    Show the history of an image  #展示一个镜像形成历史
        images    List images  #列出系统当前镜像
        import    Import the contents from a tarball to create a filesystem image  #从tar包中的内容创建一个新的文件系统映像(对应export)
        info    Display system-wide information  #显示系统相关信息
        inspect    Return low-level information on a container or image  #查看容器详细信息
        kill    Kill a running container  #kill指定docker容器
        load    Load an image from a tar archive or STDIN  #从一个tar包中加载一个镜像(对应save)
        login    Register or log in to a Docker registry#注册或者登陆一个docker源服务器
        logout    Log out from a Docker registry  #从当前Docker registry退出
        logs    Fetch the logs of a container  #输出当前容器日志信息
        pause    Pause all processes within a container#暂停容器
        port    List port mappings or a specific mapping for the CONTAINER  #查看映射端口对应的容器内部源端口
        ps    List containers  #列出容器列表
        pull    Pull an image or a repository from a registry  #从docker镜像源服务器拉取指定镜像或者库镜像
        push    Push an image or a repository to a registry  #推送指定镜像或者库镜像至docker源服务器
        rename    Rename a container  #重命名容器
        restart    Restart a running container  #重启运行的容器
        rm    Remove one or more containers  #移除一个或者多个容器
        rmi    Remove one or more images  #移除一个或多个镜像(无容器使用该镜像才可以删除,否则需要删除相关容器才可以继续或者-f强制删除)
        run    Run a command in a new container  #创建一个新的容器并运行一个命令
        save    Save an image(s) to a tar archive#保存一个镜像为一个tar包(对应load)
        search    Search the Docker Hub for images  #在dockerhub中搜索镜像
        start    Start one or more stopped containers#启动容器
        stats    Display a live stream of container(s) resource usage statistics  #统计容器使用资源
        stop    Stop a running container  #停止容器
        tag         Tag an image into a repository  #给源中镜像打标签
        top       Display the running processes of a container #查看容器中运行的进程信息
        unpause    Unpause all processes within a container  #取消暂停容器
        version    Show the Docker version information#查看容器版本号
        wait         Block until a container stops, then print its exit code  #截取容器停止时的退出状态值
    Run 'docker COMMAND --help' for more information on a command.  #运行docker命令在帮助可以获取更多信息
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54

    # 4、镜像images

    菜鸟:https://www.runoob.com/docker/docker-image-usage.html
    
    1

    # 4.1 列出所有镜像

    查看当前所有的docker镜像

    docker image ls
    docker images    # 查看当前所有的docker镜像
    
    1
    2

    # 4.2 查找镜像

    我们可以从 Docker Hub 网站来搜索镜像,Docker Hub 网址为: https://hub.docker.com/ (opens new window)

    docker search 镜像名字  # 其实就是去docker hub搜索镜像名
    
    docker search hello-world  # 搜索docker镜像
    
    NAME: 镜像仓库源的名称
    DESCRIPTION: 镜像的描述
    OFFICIAL: 是否 docker 官方发布
    stars: 类似 Github 里面的 star,表示点赞、喜欢的意思。
    AUTOMATED: 自动构建。
    
    1
    2
    3
    4
    5
    6
    7
    8
    9

    # 4.3 拖取镜像

    我们决定使用官方版本的镜像,使用命令 docker pull 来下载镜像。

    docker pull 镜像名称
    
    docker pull hello-world  # 下载docker镜像
    
    1
    2
    3

    # 4.4 删除镜像

    镜像删除使用 docker rmi 命令,比如我们删除 hello-world 镜像:

    docker rmi 镜像名/镜像id		 # 删除docker镜像(该镜像未运行)
    
    docker rmi hello-world		# 删除 hello-world 镜像
    docker rmi `docker images`  # !删除多个
    
    1
    2
    3
    4

    # 4.5 创建镜像-获取镜像

    当我们从 docker 镜像仓库中下载的镜像不能满足我们的需求时,我们可以通过以下两种方式对镜像进行更改。

    • 1、从已经创建的容器中更新镜像,并且提交这个镜像

    • 2、使用 Dockerfile 指令来创建一个新的镜像

    • 3、导入的形式,把别人打包好的镜像使用导入docker import 导入到自己的镜像中

    # 1、更新镜像-创建自定义镜像

    从已经创建的容器中更新镜像,并且提交这个镜像

    更新镜像之前,我们需要使用镜像来创建一个容器。

    docker run -t -i ubuntu:15.10 /bin/bash    # 运行进行以shell模式
    
    root@e218edb10161:/#
    
    1
    2
    3

    在运行的容器内使用 apt-get update 命令进行更新。

    在完成操作之后,输入 exit 命令来退出这个容器。

    此时 ID 为 e218edb10161 的容器,是按我们的需求更改的容器。我们可以通过命令 docker commit 来提交容器副本。

    docker commit -m="描述信息" -a="yyz" e218edb10161 ubuntu:v2
    sha256:70bf1840fd7c0d2d8ef0a42a817eb29f854c1af8f7c59fc03ac7bdee9545aff8
    
    1
    2

    各个参数说明:

    • m: 提交的描述信息

    • a: 指定镜像作者

    • e218edb10161:容器 ID

    • ubuntu:v2: 指定要创建的目标镜像名

    编辑 (opens new window)
    nginx代码kibana方法
    Docker 安装 MongoDB

    ← nginx代码kibana方法 Docker 安装 MongoDB→

    最近更新
    01
    配置yun源
    05-24
    02
    linux-配置python虚拟环境
    05-24
    03
    linux文件目录管理
    05-24
    更多文章>
    Theme by Vdoing | Copyright © 2023-2025 yizhang | MIT License
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式