美文网首页
Linux下Docker的安装及使用

Linux下Docker的安装及使用

作者: Tsnow308 | 来源:发表于2022-09-20 11:15 被阅读0次

    1.背景

    类似于电脑,要在朋友的电脑上跑你写的Java程序,就得检查他电脑有没有安装Java环境.

    类似的,要想在别的电脑上跑你写的Python程序,又得检查那台电脑有没有装python.

    如何让自己写的程序换到别的电脑上后,可以便捷的运行起来?

    将程序和程序的环境打包迁移,是一种解决方案.

    • 为啥不用虚拟机?

    虚拟机安装太麻烦,就好比一个完整的操作系统,启动起来很费时间.

    所以,你可以简单的理解为:Docker就是一个轻量级的虚拟机(只虚拟你需要的软件运行环境,冗余的一点都不要).

    • 网上看到的另一个Docker入门网站,还不错.

    https://docker.easydoc.net/

    2.安装

    服务器版本:CentOS 8.2 64位

    2.1 安装yum-utils

    <code-box id="5Jkf7F" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_1 mCS-autoHide" highlighted="true" id="pre-5Jkf7F" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-nYRwi2" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">yum install -y yum-utils</code-pre>

    </pre></code-box>

    2.2 yum配置阿里Docker源

    <code-box id="KDdcjB" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_2 mCS-autoHide" highlighted="true" id="pre-KDdcjB" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-6aTiBE" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo</code-pre>

    </pre></code-box>

    解决problem with installed package podman-1.6.4-10.的报错

    <code-box id="r7D6F2" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_3 mCS-autoHide" highlighted="true" id="pre-r7D6F2" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-8TbCZ3" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">yum erase podman buildah</code-pre>

    </pre></code-box>

    解决yum命令报错问题

    CentOS 8 EOL如何切换源?

    [图片上传失败...(image-7e83a5-1663643704610)]

    2.3 安装Docker

    <code-box id="XyBS3C" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_4 mCS-autoHide" highlighted="true" id="pre-XyBS3C" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-6ERPkZ" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);"># docker的三个组件: docker-ce、docker-ce-cli、containerd.io

    --nobest不只使用最佳选择的软件包 --skip-broken跳过无法安装的软件包

    yum install -y docker-ce docker-ce-cli containerd.io --nobest</code-pre>

    </pre></code-box>

    2.4 查看Docker版本

    <code-box id="GHQXhy" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_5 mCS-autoHide" highlighted="true" id="pre-GHQXhy" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-tNcEpj" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);"># 简单信息
    docker -v

    查看docker的版本号,包括客户端、服务端、依赖的Go等

    docker version

    查看系统(docker)层面信息,包括管理的images, containers数等

    docker info</code-pre>

    </pre></code-box>

    2.5 扩展

    1.为啥安装yum-utils?

    为了使用yum-config-manager命令, 执行--add-repo操作.

    2.添加阿里docker源干嘛?

    在最开始的时候,我们的yum仓库里的docker安装包是上面的几个,执行了yum源添加后,阿里带过来了新的docker安装包。

    [图片上传失败...(image-4253f4-1663643704610)]

    3.阿里镜像站

    阿里镜像站

    Docker-CE介绍

    01.png

    4.docker三个组件的区别

    containerd.io、docker-ce-cli、docker-ce的区别

    3.Docker服务相关

    3.1 启动

    <code-box id="wWcMhm" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_6 mCS-autoHide" highlighted="true" id="pre-wWcMhm" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-hTKaXn" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);"># 启动
    systemctl start docker

    开机自启

    systemctl enable docker

    禁用开机自启

    systemctl disable docker

    docker服务是否开机自启

    systemctl is-enabled docker

    已启动的服务列表

    systemctl list-unit-files|grep enabled</code-pre>

    </pre></code-box>

    3.2 停止

    <code-box id="JtanTr" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_7 mCS-autoHide" highlighted="true" id="pre-JtanTr" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-hCzh6T" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">systemctl stop docker</code-pre>

    </pre></code-box>

    3.3 重启

    <code-box id="bZJAaZ" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_8 mCS-autoHide" highlighted="true" id="pre-bZJAaZ" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-zrybGY" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">systemctl restart docker</code-pre>

    </pre></code-box>

    3.4 查看docker状态

    <code-box id="ndxF8K" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_9 mCS-autoHide" highlighted="true" id="pre-ndxF8K" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-W6fxQW" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">systemctl status docker</code-pre>

    </pre></code-box>

    4.Docker主要概念

    类比win

    镜像: 程序安装包

    容器: 安装好的程序

    (镜像的)仓库: 放安装包的仓库.

    4.1 仓库、镜像和容器

    • 镜像

      程序安装包

      Docker镜像里包含了已打包的应用程序及其所依赖的环境。它包含应用程序可用的文件系统和其他元数据,如镜像运行时的可执行文件路径。

    • 镜像仓库

      安装包的仓库

      Docker镜像仓库用于存放Docker镜像,以及促进不同人和不同电脑之间共享这些镜像。当编译镜像时,要么可以在编译它的电脑上运行,要么可以先上传镜像到一个镜像仓库,然后下载到另外一台电脑上并运行它。某些仓库是公开的,允许所有人从中拉取镜像,同时也有一些是私有的,仅部分人和机器可接入。

    • 容器

      安装好的软件

      Docker容器通常是一个Linux容器,它基于Docker镜像被创建。一个运行中的容器是一个运行在Docker主机上的进程,但它和主机,以及所有运行在主机上的其他进程都是隔离的。这个进程也是资源受限的,意味着它只能访问和使用分配给它的资源(CPU、内存等)。

    4.2 打包、分发和部署

    • 打包

      制作镜像

      把你软件本身、所需要的依赖、三方库等制作成一个"安装包"

    • 分发

      上传镜像仓库

      将安装包上传到软件仓库,别人可以方便的下载和安装

    • 部署

      启动镜像,获得运行着的容器.win开发好后.

      拿着下载好的安装包,用命令行运行起来(安装包中带着运行环境)

    4.3 一个简单的流程

    4.2.1 开发者在开发环境(本地机器)开发好应用后,制作出镜像。

    Docker执行命令,在本地机器构建出镜像并存储。

    4.2.2 开发者执行上传镜像命令,上传本地镜像到镜像仓库.

    Docker收到命令后,将本地镜像上传到镜像仓库。

    4.2.3 开发者向生产环境(远端服务器)发送运行镜像命令.

    生产环境服务器收到命令后,Docker会从镜像仓库拉取镜像,然后基于镜像运行容器。

    20210420095024.jpeg

    5.镜像相关

    类比win: 程序的安装包

    官方镜像仓库

    Docker镜像(image)详解

    5.1 查看镜像

    <code-box id="X2PBcr" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_10 mCS-autoHide" highlighted="true" id="pre-X2PBcr" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-ybrney" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker images</code-pre>

    </pre></code-box>

    5.2 搜索镜像

    <code-box id="mTyms4" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_11 mCS-autoHide" highlighted="true" id="pre-mTyms4" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-5hFw3d" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker search 镜像名称</code-pre>

    </pre></code-box>

    5.3 拉取镜像

    <code-box id="aKDzc8" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_12 mCS-autoHide" highlighted="true" id="pre-aKDzc8" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-yd6eXW" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker pull 镜像名称:版本号</code-pre>

    </pre></code-box>

    5.4 删除镜像

    <code-box id="X46AGC" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_13 mCS-autoHide" highlighted="true" id="pre-X46AGC" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-MM874w" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker rmi 镜像名称:版本号</code-pre>

    </pre></code-box>

    5.5 其他

    5.5.1 镜像信息

    <code-box id="dmNy2a" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_14 mCS-autoHide" highlighted="true" id="pre-dmNy2a" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-TM6Rm3" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">vim /var/lib/docker/image/overlay2/repositories.json</code-pre>

    </pre></code-box>

    [图片上传失败...(image-1a5d2d-1663643704609)]

    repositories.json文件中保存了一些基本信息

    [图片上传失败...(image-183c9b-1663643704609)]

    6.容器相关

    类比win: 已经安装好的程序

    6.1 查看容器列表

    <code-box id="sjfz7Y" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_15 mCS-autoHide" highlighted="true" id="pre-sjfz7Y" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-JER5xG" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);"># 查看正在运行的容器
    docker ps

    查看所有容器

    docker ps -a</code-pre>

    </pre></code-box>

    6.2 创建容器

    容器创建后,在容器列表中即可看到该容器(相当于安装好程序)

    以后用后文的启、停、删就可以操作该容器了.

    <code-box id="J87Y6P" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_16 mCS-autoHide" highlighted="true" id="pre-J87Y6P" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-n5JF5w" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);"># eg: \是换行的意思
    docker run -d -p 1337:1337
    --network kong-net
    --name konga
    -e "NODE_ENV=production"
    -e "DB_ADAPTER=postgres"
    -e "DB_URI=postgresql://kong:kong@172.0.0.1:5432/konga"
    pantsel/konga</code-pre>

    </pre></code-box>


    linux中-和--的区别?

    -后面一般跟简写,大多数是一个字母,如:

    <code-box id="2ApHdh" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_17 mCS-autoHide" highlighted="true" id="pre-2ApHdh" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-b8A2H8" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">ls -l</code-pre>

    </pre></code-box>

    --后面一般跟长的完整名字,如:

    <code-box id="tpzseK" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_18 mCS-autoHide" highlighted="true" id="pre-tpzseK" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-EdfSFz" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">chkconfig --add</code-pre>

    </pre></code-box>


    run参数

    • -rm

      在容器退出时自动清理容器内部的文件系统

      在Docker容器退出时,默认容器内部的文件系统仍然被保留,以方便调试并保留用户数据.

      但是,对于前台运行的容器,由于其只是在开发调试过程中短期运行,其用户数据并无保留的必要.

      启动时设置-rm选项,这样在容器退出时就能够自动清理容器内部的文件系统.

    • -i

      保持容器运行

    • -p

      端口映射

    • -e

      传递环境变量

    • -t

      为容器重新分配一个伪输入终端

    • -d

      以守护进程模式运行容器,退出后容器不会停止

    • -it

      创建一个交互式容器,推出后容器容器停止运行

    • -id

      创建一个守护容器;退出后容器不停止运行

    • –-name

      为创建的容器命名

    6.3 进入容器

    <code-box id="C8bwRe" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_19 mCS-autoHide" highlighted="true" id="pre-C8bwRe" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-7cRjhh" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker exec -it 容器名称 /bin/bash

    eg:进入一个叫konga的容器

    docker exec -it konga /bin/bash

    在容器中执行了一个ping命令

    ping 127.0.0.1

    退出当前容器

    exit</code-pre>

    </pre></code-box>

    6.4 启动容器

    <code-box id="ZwBccE" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_20 mCS-autoHide" highlighted="true" id="pre-ZwBccE" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-Gn8EEz" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker start 容器名称</code-pre>

    </pre></code-box>

    6.5 停止容器

    <code-box id="4whFZF" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_21 mCS-autoHide" highlighted="true" id="pre-4whFZF" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-kyrPX5" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker stop 容器名称</code-pre>

    </pre></code-box>

    6.6 删除容器

    <code-box id="icP7XA" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_22 mCS-autoHide" highlighted="true" id="pre-icP7XA" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-QwDTtc" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker rm 容器名称

    删除所有容器

    docker rm docker ps -aq</code-pre>

    </pre></code-box>

    6.7 查看容器详细信息

    inspect 视察、检查

    <code-box id="7xEX4m" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_23 mCS-autoHide" highlighted="true" id="pre-7xEX4m" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-mFDYTX" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker inspect 容器名称</code-pre>

    </pre></code-box>

    6.8 其他

    6.8.1 容器文件位置

    <code-box id="frNNH5" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_24 mCS-autoHide" highlighted="true" id="pre-frNNH5" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-Zh2ynt" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">cd /var/lib/docker/containers</code-pre>

    </pre></code-box>

    [图片上传失败...(image-c33118-1663643704607)]

    查看所有容器,其中的id:eb67258c80d1与上方文件夹对应

    <code-box id="WHmSs6" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_25 mCS-autoHide" highlighted="true" id="pre-WHmSs6" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-dXzpzw" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker ps -a

    显示

    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    eb67258c80d1 mongo "docker-entrypoint.s…" 7 days ago Exited (0) 6 days ago mongo</code-pre>

    </pre></code-box>

    6.8.2 从容器里拷贝文件(出来到)宿主机

    手动拷贝,后面可以使用-v命令直接挂载(映射)数据。

    <code-box id="TDmCm5" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_26 mCS-autoHide" highlighted="true" id="pre-TDmCm5" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-wCsWaQ" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker cp CONTAINERID:/path/file.type /home

    eg: 拷贝eb67258c80d1中的/home/test.txt到宿主机的/home文件夹下

    docker cp eb67258c80d1:/home/test.txt /home

    容器停止了也可以拷贝,只要容器还在,容器里面的文件就也还在.</code-pre>

    </pre></code-box>

    7.网络相关

    容器可以比拟做一个独立的系统环境,能配置自己网络,所以说容器里的localhost不一定等于宿主机的localhost

    网络模式

    • bridge:桥接docker(默认创建时,不指定网络驱动,将使用bridge模式)

    • none:不配置网络

    • host:和宿主机共享网络

      例如:当你在容器上使用80端口访问其他应用,使用的是宿主机的80端口.

    • container:容器网络连通(用的少,局限很大)

    Linux查看网络信息

    <code-box id="tQBa8m" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_27 mCS-autoHide" highlighted="true" id="pre-tQBa8m" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-66Ewwc" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);"># if没有打错.

    这里面能看到docker相关的网络.

    ifconfig</code-pre>

    </pre></code-box>

    7.1 查看docker下的网络列表

    <code-box id="mPsG4B" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_28 mCS-autoHide" highlighted="true" id="pre-mPsG4B" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-BexXN4" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker network ls</code-pre>

    </pre></code-box>

    7.2 查看单个网络详细信息

    <code-box id="ZnWcrC" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_29 mCS-autoHide" highlighted="true" id="pre-ZnWcrC" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-ZZQ7yb" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker network inspect networkname</code-pre>

    </pre></code-box>

    7.3 创建网络

    <code-box id="nTxz2z" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_30 mCS-autoHide" highlighted="true" id="pre-nTxz2z" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-zQdeWc" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);"># 不指定网络驱动时,默认创建的是bridge网络.
    docker network create networkname</code-pre>

    </pre></code-box>

    7.4 删除网络

    <code-box id="K2Hc2Y" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_31 mCS-autoHide" highlighted="true" id="pre-K2Hc2Y" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-SrktPd" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker network rm networkname</code-pre>

    </pre></code-box>

    8.日志相关

    <code-box id="JGJ5ep" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_32 mCS-autoHide" highlighted="true" id="pre-JGJ5ep" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-PMzAmS" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker logs [OPTIONS] CONTAINER

    Options参数

    --details: 显示更多的信息
    --follow(-f): 跟踪实时日志
    --since string: 显示自某个timestamp之后的日志,或相对时间,如40m(即40分钟)
    --tail string: 从日志末尾显示多少行日志, 默认是all
    --timestamps(-t): 显示时间戳
    --until string: 显示自某个timestamp之前的日志,或相对时间,如40m(即40分钟</code-pre>

    </pre></code-box>

    示例

    <code-box id="b5AYj4" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_33 mCS-autoHide" highlighted="true" id="pre-b5AYj4" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-MZc35e" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);"># 查看容器mysql 最近30分钟的日志:
    docker logs --since 30m mysql

    查看容器mysql 某时间之后的日志:

    docker logs -t --since="2019-11-02T13:23:37" mysql

    查看容器mysql 某时间段日志:

    docker logs -t --since="2019-11-02T13:23:37" --until "2019-11-03T12:23:37" mysql</code-pre>

    </pre></code-box>

    9.配置国内加速

    9.1 手动修改

    <code-box id="ytY4hH" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_34 mCS-autoHide" highlighted="true" id="pre-ytY4hH" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-hhYJ7H" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">vim /etc/docker/daemon.json

    加入镜像信息,注意不要有这行注释,json是不支持注释的,不然启动会报错

    {
    "registry-mirrors" : [
    "https://mirror.ccs.tencentyun.com",
    "http://registry.docker-cn.com",
    "http://docker.mirrors.ustc.edu.cn",
    "http://hub-mirror.c.163.com"
    ],
    "insecure-registries" : [
    "registry.docker-cn.com",
    "docker.mirrors.ustc.edu.cn"
    ],
    "debug" : true,
    "experimental" : true
    }</code-pre>

    </pre></code-box>

    重启docker

    <code-box id="PXjzB4" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_35 mCS-autoHide" highlighted="true" id="pre-PXjzB4" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-GK85Zd" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">systemctl restart docker.service</code-pre>

    </pre></code-box>

    镜像说明

    <code-box id="6MPfsk" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_36 mCS-autoHide" highlighted="true" id="pre-6MPfsk" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-Nxkmzt" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">"https://mirror.ccs.tencentyun.com" //腾讯
    "http://registry.docker-cn.com" //docker官方提供的中国镜像
    "http://docker.mirrors.ustc.edu.cn" //中国科学技术大学
    "http://hub-mirror.c.163.com" //网易</code-pre>

    </pre></code-box>

    9.2 DaoCloud镜像站

    帮助文档

    Linux

    <code-box id="x7iFYM" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_37 mCS-autoHide" highlighted="true" id="pre-x7iFYM" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">

    <code-pre class="code-pre code-pre-line" id="pre-fcSMKW" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);"># 下载sh脚本 手动下载浏览器访问: https://get.daocloud.io/daotools/set_mirror.sh</code-pre>

    </pre></code-box>

    相关文章

      网友评论

          本文标题:Linux下Docker的安装及使用

          本文链接:https://www.haomeiwen.com/subject/tuamortx.html