如何从0到1构建自己的 Docker 应用
简介 在日常开发或者生产环境中,很多情况下,我们的系统都不是一个应用可以搞定的,而是由很多个部分组成,比如 webapp,数据库,缓存等。所以这一章的例子,我们就以一个 web 应用 + 缓存 redis 作为例子构建一个稍微复杂点的应用。
<p style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">在日常开发或者生产环境中,很多情况下,我们的系统都不是一个应用可以搞定的,而是由很多个部分组成,比如 webapp,数据库,缓存等。所以这一章的例子,我们就以一个 web 应用 + 缓存 redis 作为例子构建一个稍微复杂点的应用。<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></p>
<p style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">使用的语言和应用的版本如下:Python 3.8.1,Flask库 1.1.1,Redis库 3.4.1。</span></p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<h2 style="margin-right: 16px; margin-left: 16px; outline: 0px; font-weight: 400; font-size: 16px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 20px; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">1. web 应用</strong></span></h2>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">这次我们使用 Python 来编写我们的 web 应用,上一次我们使用的是 Go 语言。由于 Go 语言部署直接使用二进制文件,Dockerfile 会极其的简单,为了让大家熟悉一下 Dockerfile 的应用,所以这里我们使用 Python 语言里编写我们的 web 应用。<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></p>
<p style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">Python 语言相信大家都很熟悉,不熟悉也没有关系,代码都很简单。基于 Python 的 web 网络应用框架比较出名的有 Django,Tornado,Flask 等。我们这里使用 Flask 来构建我们的应用,因为 Flask 是一种极其轻量的框架。<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></p>
<p style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<h3 style="margin-right: 16px; margin-left: 16px; outline: 0px; font-weight: 400; font-size: 16px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">1.1 Flask 安装</strong></h3>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">Flask 安装很简单,和其他 Python 依赖安装基本没有区别。</span></p>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 54px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="nginx"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__attribute" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">pip</span> install flask</span></code></pre>
</section>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<h3 style="margin-right: 16px; margin-left: 16px; outline: 0px; font-weight: 400; font-size: 16px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">1.2 Flask demo</strong></h3>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">我们前面说了 Flask 是一个非常轻量的 web 框架,那么有多轻量呢?轻量到我们使用下面几行代码就可以构建出来一个简单的 web 应用。<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></p>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 210px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="python"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">from</span> flask <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">import</span> Flask</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><br style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">app = Flask(__name__)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><br style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;">@app.route('/')</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__function" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">def</span> <span class="code-snippet__title" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">hello</span><span class="code-snippet__params" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">()</span>:</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">return</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'Hello, Flask'</span></span></code></pre>
</section>
<p style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">启动应用。<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></p>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 106px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="cs"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">$ env FLASK_APP=hello.py flask run</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> * Serving Flask app <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">"hello"</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> * Running <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">on</span> http:<span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">//127.0.0.1:5000/ (Press CTRL+C to quit)</span></span></code></pre>
</section>
<p style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </span></p>
<p style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">应用默认启动在 5000 端口,我们可以通过 -p 参数指定引用的启动端口。当然 Flask 还支持其他参数,我们可以通过 flask run --help 进行查看。<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></p>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 808px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="kotlin"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__symbol" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">root@</span>a36d1df88169:/# flask run --help</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">Usage: flask run [OPTIONS]</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><br style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> Run a local development server.</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><br style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> This server <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">is</span> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">for</span> development purposes only. It does not provide the</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> stability, security, or performance of production WSGI servers.</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><br style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> The reloader and debugger are enabled <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">by</span> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">default</span> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">if</span> FLASK_ENV=development</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> or FLASK_DEBUG=<span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">1</span>.</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><br style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">Options:</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> -h, --host TEXT The <span class="code-snippet__class" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">interface</span> <span class="code-snippet__title" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">to</span> <span class="code-snippet__title" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">bind</span> <span class="code-snippet__title" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">to</span>.</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> -p, --port INTEGER The port to bind to.</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> --cert PATH Specify a certificate file to use HTTPS.</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> --key FILE The key file to use <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">when</span> specifying a</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> certificate.</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> --reload / --no-reload Enable or disable the reloader. By <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">default</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> the reloader <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">is</span> active <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">if</span> debug <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">is</span> enabled.</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> --debugger / --no-debugger Enable or disable the debugger. By <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">default</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> the debugger <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">is</span> active <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">if</span> debug <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">is</span> enabled.</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> --eager-loading / --lazy-loader</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> Enable or disable eager loading. By <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">default</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> eager loading <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">is</span> enabled <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">if</span> the reloader <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">is</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> disabled.</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> --with-threads / --without-threads</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> Enable or disable multithreading.</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> --extra-files PATH Extra files that trigger a reload on change.</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> Multiple paths are separated <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">by</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">':'</span>.</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> --help Show <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">this</span> message and exit.</span></code></pre>
</section>
<p style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </span></p>
<p style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">应用启动了之后,我们可以访问 5000 端口来验证应用是不是正常的。<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></p>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 80px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="cs"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">[<span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;">root@docker ~</span>]<span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;"># curl localhost:5000</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">Hello, Flask</span></code></pre>
</section>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<h3 style="margin-right: 16px; margin-left: 16px; outline: 0px; font-weight: 400; font-size: 16px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">1.3 Flask 使用</strong></h3>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">上面介绍了 Flask 最简单的使用 demo,下面我们使用 Flask 来编写我们应用和 Redis 进行交互。首先我们也要先安装 Python 依赖库:redis。<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></p>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 54px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="nginx"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__attribute" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">pip</span> install redis</span></code></pre>
</section>
<p style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">我们主要要实现三个功能:<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></p>
<p style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<ol class="list-paddingleft-1" style="margin-right: 16px; margin-left: 16px; padding-left: 1.2em; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<section style="outline: 0px; max-width: 100%; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">redis 连接</span></section>
</li>
<li style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<section style="outline: 0px; max-width: 100%; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">提供一个 route set 实现对 redis 中的值进行设置</span></section>
</li>
<li style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<section style="outline: 0px; max-width: 100%; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">提供一个 route get 实现对 redis 中的值进行查询</span></section>
</li>
</ol>
<h5 style="margin-right: 16px; margin-left: 16px; outline: 0px; font-weight: 400; font-size: 16px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </h5>
<h5 style="margin-right: 16px; margin-left: 16px; outline: 0px; font-weight: 400; font-size: 16px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">redis 连接</strong></h5>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">redis 连接,我们直接使用 Python 的依赖库 Redis。</span></section>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 106px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="makefile"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">import redis</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><br style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">redis_client = redis.Redis(host=redis_host, port=redis_port, db=0)</span></code></pre>
</section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </span></section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">其中连接 Redis 需要使用三个参数:<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></section>
<ul class="list-paddingleft-1" style="margin-right: 16px; margin-left: 16px; padding-left: 1.2em; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<section style="outline: 0px; max-width: 100%; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">host: redis 的 host</span></section>
</li>
<li style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<section style="outline: 0px; max-width: 100%; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">port: redis 的端口</span></section>
</li>
<li style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<section style="outline: 0px; max-width: 100%; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">db:redis 中的数据库,我们使用 db = 0 即可。</span></section>
</li>
</ul>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;"><br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" />这里的一个核心问题是 redis 运行在另外一个 Docker 中,那我们在应用的 Docker 中如何连接 redis 实例呢?也就是如何发现redis 的 host 和 port 呢?<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /><br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">在 Docker 技术中我们可以在启动 Docker 的时候指定参数 --link 将两个 Docker 的网络进行打通。在下面部署的时候我们再细说。<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /><br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></section>
<h5 style="margin-right: 16px; margin-left: 16px; outline: 0px; font-weight: 400; font-size: 16px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">set route</strong></h5>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">编写一个 route,可以对 redis 进行写入。<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></section>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 184px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="cs"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">@app.route(<span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'/set'</span>)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__function" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">def <span class="code-snippet__title" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">set</span>():</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> key</span> = request.args.<span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">get</span>(<span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">"key"</span>)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">value</span> = request.args.<span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">get</span>(<span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">"value"</span>)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> redis_client.<span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">set</span>(key, <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">value</span>)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">return</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'OK. We have set '</span> + key + <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">' to be '</span> + <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">value</span></span></code></pre>
</section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">其中 request.args 中可以获取到 url 中的参数。但是上面的代码没有做参数校验,key 和 value 可能是空,我们加一个参数校验的逻辑。<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></section>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 236px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="cs"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">@app.route(<span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'/set'</span>)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__function" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">def <span class="code-snippet__title" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">set</span>():</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> key</span> = request.args.<span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">get</span>(<span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">"key"</span>)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">value</span> = request.args.<span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">get</span>(<span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">"value"</span>)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">if</span> key <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">is</span> None or <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">value</span> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">is</span> None:</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">return</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'OOps, the key or value is NULL'</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> redis_client.<span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">set</span>(key, <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">value</span>)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">return</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'OK. We have set '</span> + key + <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">' to be '</span> + <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">value</span></span></code></pre>
</section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </span></section>
<h5 style="margin-right: 16px; margin-left: 16px; outline: 0px; font-weight: 400; font-size: 16px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">get route</strong></h5>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">编写一个 route 对 redis 中的值查询<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></section>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 210px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="kotlin"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;">@app</span>.route(<span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'/get'</span>)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">def <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">get</span>():</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> key = request.args.<span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">get</span>(<span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'key'</span>)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">if</span> key <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">is</span> None:</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">return</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'OOps, the key is null'</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> value = redis_client.<span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">get</span>(key)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">return</span> value</span></code></pre>
</section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </span></section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">至此,我们的 web 应用代码编写完成,完整的代码如下,其中 redis-host 现在还是一个占位符,我们部署的时候会把这个变量注入进来。<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></section>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 600px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="kotlin"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">from flask <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">import</span> Flask, request</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">import</span> redis</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><br style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">redis_client = redis.Redis(host=<span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'redis-host'</span>, port=<span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">6379</span>, db=<span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">0</span>)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">app = Flask(__name__)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><br style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;">@app</span>.route(<span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'/set'</span>)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">def <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">set</span>():</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> key = request.args.<span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">get</span>(<span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'key'</span>)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> value = request.args.<span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">get</span>(<span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'value'</span>)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">if</span> key <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">is</span> None or value <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">is</span> None:</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">return</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'OOps, the key or value is NULL'</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> redis_client.<span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">set</span>(key, value)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">return</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'OK. We have set '</span> + key + <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">' to be '</span> + value</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><br style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;">@app</span>.route(<span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'/get'</span>)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">def <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">get</span>():</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> key = request.args.<span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">get</span>(<span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'key'</span>)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">if</span> key <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">is</span> None:</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">return</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'OOps, the key is null'</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> value = redis_client.<span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">get</span>(key)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">return</span> value</span></code></pre>
</section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </span></section>
<h2 style="margin-right: 16px; margin-left: 16px; outline: 0px; font-weight: 400; font-size: 16px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 20px; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">2. Dockerfile</strong></span></h2>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">下面开始编写我们的 Dockerfile。回忆一下我们上面编写 web 应用过程中,主要安装了依赖 flask 和 redis 依赖。我们可以很简单写出来我们的 Dockerfile 如下,并命名为 Dockerfile。<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></section>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 340px; list-style-type: none; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="sql"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">from python:3</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><br style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">RUN pip <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">install</span> flask</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">RUN pip <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">install</span> redis</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">RUN mkdir /<span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">data</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><br style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">COPY hello.py /<span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">data</span>/</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">WORKDIR /<span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">data</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><br style="outline: 0px; max-width: 1000%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">EXPOSE <span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">5000</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">ENV FLASK_APP=/<span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">data</span>/hello.py</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">ENTRYPOINT ["flask", "run", "-h", "0.0.0.0"]</span></code></pre>
</section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </span></section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">我们对这个 Dockerfile 进行一个简单解释:</span></section>
<ul class="list-paddingleft-1" style="margin-right: 16px; margin-left: 16px; padding-left: 1.2em; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 100%; font-size: 16px; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<section style="outline: 0px; max-width: 100%; line-height: 1.75em; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">from:表示基础镜像是 python:3;</span></section>
</li>
<li style="outline: 0px; max-width: 100%; font-size: 16px; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<section style="outline: 0px; max-width: 100%; line-height: 1.75em; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">RUN:表示在 docker build 的时候会执行后面的几个命令;</span></section>
</li>
<li style="outline: 0px; max-width: 100%; font-size: 16px; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<section style="outline: 0px; max-width: 100%; line-height: 1.75em; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">COPY:拷贝文件或者目录都可以;</span></section>
</li>
<li style="outline: 0px; max-width: 100%; font-size: 16px; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<section style="outline: 0px; max-width: 100%; line-height: 1.75em; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">WORKDIR:表示启动容器之后,当前的工作目录;</span></section>
</li>
<li style="outline: 0px; max-width: 100%; font-size: 16px; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<section style="outline: 0px; max-width: 100%; line-height: 1.75em; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">EXPOSE:表示容器要暴露 5000 端口;</span></section>
</li>
<li style="outline: 0px; max-width: 100%; font-size: 16px; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<section style="outline: 0px; max-width: 100%; line-height: 1.75em; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">ENV:环境变量;</span></section>
</li>
<li style="outline: 0px; max-width: 100%; font-size: 16px; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<section style="outline: 0px; max-width: 100%; line-height: 1.75em; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">ENTRYPOINT:表示 Docker 容器的启动进程。这里 entrypoint 中的 flask run 我们增加了参数 -h 0.0.0.0。如果不加这个参数的话,进程默认绑定到 127.0.0.1,外面是没有办法访问的。</span></section>
<section style="outline: 0px; max-width: 100%; line-height: 1.75em; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"></section>
</li>
</ul>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">通过该 dockerfile 来构建镜像。基本每一个命令都会对应一个 step,如下。<br style="outline: 0px; max-width: 100%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;" /><br style="outline: 0px; max-width: 100%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></section>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 574px; list-style-type: none; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="properties"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;">[root@docker</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">web]# docker build -t web:v1 .</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__attr" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">Sending</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">build context to Docker daemon 3.584kB</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__attr" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">Step</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">1/8 : from python:3</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;">---></span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">efdecc2e377a</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__attr" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">Step</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">2/8 : RUN pip install flask</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;">---></span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">Running in c4dfe7b3e466</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__attr" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">Collecting</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">flask</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__attr" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">Downloading</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">Flask-1.1.1-py2.py3-none-any.whl (94 kB)</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__attr" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">Collecting</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">itsdangerous>=0.24</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__attr" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">Downloading</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">itsdangerous-1.1.0-py2.py3-none-any.whl (16 kB)</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__attr" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">Collecting</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">Jinja2>=2.10.1</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__attr" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">Downloading</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">Jinja2-2.11.1-py2.py3-none-any.whl (126 kB)</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__attr" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">Collecting</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">Werkzeug>=0.15</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__attr" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">Downloading</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">Werkzeug-1.0.0-py2.py3-none-any.whl (298 kB)</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__attr" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">.......</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__attr" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">Step</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">8/8 : ENTRYPOINT ["flask", "run"]</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;">---></span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">Running in 25594e1de72f</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__attr" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">Removing</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">intermediate container 25594e1de72f</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;">---></span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">d18b55e4d1fd</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__attr" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">Successfully</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">built d18b55e4d1fd</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__attr" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">Successfully</span> <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">tagged web:v1</span></span></code></pre>
</section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </span></section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">构建成功之后,我们可以通过 docker images 查看到我们刚才 build 出来的镜像 web。<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></section>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 80px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="cs"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">[<span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;">root@docker demo</span>]<span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;"># docker images | grep web</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">web v1 <span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">02</span>cc264143dc <span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">6</span> minutes ago <span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">943</span>MB</span></code></pre>
</section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"></section>
<h2 style="margin-right: 16px; margin-left: 16px; outline: 0px; font-weight: 400; font-size: 16px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 20px; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">3. 部署</strong></span></h2>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">我们先来部署一个 Redis Docker,-d 参数表示以 daemon 的方式运行。-p 表示端口映射。-name 表示 Docker 容器的名字叫 redis-test。<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></section>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 54px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="css"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__selector-tag" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">docker</span> <span class="code-snippet__selector-tag" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">run</span> <span class="code-snippet__selector-tag" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">--name</span> <span class="code-snippet__selector-tag" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">redis-test</span> <span class="code-snippet__selector-tag" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">-p</span> 6379<span class="code-snippet__selector-pseudo" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">:6379</span> <span class="code-snippet__selector-tag" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">-d</span> <span class="code-snippet__selector-tag" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">redis</span><span class="code-snippet__selector-pseudo" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">:latest</span></span></code></pre>
</section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </span></section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">下面部署我们的 web 应用。<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></section>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 158px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="cs"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">[<span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;">root@docker ~</span>]<span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;"># docker run -p 5000:5000 --link redis-test:redis-host -d --name web web:v1</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">64</span>eef1f67c3934b6257510f47b587c59cee635188a4043b749966e71d2bc8c08</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">[<span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;">root@docker ~</span>]<span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;"># docker ps</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">64</span>eef1f67c39 web:v1 <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">"flask run -h 0.0.0.0"</span> <span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">2</span> seconds ago Up <span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">1</span> second <span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">0.0</span><span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">.0</span><span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">.0</span>:<span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">5000</span>-><span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">5000</span>/tcp web</span></code></pre>
</section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </span></section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">其中有一个运行参数需要进行简单说明,也就是 --link。link 后面跟一对映射的值,左侧的为已经存在的 Docker 容器,右侧的为该容器映射到我们启动的 Docker 应用中的 host 名字,这里也就是 web 这个 Docker 容器。我们下面通过 docker exec 进入到容器中看一下 link 是怎么做的。<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /><br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">我们查看一下 hosts 文件。<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></section>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 262px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="ruby"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">root@64eef1f67c39<span class="code-snippet__symbol" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">:/data</span><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;"># cat /etc/hosts</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">127.0</span>.<span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">0</span>.<span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">1</span> localhost</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__symbol" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">:</span><span class="code-snippet__symbol" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">:</span><span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">1</span> localhost ip6-localhost ip6-loopback</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">fe00::<span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">0</span> ip6-localnet</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">ff00::<span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">0</span> ip6-mcastprefix</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">ff02::<span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">1</span> ip6-allnodes</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">ff02::<span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">2</span> ip6-allrouters</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">172.17</span>.<span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">0</span>.<span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">5</span> redis-host 0d748e8ce766 redis-test</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">172.17</span>.<span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">0</span>.<span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">6</span> <span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">64</span>eef1f67c39</span></code></pre>
</section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </span></section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">我们可以看到 redis-host 已经被写到 hosts 中,所以我们在 web 这个 Docker 容器中就可以通过 redis-host 这个主机名访问到 Redis 容器了,这也是我们的应用代码的写法。</span></section>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<h2 style="margin-right: 16px; margin-left: 16px; outline: 0px; font-weight: 400; font-size: 16px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 20px; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">4. 验证</strong></span></h2>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">部署完成,我们下面进行一个简单的验证。在宿主机上执行下面命令去设置一对 kv: <imooc, </span><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">imooc.com</span><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">> 写入到 Redis 中。<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></section>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 80px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="cs"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">[<span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;">root@docker ~</span>]<span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;"># curl "localhost:5000/set?key=imooc&value=imooc.com"</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">OK. We have <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">set</span> imooc to be imooc.com</span></code></pre>
</section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"></section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </span></section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">第二个请求去读取该值,如下。<br style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></section>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 80px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="cs"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">[<span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;">root@docker ~</span>]<span class="code-snippet__meta" style="outline: 0px; max-width: 1000%; color: #afafaf; box-sizing: border-box !important; overflow-wrap: break-word !important;"># curl "localhost:5000/get?key=imooc"</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">imooc.com</span></code></pre>
</section>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"></section>
<h2 style="margin-right: 16px; margin-left: 16px; outline: 0px; font-weight: 400; font-size: 16px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 20px; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">5. 总结</strong></span></h2>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<section style="margin-right: 16px; margin-left: 16px; outline: 0px; max-width: 100%; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; line-height: 1.75em; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 16px; box-sizing: border-box !important; overflow-wrap: break-word !important;">至此,我们第一个动手实践的 Docker 应用已经完成。</span></section>
分享到:
转载:
https://mp.weixin.qq.com/s/DjLMP5rw84KTCDJY-8PK4A
喜欢 1
收藏
暂无评论信息
- 相关文章
- 文章推荐
-
git:如何管理本机的多个ssh密钥(多个远程仓库账号)
如果我们电脑上已经存在了一个ssh key,那么我们需要在我们电脑上生成第二个你想在本电脑上使用的id_rsa,使用命令:ssh-keygen -t rsa -C "你的github账号"。
-
Docker 常用命令
docker目前代替虚拟机使用的一个容器,灵活好用。
-
眼镜试戴的装饰效果
开发眼镜类产品的时候需要使用试戴的功能,这里就有你需要的学习资料哦!
-
娱美德旗下MMORPG手游《传奇4》将推出新PVP玩法"比奇掠夺"&
《传奇4》推出新门派PVP玩法!韩国首尔2022年6月29日 /美通社/ -- 《传奇4》(MIR4)的新PVP玩法比奇掠夺(Bicheon Heist)于2022年6月28日推出。
- 点击排行
- 站长推荐
- 猜你喜欢
- 网站信息
- 站内问答:12篇
- 站内文章:212篇
- 建站时间:已运行1107天
- 备案号: 浙ICP备2022018799号
- 语言:
English(USA)
French(FR)
Chinese(ZH)
无数据