Files
iot-dc3/docs/tip/docker-compose.html
T
2023-04-14 00:38:49 +08:00

86 lines
28 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
/>
<title>Docker Compose | IoT DC3</title>
<meta name="description" content="" />
<meta name="generator" content="VuePress 1.9.9" />
<link rel="icon" href="/assets/images/favicon.ico">
<script type="text/javascript" src="/assets/js/push.js"></script> <meta name="description" content="DC3是一个基于Spring Cloud的开源的、分布式的物联网(IOT)平台,用于快速开发物联网项目和管理物联设备,是一整套物联系统解决方案。">
<meta name="referrer" content="never">
<meta name="keywords" content="iot,dc3,DC3,iotdc3,iot dc3,IOTDC3,IoTDC3,IOT DC3,IoT DC3,物联网,开源,分布式,物联网平台,IOT平台"> <link rel="preload" href="/assets/css/0.styles.116dcc83.css" as="style"><link rel="preload" href="/assets/js/app.7dfefe51.js" as="script"><link rel="preload" href="/assets/js/2.a8b8915e.js" as="script"><link rel="preload" href="/assets/js/47.dc2d8aff.js" as="script"><link rel="prefetch" href="/assets/js/10.db658154.js"><link rel="prefetch" href="/assets/js/11.287152fd.js"><link rel="prefetch" href="/assets/js/12.08136beb.js"><link rel="prefetch" href="/assets/js/13.83b3d580.js"><link rel="prefetch" href="/assets/js/14.d5387cec.js"><link rel="prefetch" href="/assets/js/15.aafb2a89.js"><link rel="prefetch" href="/assets/js/16.01fcc650.js"><link rel="prefetch" href="/assets/js/17.a097fd52.js"><link rel="prefetch" href="/assets/js/18.acd93e71.js"><link rel="prefetch" href="/assets/js/19.6f12b224.js"><link rel="prefetch" href="/assets/js/20.bac69ff1.js"><link rel="prefetch" href="/assets/js/21.9105165e.js"><link rel="prefetch" href="/assets/js/22.de1f017c.js"><link rel="prefetch" href="/assets/js/23.fb20a8f5.js"><link rel="prefetch" href="/assets/js/24.6459dc88.js"><link rel="prefetch" href="/assets/js/25.0587cb23.js"><link rel="prefetch" href="/assets/js/26.b6254386.js"><link rel="prefetch" href="/assets/js/27.479148c7.js"><link rel="prefetch" href="/assets/js/28.da247a59.js"><link rel="prefetch" href="/assets/js/29.f175dd67.js"><link rel="prefetch" href="/assets/js/3.8e04da2b.js"><link rel="prefetch" href="/assets/js/30.5ba7a495.js"><link rel="prefetch" href="/assets/js/31.01c3d218.js"><link rel="prefetch" href="/assets/js/32.de0e0ff7.js"><link rel="prefetch" href="/assets/js/33.0e117d4a.js"><link rel="prefetch" href="/assets/js/34.010094c5.js"><link rel="prefetch" href="/assets/js/35.8a377a71.js"><link rel="prefetch" href="/assets/js/36.fbb64a47.js"><link rel="prefetch" href="/assets/js/37.c2b9d4da.js"><link rel="prefetch" href="/assets/js/38.a66be625.js"><link rel="prefetch" href="/assets/js/39.76e387bc.js"><link rel="prefetch" href="/assets/js/4.470d098a.js"><link rel="prefetch" href="/assets/js/40.0e9ee726.js"><link rel="prefetch" href="/assets/js/41.e68f3c2e.js"><link rel="prefetch" href="/assets/js/42.ba03ba76.js"><link rel="prefetch" href="/assets/js/43.e6a91a35.js"><link rel="prefetch" href="/assets/js/44.9304b041.js"><link rel="prefetch" href="/assets/js/45.586518cf.js"><link rel="prefetch" href="/assets/js/46.ab599c67.js"><link rel="prefetch" href="/assets/js/48.06e9c64e.js"><link rel="prefetch" href="/assets/js/49.627cc127.js"><link rel="prefetch" href="/assets/js/5.0f4aedb8.js"><link rel="prefetch" href="/assets/js/50.bf665f72.js"><link rel="prefetch" href="/assets/js/51.08e5dea0.js"><link rel="prefetch" href="/assets/js/52.8e37a9c4.js"><link rel="prefetch" href="/assets/js/53.8c472224.js"><link rel="prefetch" href="/assets/js/54.bb582a52.js"><link rel="prefetch" href="/assets/js/55.640d9ecb.js"><link rel="prefetch" href="/assets/js/56.e2e2a21e.js"><link rel="prefetch" href="/assets/js/57.9b9b26a7.js"><link rel="prefetch" href="/assets/js/58.0d4a46c3.js"><link rel="prefetch" href="/assets/js/59.d1f11d32.js"><link rel="prefetch" href="/assets/js/6.547754b6.js"><link rel="prefetch" href="/assets/js/7.aea1a047.js"><link rel="prefetch" href="/assets/js/8.f35f3888.js"><link rel="prefetch" href="/assets/js/9.3f13bdbf.js"> <link rel="stylesheet" href="/assets/css/0.styles.116dcc83.css">
</head>
<body>
<div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="ant-row"><div class="nav-button"><i aria-label="icon: bars" class="anticon anticon-bars"><svg viewBox="0 0 1024 1024" focusable="false" data-icon="bars" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M912 192H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 284H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 284H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM104 228a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm0 284a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm0 284a56 56 0 1 0 112 0 56 56 0 1 0-112 0z"></path></svg></i> <span></span></div> <div class="ant-col ant-col-xs-24 ant-col-sm-24 ant-col-md-6 ant-col-lg-6 ant-col-xl-5 ant-col-xxl-4"><a href="/" class="router-link-active home-link"><img src="/assets/images/logo.png" alt="IoT DC3" class="logo"> <span class="site-name">IoT DC3</span></a> <div class="search-box mobile-search"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div></div> <div class="nav-space-between ant-col ant-col-xs-0 ant-col-sm-0 ant-col-md-18 ant-col-lg-18 ant-col-xl-19 ant-col-xxl-20"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><ul role="menu" id="nav" class="ant-menu ant-menu-horizontal ant-menu-root ant-menu-light"><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/" class="router-link-active">
首页
</a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/docs/" class="router-link-active">
指南
</a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/config/">
配置
</a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-item"><a href="/faq/">
FAQ
</a></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="display:none;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>
代码仓库
</span><i class="ant-menu-submenu-arrow"></i></div></li><li role="menuitem" class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" style="visibility:hidden;position:absolute;"><div aria-haspopup="true" class="ant-menu-submenu-title"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li></ul> <ul class="extra-group"><!----> <!----></ul></nav></div></div> <!----></header> <aside class="sidebar"><!----> <ul class="sidebar-links"><li><a href="/docs/" aria-current="page" title="简介" class="sidebar-link">简介</a></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>开发指南</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/docs/code/0-environment.html" title="注意事项" class="sidebar-link">注意事项</a></li><li><a href="/docs/code/1-idea-start.html" title="必要软件环境" class="sidebar-link">必要软件环境</a></li><li><a href="/docs/code/2-web-ui.html" title="构建 IoT DC3 Web UI" class="sidebar-link">构建 IoT DC3 Web UI</a></li><li><a href="/docs/code/3-quick-start.html" title="快速启动" class="sidebar-link">快速启动</a></li><li><a href="/docs/code/4-start.html" title="🚀最佳实践" class="sidebar-link">🚀最佳实践</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>操作手册</span> <span class="arrow right"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>功能说明</span> <span class="arrow right"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>驱动使用说明</span> <span class="arrow right"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>相关文档</span> <span class="arrow down"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/docs/tip/centos-create-user.html" title="创建新用户" class="sidebar-link">创建新用户</a></li><li><a href="/docs/tip/centos-install-gnome.html" title="查询 yum group" class="sidebar-link">查询 yum group</a></li><li><a href="/docs/tip/centos-install-kvm.html" title="检测是否支持 KVM" class="sidebar-link">检测是否支持 KVM</a></li><li><a href="/docs/tip/centos-install-pip.html" title="检测是否安装 pip" class="sidebar-link">检测是否安装 pip</a></li><li><a href="/docs/tip/centos-install-vnc.html" title="安装 VNC Server" class="sidebar-link">安装 VNC Server</a></li><li><a href="/docs/tip/docker-compose.html" aria-current="page" title="Docker Compose" class="active sidebar-link">Docker Compose</a></li><li><a href="/docs/tip/ffmpeg.html" title="视频剪切" class="sidebar-link">视频剪切</a></li><li><a href="/docs/tip/http-code.html" title="HTTP 状态码" class="sidebar-link">HTTP 状态码</a></li><li><a href="/docs/tip/install-centos7.html" title="1.安装UltraISO" class="sidebar-link">1.安装UltraISO</a></li><li><a href="/docs/tip/iptables.html" title="屏蔽某个 IP" class="sidebar-link">屏蔽某个 IP</a></li><li><a href="/docs/tip/nginx-prefix.html" title="Location 语法" class="sidebar-link">Location 语法</a></li><li><a href="/docs/tip/nginx-rtmp.html" title="开发环境" class="sidebar-link">开发环境</a></li><li><a href="/docs/tip/nodejs-upgrade.html" title="卸载&amp;重新安装nodejs" class="sidebar-link">卸载&amp;重新安装nodejs</a></li><li><a href="/docs/tip/nohup.html" title="只输出错误信息到日志文件" class="sidebar-link">只输出错误信息到日志文件</a></li><li><a href="/docs/tip/string-format.html" title="String.format()字符串常规类型格式化的两种重载方式" class="sidebar-link">String.format()字符串常规类型格式化的两种重载方式</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>集群部署</span> <span class="arrow right"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>错误</span> <span class="arrow right"><i aria-label="icon: down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></i></span></p> <!----></section></li><li><a href="/docs/update-log.html" title="更新日志&amp;&amp;开发计划" class="sidebar-link">更新日志&amp;&amp;开发计划</a></li><li><a href="/docs/about.html" title="关于项目" class="sidebar-link">关于项目</a></li></ul> </aside> <main class="page has-page-anchor"> <div class="theme-dc3-content content__default"><h3 id="docker-compose">Docker Compose <a href="#docker-compose" class="header-anchor">#</a></h3> <blockquote><ul><li><p>使用 Docker Compose 可以轻松、高效的管理容器,它是一个用于定义和运行多容器 Docker 的应用程序工具</p></li> <li><p>Docker Compose 将所管理的容器分为三层,分别是工程(project)、服务(service)、容器(container)</p></li> <li><p>Docker Compose 运行目录下的所有文件(docker-compose.yml)组成一个工程,一个工程包含多个服务,每个服务中定义了容器运行的镜像、参数、依赖,一个服务可包括多个容器实例</p></li></ul></blockquote> <h3 id="检测是否安装-docker-compose">检测是否安装 docker compose <a href="#检测是否安装-docker-compose" class="header-anchor">#</a></h3> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">docker-compose</span> version
</code></pre></div><h3 id="安装">安装 <a href="#安装" class="header-anchor">#</a></h3> <blockquote><p>这里以按照 <code>1.27.4</code> 版本为例,最新版本可以在 <a href="https://github.com/docker/compose/releases" target="_blank" rel="noopener noreferrer">https://github.com/docker/compose/releases<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> 查询到。</p></blockquote> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 该步骤将 docker-compose 可执行文件下载到目标机器的 /usr/local/bin/docker-compose 位置;</span>
<span class="token comment"># 如果网络比较慢,也可以手动下载,然放到 /usr/local/bin/docker-compose 位置。</span>
<span class="token function">sudo</span> <span class="token function">curl</span> <span class="token parameter variable">-L</span> https://github.com/docker/compose/releases/download/1.27.4/docker-compose-<span class="token variable"><span class="token variable">$(</span><span class="token function">uname</span> <span class="token parameter variable">-s</span><span class="token variable">)</span></span>-<span class="token variable"><span class="token variable">$(</span><span class="token function">uname</span> <span class="token parameter variable">-m</span><span class="token variable">)</span></span> <span class="token parameter variable">-o</span> /usr/local/bin/docker-compose
<span class="token comment"># 该步骤给 /usr/local/bin/docker-compose 可执行文件授权</span>
<span class="token function">sudo</span> <span class="token function">chmod</span> +x /usr/local/bin/docker-compose
<span class="token comment"># 查看 docker-compose 版本,检查是否安装成功</span>
<span class="token function">docker-compose</span> <span class="token parameter variable">-v</span>
</code></pre></div><p><strong>或者</strong></p> <div class="language-bash extra-class"><pre class="language-bash"><code>pip <span class="token function">install</span> <span class="token function">docker-compose</span>
</code></pre></div><h3 id="docker-compose-yml-属性">docker-compose.yml 属性 <a href="#docker-compose-yml-属性" class="header-anchor">#</a></h3> <blockquote><p>Compose允许用户通过一个docker-compose.yml模板文件(YAML 格式)来定义一组相关联的应用容器为一个项目(project)。</p> <p>Compose模板文件是一个定义服务、网络和卷的YAML文件。Compose模板文件默认路径是当前目录下的docker-compose.yml,可以使用.yml或.yaml作为文件扩展名。
Docker-Compose标准模板文件应该包含version、services、networks 三大部分,最关键的是services和networks两个部分。</p></blockquote> <div class="language-yaml extra-class"><pre class="language-yaml"><code><span class="token key atrule">version</span><span class="token punctuation">:</span> <span class="token string">'3.3'</span>
<span class="token key atrule">services</span><span class="token punctuation">:</span>
<span class="token key atrule">gateway</span><span class="token punctuation">:</span>
<span class="token key atrule">build</span><span class="token punctuation">:</span>
<span class="token key atrule">context</span><span class="token punctuation">:</span> ../dc3<span class="token punctuation">-</span>gateway/
<span class="token key atrule">dockerfile</span><span class="token punctuation">:</span> ./Dockerfile
<span class="token key atrule">image</span><span class="token punctuation">:</span> pnoker/dc3<span class="token punctuation">-</span>gateway<span class="token punctuation">:</span>1.0.0
<span class="token key atrule">restart</span><span class="token punctuation">:</span> always
<span class="token key atrule">ports</span><span class="token punctuation">:</span>
<span class="token punctuation">-</span> 8000<span class="token punctuation">:</span><span class="token number">8000</span>
<span class="token key atrule">container_name</span><span class="token punctuation">:</span> dc3<span class="token punctuation">-</span>gateway
<span class="token key atrule">hostname</span><span class="token punctuation">:</span> dc3<span class="token punctuation">-</span>gateway
<span class="token key atrule">volumes</span><span class="token punctuation">:</span>
<span class="token punctuation">-</span> logs<span class="token punctuation">:</span>/dc3<span class="token punctuation">-</span>gateway/dc3/logs
<span class="token key atrule">networks</span><span class="token punctuation">:</span>
<span class="token key atrule">dc3net</span><span class="token punctuation">:</span>
<span class="token key atrule">aliases</span><span class="token punctuation">:</span>
<span class="token punctuation">-</span> dc3<span class="token punctuation">-</span>gateway
<span class="token key atrule">volumes</span><span class="token punctuation">:</span>
<span class="token key atrule">logs</span><span class="token punctuation">:</span>
<span class="token key atrule">networks</span><span class="token punctuation">:</span>
<span class="token key atrule">dc3net</span><span class="token punctuation">:</span>
<span class="token key atrule">driver</span><span class="token punctuation">:</span> <span class="token string">'bridge'</span>
</code></pre></div><ul><li><strong>version</strong>:docker-compose的版本号</li> <li><strong>context</strong>:Dockerfile的文件路径,也可以是到链接到git仓库的url,当提供的值是相对路径时,被解析为相对于撰写文件的路径,此目录也是发送到Docker守护进程的context</li> <li><strong>dockerfile</strong>:使用dockerfile文件来构建,必须指定构建路径</li> <li><strong>image</strong>:指定服务的镜像名称或镜像ID。如果镜像在本地不存在,Compose将会尝试拉取镜像</li> <li><strong>restart</strong>:重启策略</li> <li><strong>ports</strong>:端口映射列表,宿主机端口:容器端口</li> <li><strong>container_name</strong>:Compose容器名称格式是:&lt;项目名称&gt;&lt;服务名称&gt;&lt;序号&gt;
可以自定义项目名称、服务名称,但如果想完全控制容器的命名,可以使用标签指定</li> <li><strong>hostname</strong>:容器的hostname</li> <li><strong>volumes</strong>:挂载一个目录或者一个已存在的数据卷容器,可以直接使用 [HOST:CONTAINER]格式,或者使用[HOST:CONTAINER:ro]格式,后者对于容器来说,数据卷是只读的,可以有效保护宿主机的文件系统</li> <li><strong>networks</strong>:设置网络模式</li></ul> <h3 id="常见指令">常见指令 <a href="#常见指令" class="header-anchor">#</a></h3> <h4 id="_1-ps-列出所有运行容器">1.ps(列出所有运行容器) <a href="#_1-ps-列出所有运行容器" class="header-anchor">#</a></h4> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">docker-compose</span> <span class="token function">ps</span>
</code></pre></div><h4 id="_2-logs-查看服务日志输出">2.logs(查看服务日志输出) <a href="#_2-logs-查看服务日志输出" class="header-anchor">#</a></h4> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">docker-compose</span> logs
</code></pre></div><h4 id="_3-port-打印绑定的公共端口">3.port(打印绑定的公共端口) <a href="#_3-port-打印绑定的公共端口" class="header-anchor">#</a></h4> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">docker-compose</span> port dc3-web <span class="token number">443</span>
</code></pre></div><h4 id="_4-build-构建或者重新构建服务">4.build(构建或者重新构建服务) <a href="#_4-build-构建或者重新构建服务" class="header-anchor">#</a></h4> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">docker-compose</span> build
</code></pre></div><h4 id="_5-start-启动指定服务已存在的容器">5.start(启动指定服务已存在的容器) <a href="#_5-start-启动指定服务已存在的容器" class="header-anchor">#</a></h4> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">docker-compose</span> start dc3-web
</code></pre></div><h4 id="_6-stop-停止已运行的服务的容器">6.stop(停止已运行的服务的容器) <a href="#_6-stop-停止已运行的服务的容器" class="header-anchor">#</a></h4> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">docker-compose</span> stop dc3-web
</code></pre></div><h4 id="_7-rm-删除指定服务的容器">7.rm(删除指定服务的容器) <a href="#_7-rm-删除指定服务的容器" class="header-anchor">#</a></h4> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">docker-compose</span> <span class="token function">rm</span> dc3-web
</code></pre></div><h4 id="_8-up-构建、启动容器">8.up(构建、启动容器) <a href="#_8-up-构建、启动容器" class="header-anchor">#</a></h4> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">docker-compose</span> up
</code></pre></div><h4 id="_9-kill-通过发送-sigkill-信号来停止指定服务的容器">9.kill(通过发送 SIGKILL 信号来停止指定服务的容器) <a href="#_9-kill-通过发送-sigkill-信号来停止指定服务的容器" class="header-anchor">#</a></h4> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">docker-compose</span> <span class="token function">kill</span> dc3-web
</code></pre></div><h4 id="_10-pull-下载服务镜像">10.pull(下载服务镜像) <a href="#_10-pull-下载服务镜像" class="header-anchor">#</a></h4> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">docker-compose</span> pull
</code></pre></div><h4 id="_11-scale-设置指定服务运气容器的个数">11.scale(设置指定服务运气容器的个数) <a href="#_11-scale-设置指定服务运气容器的个数" class="header-anchor">#</a></h4> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">docker-compose</span> scale dc3-web<span class="token operator">=</span><span class="token number">3</span>
</code></pre></div><h4 id="_12-run-在一个服务上执行一个命令">12.run(在一个服务上执行一个命令) <a href="#_12-run-在一个服务上执行一个命令" class="header-anchor">#</a></h4> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">docker-compose</span> run web <span class="token function">bash</span>
</code></pre></div></div> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2023/4/12 下午5:00:18</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev"><a href="/docs/tip/centos-install-vnc.html" class="prev"><i aria-label="icon: left" class="anticon anticon-left"><svg viewBox="64 64 896 896" focusable="false" data-icon="left" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M724 218.3V141c0-6.7-7.7-10.4-12.9-6.3L260.3 486.8a31.86 31.86 0 0 0 0 50.3l450.8 352.1c5.3 4.1 12.9.4 12.9-6.3v-77.3c0-4.9-2.3-9.6-6.1-12.6l-360-281 360-281.1c3.8-3 6.1-7.7 6.1-12.6z"></path></svg></i>
安装 VNC Server
</a></span> <span class="next"><a href="/docs/tip/ffmpeg.html">
视频剪切
<i aria-label="icon: right" class="anticon anticon-right"><svg viewBox="64 64 896 896" focusable="false" data-icon="right" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M765.7 486.8L314.9 134.7A7.97 7.97 0 0 0 302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 0 0 0-50.4z"></path></svg></i></a></span></p></div> <div class="page-anchor"><div class="ant-space ant-space-vertical" style="width:100%;"><div class="ant-space-item"><div class="page-anchor-offset"><div><div class="ant-anchor-wrapper" style="max-height:100vh;"><div class="ant-anchor"><div class="ant-anchor-ink"><span class="ant-anchor-ink-ball"></span></div></div></div></div></div></div></div></div> </main> <!----></div><div class="global-ui"></div></div>
<script src="/assets/js/app.7dfefe51.js" defer></script><script src="/assets/js/2.a8b8915e.js" defer></script><script src="/assets/js/47.dc2d8aff.js" defer></script>
</body>
</html>