<?xml version="1.0" encoding="utf-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><title>PHP开发日志</title><link>https://lxf.net/</link><description></description><item><title>test</title><link>https://lxf.net/?id=88</link><description>&lt;p&gt;&lt;img src=&quot;https://lxf.net/zb_users/upload/2025/09/202509141757821420180958.jpg&quot; title=&quot;123.jpg&quot; alt=&quot;123.jpg&quot;/&gt;&lt;/p&gt;</description><pubDate>Sun, 14 Sep 2025 11:41:14 +0800</pubDate></item><item><title>SAAS多租户模型内容</title><link>https://lxf.net/?id=87</link><description>&lt;p&gt;1. 租户生命周期管理&lt;/p&gt;&lt;p&gt;租户创建流程：&lt;/p&gt;&lt;p&gt;注册页面需要支持租户基本信息的收集（如公司名称、联系人信息、初始管理员账号等）。&lt;/p&gt;&lt;p&gt;支持为租户分配唯一的子域名或自定义域名。&lt;/p&gt;&lt;p&gt;自动化流程：租户创建后，可能需要初始化数据库、配置默认数据（如初始用户角色、权限等）。&lt;/p&gt;&lt;p&gt;租户状态管理：&lt;/p&gt;&lt;p&gt;状态字段（如 active、suspended、expired 等），用于标识租户的状态。&lt;/p&gt;&lt;p&gt;提供手动或自动化的状态切换逻辑（例如到期后自动暂停）。&lt;/p&gt;&lt;p&gt;租户删除与归档：&lt;/p&gt;&lt;p&gt;提供软删除功能，允许将租户归档而不是直接删除。&lt;/p&gt;&lt;p&gt;归档后的租户数据可以保留一段时间，以备后续恢复或审计。&lt;/p&gt;&lt;p&gt;2. 计费与支付管理&lt;/p&gt;&lt;p&gt;套餐管理：&lt;/p&gt;&lt;p&gt;定义不同的套餐计划（如免费版、基础版、高级版等），每个套餐可以包含不同的功能限制（如用户数量、存储空间、API 请求次数等）。&lt;/p&gt;&lt;p&gt;支持动态调整套餐（升级/降级）。&lt;/p&gt;&lt;p&gt;续费与试用期：&lt;/p&gt;&lt;p&gt;支持试用期设置，并在试用期结束前提醒租户续费。&lt;/p&gt;&lt;p&gt;提供自动续费选项（通过支付网关实现）。&lt;/p&gt;&lt;p&gt;支付网关集成：&lt;/p&gt;&lt;p&gt;集成主流支付网关（如 Stripe、PayPal、支付宝、微信支付等）。&lt;/p&gt;&lt;p&gt;记录支付历史和发票信息。&lt;/p&gt;&lt;p&gt;账单与发票管理：&lt;/p&gt;&lt;p&gt;生成详细的账单记录，包括费用明细、支付状态、发票下载链接等。&lt;/p&gt;&lt;p&gt;支持导出 PDF 格式的发票。&lt;/p&gt;&lt;p&gt;3. 域名管理&lt;/p&gt;&lt;p&gt;子域名分配：&lt;/p&gt;&lt;p&gt;自动生成租户的子域名（如 tenant1.example.com）。&lt;/p&gt;&lt;p&gt;允许租户自定义子域名（如 custom-name.example.com）。&lt;/p&gt;&lt;p&gt;自定义域名绑定：&lt;/p&gt;&lt;p&gt;支持租户绑定自己的域名（如 tenant1.com）。&lt;/p&gt;&lt;p&gt;提供 DNS 设置指南（如 CNAME 或 A 记录指向你的服务器）。&lt;/p&gt;&lt;p&gt;SSL 证书管理：&lt;/p&gt;&lt;p&gt;自动为租户的子域名或自定义域名申请 SSL 证书（推荐使用 Let&amp;#39;s Encrypt）。&lt;/p&gt;&lt;p&gt;监控证书的有效期并自动续期。&lt;/p&gt;&lt;p&gt;4. 租户资源隔离与限制&lt;/p&gt;&lt;p&gt;数据库隔离：&lt;/p&gt;&lt;p&gt;使用 stancl/tenancy 的多数据库模式，确保每个租户的数据完全隔离。&lt;/p&gt;&lt;p&gt;文件存储隔离：&lt;/p&gt;&lt;p&gt;配置独立的文件存储路径或 S3 存储桶，避免不同租户之间的文件冲突。&lt;/p&gt;&lt;p&gt;资源配额限制：&lt;/p&gt;&lt;p&gt;对租户的资源使用进行限制（如存储空间、带宽、并发连接数等）。&lt;/p&gt;&lt;p&gt;提供实时监控和告警功能。&lt;/p&gt;&lt;p&gt;5. 租户管理面板&lt;/p&gt;&lt;p&gt;租户信息概览：&lt;/p&gt;&lt;p&gt;显示租户的基本信息（如公司名称、联系人、创建时间等）。&lt;/p&gt;&lt;p&gt;显示当前套餐、有效期、支付状态等。&lt;/p&gt;&lt;p&gt;活动日志：&lt;/p&gt;&lt;p&gt;记录租户的操作日志（如登录、修改配置等）。&lt;/p&gt;&lt;p&gt;提供搜索和过滤功能，方便排查问题。&lt;/p&gt;&lt;p&gt;权限管理：&lt;/p&gt;&lt;p&gt;为每个租户分配独立的管理员账户，并支持多角色权限管理。&lt;/p&gt;&lt;p&gt;允许租户管理员自行管理其团队成员。&lt;/p&gt;&lt;p&gt;6. 通知与提醒&lt;/p&gt;&lt;p&gt;邮件通知：&lt;/p&gt;&lt;p&gt;在租户即将到期、支付失败或发生异常时发送邮件提醒。&lt;/p&gt;&lt;p&gt;站内消息：&lt;/p&gt;&lt;p&gt;提供站内消息系统，向租户管理员发送重要通知。&lt;/p&gt;&lt;p&gt;短信/推送通知：&lt;/p&gt;&lt;p&gt;集成短信服务或推送通知服务（如 Twilio、Firebase Cloud Messaging），以覆盖更多通知场景。&lt;/p&gt;&lt;p&gt;7. 安全与合规&lt;/p&gt;&lt;p&gt;数据隐私与备份：&lt;/p&gt;&lt;p&gt;定期备份租户数据，并提供数据恢复功能。&lt;/p&gt;&lt;p&gt;遵守 GDPR 或其他相关法规，确保租户数据的安全和隐私。&lt;/p&gt;&lt;p&gt;身份验证与授权：&lt;/p&gt;&lt;p&gt;实现强大的身份验证机制（如双因素认证）。&lt;/p&gt;&lt;p&gt;确保租户之间的权限隔离，避免越权访问。&lt;/p&gt;&lt;p&gt;日志与审计：&lt;/p&gt;&lt;p&gt;记录所有关键操作（如租户创建、删除、支付等）。&lt;/p&gt;&lt;p&gt;提供审计日志查询功能，便于追踪和分析。&lt;/p&gt;&lt;p&gt;8. 扩展功能&lt;/p&gt;&lt;p&gt;多语言支持：&lt;/p&gt;&lt;p&gt;为租户提供多语言界面支持，满足国际化需求。&lt;/p&gt;&lt;p&gt;自定义主题：&lt;/p&gt;&lt;p&gt;允许租户自定义其 SAAS 应用的外观（如颜色、Logo 等）。&lt;/p&gt;&lt;p&gt;API 接口：&lt;/p&gt;&lt;p&gt;提供 API 接口，让租户能够通过编程方式与其数据交互。&lt;/p&gt;&lt;p&gt;确保 API 的安全性（如使用 OAuth2 或 API 密钥）。&lt;/p&gt;&lt;p&gt;数据分析与报表：&lt;/p&gt;&lt;p&gt;提供租户使用情况的统计报表（如活跃用户数、资源消耗等）。&lt;/p&gt;&lt;p&gt;帮助租户更好地了解其业务表现。&lt;/p&gt;&lt;p&gt;9. 性能与扩展性&lt;/p&gt;&lt;p&gt;缓存优化：&lt;/p&gt;&lt;p&gt;使用 Redis 或 Memcached 缓存常用数据，提升性能。&lt;/p&gt;&lt;p&gt;队列处理：&lt;/p&gt;&lt;p&gt;将耗时任务（如发送邮件、生成报告等）放入队列中异步处理。&lt;/p&gt;&lt;p&gt;水平扩展：&lt;/p&gt;&lt;p&gt;设计可扩展的架构，支持多服务器部署以应对高并发场景。&lt;/p&gt;&lt;p&gt;10. 文档与支持&lt;/p&gt;&lt;p&gt;帮助中心：&lt;/p&gt;&lt;p&gt;提供详细的帮助文档，指导租户如何使用系统。&lt;/p&gt;&lt;p&gt;客户支持：&lt;/p&gt;&lt;p&gt;提供在线客服或工单系统，快速响应租户的问题。&lt;/p&gt;&lt;p&gt;开发者工具：&lt;/p&gt;&lt;p&gt;如果你的 SAAS 系统面向开发者，可以提供 SDK、API 文档和示例代码。&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Wed, 02 Apr 2025 20:04:00 +0800</pubDate></item><item><title>alpine.js Jquery Vue</title><link>https://lxf.net/?id=86</link><description>&lt;div&gt;&lt;div&gt;&lt;p&gt;Alpine.js 是一个轻量级的 JavaScript 框架，适用于开发简单、交互性要求不太复杂的网页。下面是一些适合使用 Alpine.js 开发的网页场景：&lt;/p&gt;&lt;ol class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;小型项目或页面：&lt;/strong&gt; Alpine.js 非常适合开发小型项目或简单的单页面应用（SPA），因为它的体积很小，加载速度快，不需要像其他大型框架那样复杂的构建和配置。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;表单交互：&lt;/strong&gt; 如果你需要为网页添加一些表单交互功能，比如输入验证、动态显示/隐藏表单字段等，Alpine.js 是一个很好的选择。它的数据绑定和事件监听能力使得处理表单交互变得简单而高效。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;条件渲染：&lt;/strong&gt; 当需要根据特定条件显示或隐藏一些元素时，比如根据用户的登录状态展示不同的界面，使用 Alpine.js 的 &lt;code&gt;x-show&lt;/code&gt; 或 &lt;code&gt;x-if&lt;/code&gt; 指令可以轻松实现条件渲染。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;简单动画效果：&lt;/strong&gt; Alpine.js 支持简单的动画效果，通过 &lt;code&gt;x-transition&lt;/code&gt; 和 &lt;code&gt;x-show&lt;/code&gt; 结合使用，可以实现一些基本的元素过渡效果。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;增强现有页面：&lt;/strong&gt; 如果你已经有一个静态页面，但希望在其中添加一些交互性功能而不想引入整个大型框架，那么可以使用 Alpine.js 来为现有页面增加交互性。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;快速原型开发：&lt;/strong&gt; 当你需要快速构建一个原型或演示页面时，Alpine.js 提供了简单而快速的开发方式，让你可以迅速验证概念和想法。&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;请注意，由于 Alpine.js 的定位是轻量级框架，对于复杂的应用程序或大规模的项目，你可能需要考虑更为功能丰富的框架，比如 Vue.js、React 或 Angular。这些框架提供更多高级特性和更好的可扩展性，适合构建大型和复杂的应用程序。&lt;/p&gt;&lt;p&gt;综上所述，Alpine.js 是一个优秀的选择，特别适用于小型项目、简单页面、表单交互和快速原型开发等场景。&lt;/p&gt;&lt;h2 data-id=&quot;heading-0&quot;&gt;那么我项目已经使用了jquery还需要使用alpine.js吗?&lt;/h2&gt;&lt;p&gt;Alpine.js 和 jQuery 都是用于前端开发的 JavaScript 库，但它们在设计理念、用法和特点上有很大的区别。下面是对比 Alpine.js 和 jQuery 的描述解析：&lt;/p&gt;&lt;ol class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;设计理念：&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;ul class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;Alpine.js：Alpine.js 是一个轻量级的 JavaScript 框架，专注于在现有 HTML 上增强交互性和动态功能。它的设计哲学是&amp;quot;更少的 JavaScript&amp;quot;，通过在 HTML 中使用指令和表达式来实现交互功能，而不是通过 JavaScript 代码来操作 DOM。这样可以使开发过程更简单、更直观，同时保持 HTML 和 JavaScript 的分离。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;jQuery：jQuery 是一个功能强大且广泛应用的 JavaScript 库，旨在简化 DOM 操作和处理事件。它提供了许多便捷的 API，使得选择元素、添加动画、处理事件等操作更加简单。它在较早的 Web 开发中非常流行，但随着现代浏览器的发展和原生 JavaScript API 的增强，jQuery 的地位逐渐被其他框架和库取代。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;使用方式：&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;ul class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;Alpine.js：Alpine.js 的使用方式非常简单，你只需将 Alpine.js 文件引入到 HTML 中，然后在元素上添加指令和表达式即可。它不需要特定的构建工具，也不需要学习新的 API，可以很方便地与现有项目集成。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;jQuery：使用 jQuery 需要先将 jQuery 库文件引入到 HTML 中，然后通过选择器选择元素并使用 jQuery 提供的方法来操作 DOM、添加事件处理等。虽然 jQuery 提供了方便的 API，但它的使用仍然需要学习一些特定的语法和方法。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;体积和性能：&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;ul class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;Alpine.js：Alpine.js 的体积非常小，仅有几 KB 大小，因此加载速度很快。由于它的设计理念是&amp;quot;更少的 JavaScript&amp;quot;，在性能方面表现很好，特别适合用于小型项目和简单页面。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;jQuery：相比于 Alpine.js，jQuery 的体积较大，虽然现代浏览器已经对其进行了缓存优化，但仍然比 Alpine.js 大很多。在性能方面，jQuery 提供了许多功能，有时可能会带来不必要的性能开销，特别是在现代浏览器已经原生支持许多常见操作的情况下。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;适用场景：&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;ul class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;Alpine.js：适用于小型项目、简单页面、表单交互、增强现有页面和快速原型开发等场景。它更加轻量，适合那些不需要复杂功能的项目。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;jQuery：在较早的 Web 开发中，jQuery 非常流行，适用于需要处理大量 DOM 操作和事件的项目。然而，现在在很多情况下，原生 JavaScript 已经能够胜任 jQuery 的任务，并且更为高效。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ol&gt;&lt;p&gt;总的来说，Alpine.js 和 jQuery 都有各自的优势和适用场景。如果你需要在现有 HTML 中增加一些交互功能，尤其是对于小型项目和简单页面，Alpine.js 是一个很好的选择。而对于复杂的项目和大规模的应用程序，可能更适合使用现代的前端框架，或者在不需要考虑兼容性的情况下，直接使用原生 JavaScript。&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Thu, 02 Jan 2025 08:22:27 +0800</pubDate></item><item><title>nuxtjs3 自定义$fetch pinia组合数据预取</title><link>https://lxf.net/?id=85</link><description>&lt;p&gt;//&lt;span class=&quot;hljs-string&quot;&gt;&amp;#39;~/plugins/piniaFetchPlugin.ts&amp;#39;&lt;/span&gt;,&amp;nbsp;&lt;/p&gt;&lt;div style=&quot;color: rgb(204, 204, 204); background-color: rgb(31, 31, 31); font-family: Menlo, Monaco, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; line-height: 18px; white-space-collapse: preserve;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #c586c0;&quot;&gt;import&lt;/span&gt; { &lt;span style=&quot;color: #9cdcfe;&quot;&gt;defineNuxtPlugin&lt;/span&gt; } &lt;span style=&quot;color: #c586c0;&quot;&gt;from&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;&amp;#39;#app&amp;#39;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #c586c0;&quot;&gt;import&lt;/span&gt; { &lt;span style=&quot;color: #9cdcfe;&quot;&gt;useRuntimeConfig&lt;/span&gt; } &lt;span style=&quot;color: #c586c0;&quot;&gt;from&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;&amp;#39;#imports&amp;#39;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #c586c0;&quot;&gt;import&lt;/span&gt; { &lt;span style=&quot;color: #9cdcfe;&quot;&gt;PiniaPluginContext&lt;/span&gt; } &lt;span style=&quot;color: #c586c0;&quot;&gt;from&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;&amp;#39;pinia&amp;#39;&lt;/span&gt;&lt;/div&gt;&lt;br/&gt;&lt;div&gt;&lt;span style=&quot;color: #c586c0;&quot;&gt;export&lt;/span&gt; &lt;span style=&quot;color: #c586c0;&quot;&gt;default&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;defineNuxtPlugin&lt;/span&gt;((&lt;span style=&quot;color: #9cdcfe;&quot;&gt;nuxtApp&lt;/span&gt;) &lt;span style=&quot;color: #569cd6;&quot;&gt;=&amp;gt;&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;nuxtApp&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;$pinia&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;use&lt;/span&gt;(({ &lt;span style=&quot;color: #9cdcfe;&quot;&gt;store&lt;/span&gt; }&lt;span style=&quot;color: #d4d4d4;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;PiniaPluginContext&lt;/span&gt;) &lt;span style=&quot;color: #569cd6;&quot;&gt;=&amp;gt;&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;store&lt;/span&gt;.&lt;span style=&quot;color: #dcdcaa;&quot;&gt;$fetch&lt;/span&gt; &lt;span style=&quot;color: #d4d4d4;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #569cd6;&quot;&gt;async&lt;/span&gt; (&lt;span style=&quot;color: #dcdcaa;&quot;&gt;fetcher&lt;/span&gt;&lt;span style=&quot;color: #d4d4d4;&quot;&gt;:&lt;/span&gt; () &lt;span style=&quot;color: #569cd6;&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #4ec9b0;&quot;&gt;Promise&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #4ec9b0;&quot;&gt;void&lt;/span&gt;&amp;gt;) &lt;span style=&quot;color: #569cd6;&quot;&gt;=&amp;gt;&lt;/span&gt; {&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #c586c0;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #9cdcfe;&quot;&gt;process&lt;/span&gt;.&lt;span style=&quot;color: #9cdcfe;&quot;&gt;server&lt;/span&gt;) {&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #c586c0;&quot;&gt;await&lt;/span&gt; &lt;span style=&quot;color: #dcdcaa;&quot;&gt;fetcher&lt;/span&gt;()&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;})&lt;/div&gt;&lt;div&gt;})&lt;/div&gt;&lt;br/&gt;&lt;/div&gt;&lt;p&gt;使用&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;lt;template&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp; &amp;lt;div&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;p v-if=&amp;quot;data&amp;quot;&amp;gt;{{ data }}&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;p v-else&amp;gt;Loading...&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp; &amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;lt;script setup&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;import { useExampleStore } from &amp;#39;@/stores/example&amp;#39;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;// 获取store实例&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;const store = useExampleStore()&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;// 在setup中预取数据&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;await store.$fetch(store.fetchData)&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;// 使用store中的数据&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;const data = store.$state.data&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;配置：&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;color: rgb(204, 204, 204); background-color: rgb(31, 31, 31); font-family: Menlo, Monaco, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; line-height: 18px; white-space-collapse: preserve;&quot;&gt;&lt;div&gt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;plugins&lt;/span&gt;&lt;span style=&quot;color: #9cdcfe;&quot;&gt;:&lt;/span&gt; [&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #ce9178;&quot;&gt;&amp;#39;~/plugins/piniaFetchPlugin.ts&amp;#39;&lt;/span&gt;,&lt;/div&gt;&lt;div&gt;],&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Wed, 05 Jun 2024 22:49:26 +0800</pubDate></item><item><title>要通过Docker镜像来配置Vue Storefront运行环境，请按照以下步骤操作：</title><link>https://lxf.net/?id=84</link><description>&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;### 1. 准备Dockerfile&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;首先，您需要一个Dockerfile来构建包含Vue Storefront及其依赖的镜像。Dockerfile通常会从Node.js基础镜像开始，并执行安装Vue Storefront和其依赖、打包应用以及配置Nginx等步骤。下面是一个基本示例：&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;```Dockerfile&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;# 使用官方Node.js镜像作为构建阶段的基础镜像&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;FROM node:latest AS build-stage&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;# 设置工作目录&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;WORKDIR /app/vue-storefront&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;# 将主机上的package.json和package-lock.json复制到容器中以安装依赖&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;COPY package*.json ./&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;# 安装项目依赖&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;RUN npm ci&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;# 复制剩余源代码到容器&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;COPY . .&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;# 执行构建命令（根据Vue Storefront的实际构建命令调整）&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;RUN npm run build&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;# 部署阶段使用nginx作为基础镜像&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;FROM nginx:alpine&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;# 删除默认配置文件&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;RUN rm -rf /etc/nginx/conf.d/default.conf&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;# 将nginx配置文件复制到容器内&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;COPY default.conf /etc/nginx/conf.d/&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;# 将编译好的Vue Storefront静态资源复制到nginx的web服务目录&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;COPY --from=build-stage /app/vue-storefront/dist /usr/share/nginx/html&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;# 暴露端口&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;EXPOSE 80&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;# 启动nginx&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;CMD [&amp;quot;nginx&amp;quot;, &amp;quot;-g&amp;quot;, &amp;quot;daemon off;&amp;quot;]&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;```&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;### 2. 编写Nginx配置文件 `default.conf`&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;创建一个名为 `default.conf` 的文件在项目根目录下，它将被复制到容器内的Nginx配置目录中：&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;```conf&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;server {&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp; &amp;nbsp; listen 80;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp; &amp;nbsp; server_name storefront.example.com; # 替换为实际域名或服务器IP地址&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp; &amp;nbsp; location / {&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; root&amp;nbsp; &amp;nbsp;/usr/share/nginx/html;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; index&amp;nbsp; index.html;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try_files $uri $uri/ /index.html;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gzip on;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gzip_min_length 1k;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gzip_comp_level 5;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp; &amp;nbsp; error_page&amp;nbsp; &amp;nbsp;500 502 503 504&amp;nbsp; /50x.html;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp; &amp;nbsp; location = /50x.html {&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; root&amp;nbsp; &amp;nbsp;/usr/share/nginx/html;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;```&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;### 3. 构建Docker镜像&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;确保您的Vue Storefront项目已正确构建并准备好部署后，在终端中切换至包含Dockerfile的项目根目录，然后构建镜像：&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;```sh&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;docker build -t vue-storefront-app .&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;```&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;### 4. 运行Docker容器&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;构建完成后，运行Docker容器并将宿主机端口映射到容器内：&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;```sh&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;docker run -d -p 8080:80 --name vue-storefront-instance vue-storefront-app&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;```&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;这样就通过Docker创建了一个包含Vue Storefront运行环境的容器，并且可以在本地通过 `http://localhost:8080` 访问应用（如果映射的是8080端口）。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;请根据实际情况调整上述步骤中的配置和命令。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Fri, 26 Jan 2024 23:01:41 +0800</pubDate></item><item><title>1. Docker Compose 和 Dockerfile 的区别</title><link>https://lxf.net/?id=82</link><description>&lt;h3 id=&quot;258bcc&quot; style=&quot;box-sizing: border-box; font-family: Lato, &amp;quot;Helvetica Neue&amp;quot;, Arial, Helvetica, sans-serif; padding: 0px; line-height: 1.43; margin: 1.2em 0px 20px; font-size: 1.2em; position: relative; color: rgb(99, 107, 111); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. Docker Compose 和 Dockerfile 的区别&lt;/h3&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 30px; margin-top: 0px; margin-bottom: 10px; color: rgb(99, 107, 111); font-family: Helvetica, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Noto Sans&amp;quot;, Roboto, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif; font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;Docker Compose 和 Dockerfile 都是用于构建和管理 Docker 容器的工具，但它们有着不同的作用和使用方式。&lt;/p&gt;&lt;ul style=&quot;box-sizing: border-box; margin-bottom: 10px; padding: 10px 20px 10px 30px; line-height: 30px; color: rgb(125, 134, 136); font-family: Helvetica, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Noto Sans&amp;quot;, Roboto, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif; font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 30px; margin-top: 16px; margin-bottom: 10px;&quot;&gt;Dockerfile 是一个文本文件，用于定义 Docker 镜像的构建规则。它包含了一系列的指令，用于指定容器运行时的操作系统、软件环境、应用程序、文件拷贝等信息。通过 Dockerfile，可以构建出一个自定义的 Docker 镜像，使得该镜像能够在任意支持 Docker 的主机上运行。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 30px; margin-top: 16px; margin-bottom: 10px;&quot;&gt;Docker Compose 则是一个用于定义和运行多个 Docker 容器的工具。通过 Docker Compose，可以使用 YAML 文件来描述应用程序的服务、网络、存储等资源，并使用一个命令来启动、停止、重启和管理整个应用程序。在一个 Docker Compose 的配置文件中，可以定义多个 Docker 容器，每个容器都可以使用自定义的 Docker 镜像，并可以指定容器之间的依赖关系和通信方式。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 30px; margin-top: 0px; margin-bottom: 10px; color: rgb(99, 107, 111); font-family: Helvetica, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Noto Sans&amp;quot;, Roboto, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif; font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;因此，Dockerfile 更多地用于创建和定制 Docker 镜像，而 Docker Compose 更多地用于管理多个 Docker 容器，让它们能够协同工作来构建一个完整的应用程序。&lt;/p&gt;&lt;h3 id=&quot;0edde5&quot; style=&quot;box-sizing: border-box; font-family: Lato, &amp;quot;Helvetica Neue&amp;quot;, Arial, Helvetica, sans-serif; padding: 0px; line-height: 1.43; margin: 1.2em 0px 20px; font-size: 1.2em; position: relative; color: rgb(99, 107, 111); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a name=&quot;2.举例说明&quot; class=&quot;reference-link&quot; style=&quot;box-sizing: border-box; background: transparent; color: rgb(23, 117, 204); position: relative;&quot;&gt;&lt;/a&gt;&lt;span class=&quot;header-link octicon octicon-link&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;2. 举例说明&lt;/h3&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 30px; margin-top: 0px; margin-bottom: 10px; color: rgb(99, 107, 111); font-family: Helvetica, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Noto Sans&amp;quot;, Roboto, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif; font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;假设你要在 CentOS 7 系统上运行一个 PHP Web 应用程序，并使用 Nginx 作为 Web 服务器，可以使用 Dockerfile 和 Docker Compose 来实现。&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 30px; margin-top: 0px; margin-bottom: 10px; color: rgb(99, 107, 111); font-family: Helvetica, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Noto Sans&amp;quot;, Roboto, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif; font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;box-sizing: border-box; font-weight: 700;&quot;&gt;使用 Dockerfile，可以创建一个自定义的 PHP+Nginx 镜像，例如：&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;box-sizing: border-box; color: rgb(99, 107, 111); font-family: Helvetica, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Noto Sans&amp;quot;, Roboto, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif; font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); position: relative;&quot;&gt;&lt;pre class=&quot;  language-shell&quot; style=&quot;box-sizing: border-box; overflow: auto; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-radius: 0px; margin: 1.5em -35px; padding: 1.5em 35px; line-height: 1.5; border: 1px solid rgb(239, 239, 239); color: rgb(248, 248, 242); overflow-wrap: normal; background-color: rgb(56, 69, 72); box-shadow: rgba(199, 199, 199, 0.16) 0px 2px 5px 0px, rgba(242, 242, 242, 0.12) 0px 2px 10px 0px; hyphens: none; tab-size: 4; word-break: inherit; word-spacing: normal;&quot;&gt;FROM&amp;nbsp;php:7.4-fpm
RUN&amp;nbsp;apt-get&amp;nbsp;update&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;apt-get&amp;nbsp;install&amp;nbsp;-y&amp;nbsp;nginx
COPY&amp;nbsp;nginx.conf&amp;nbsp;/etc/nginx/nginx.conf
WORKDIR&amp;nbsp;/var/www/html
COPY&amp;nbsp;src/&amp;nbsp;/var/www/html/
EXPOSE&amp;nbsp;80
CMD&amp;nbsp;[&amp;quot;nginx&amp;quot;,&amp;nbsp;&amp;quot;-g&amp;quot;,&amp;nbsp;&amp;quot;daemon&amp;nbsp;off;&amp;quot;]&lt;/pre&gt;&lt;/div&gt;&lt;blockquote style=&quot;box-sizing: border-box; line-height: 30px; border-left: none; color: rgb(135, 150, 168); font-size: 15px; padding: 1rem; background-color: rgb(245, 248, 252); font-family: Helvetica, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Noto Sans&amp;quot;, Roboto, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif; text-wrap: wrap; margin: 20px 0px !important;&quot;&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 30px; margin-top: 0px; margin-bottom: 0px;&quot;&gt;该 Dockerfile 基于官方的 PHP 7.4-fpm 镜像，安装了 Nginx，并将应用程序代码复制到容器的 /var/www/html 目录下。该镜像还将容器的 80 端口映射到宿主机，以便可以从宿主机通过浏览器访问该应用程序。&lt;/p&gt;&lt;/blockquote&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 30px; margin-top: 0px; margin-bottom: 10px; color: rgb(99, 107, 111); font-family: Helvetica, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Noto Sans&amp;quot;, Roboto, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif; font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;使用 Docker Compose，可以定义一个 YAML 文件，来同时启动 PHP 和 Nginx 两个容器，并将它们连接到同一个 Docker 网络中。例如：&lt;/p&gt;&lt;div style=&quot;box-sizing: border-box; color: rgb(99, 107, 111); font-family: Helvetica, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Noto Sans&amp;quot;, Roboto, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif; font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255); position: relative;&quot;&gt;&lt;pre class=&quot;  language-yaml&quot; style=&quot;box-sizing: border-box; overflow: auto; font-family: Consolas, Monaco, &amp;quot;Andale Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, monospace; font-size: 1em; border-radius: 0px; margin: 1.5em -35px; padding: 1.5em 35px; line-height: 1.5; border: 1px solid rgb(239, 239, 239); color: rgb(248, 248, 242); overflow-wrap: normal; background-color: rgb(56, 69, 72); box-shadow: rgba(199, 199, 199, 0.16) 0px 2px 5px 0px, rgba(242, 242, 242, 0.12) 0px 2px 10px 0px; hyphens: none; tab-size: 4; word-break: inherit; word-spacing: normal;&quot;&gt;`version:&amp;nbsp;&amp;#39;3&amp;#39;services:
&amp;nbsp;&amp;nbsp;php:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;image:&amp;nbsp;php:7.4-fpm&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;volumes:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;./src:/var/www/html&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;networks:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;my-network&amp;nbsp;&amp;nbsp;nginx:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;image:&amp;nbsp;nginx:latest&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ports:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;&amp;quot;80:80&amp;quot;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;volumes:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;./nginx.conf:/etc/nginx/nginx.conf&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;networks:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;my-networknetworks:
&amp;nbsp;&amp;nbsp;my-network:`&lt;/pre&gt;&lt;/div&gt;&lt;blockquote style=&quot;box-sizing: border-box; line-height: 30px; border-left: none; color: rgb(135, 150, 168); font-size: 15px; padding: 1rem; background-color: rgb(245, 248, 252); font-family: Helvetica, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Noto Sans&amp;quot;, Roboto, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif; text-wrap: wrap; margin: 20px 0px !important;&quot;&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 30px; margin-top: 0px; margin-bottom: 0px;&quot;&gt;该 Docker Compose 文件定义了两个服务：一个是基于官方的 PHP 7.4-fpm 镜像，另一个是基于官方的 Nginx 镜像。它们都挂载了本地的应用程序代码和 Nginx 配置文件，并将它们连接到一个名为 my-network 的 Docker 网络中。此外，Nginx 容器的 80 端口也映射到了宿主机的 80 端口上。&lt;/p&gt;&lt;/blockquote&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 30px; margin-top: 0px; margin-bottom: 10px; color: rgb(99, 107, 111); font-family: Helvetica, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Noto Sans&amp;quot;, Roboto, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif; font-size: 15px; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;总的来说，Dockerfile 更适合创建和定制单个镜像，而 Docker Compose 更适合管理多个容器并将它们组合在一起构建一个完整的应用程序。在这个例子中，使用 Dockerfile 可以创建一个自定义的 PHP+Nginx 镜像，而使用 Docker Compose 可以同时启动 PHP 和 Nginx 两个容器，并将它们连接到同一个 Docker 网络中。&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Sat, 06 Jan 2024 19:15:34 +0800</pubDate></item><item><title>从零构建一个基于 Docker 的 Laravel 应用</title><link>https://lxf.net/?id=81</link><description>&lt;h2 style=&quot;margin: 0px 0px 1rem; padding: 0px; outline: 0px; font-weight: 400; font-size: 24px; max-width: 100%; box-sizing: border-box; color: rgb(21, 153, 87); line-height: 1.35; text-wrap: wrap; text-align: center; visibility: visible; overflow-wrap: break-word !important;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-size: 20px; visibility: visible;&quot;&gt;Docker 简介&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; font-size: 16px; white-space: pre-line; line-height: 30px; color: rgb(74, 74, 74); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; visibility: visible; overflow-wrap: break-word !important;&quot;&gt;其实在这样的一个云计算时代, Docker 早就已被人众所周知了,它改变了传统物理机的虚拟化方式,使得机器的资源得到了高效的利用. 因为运行在 Docker 中的应用实际上就是运行在宿主机上的, 所以它是不需要进行硬件层面的虚拟化以及运行一个完整操作系统来支持. 于是在应用代码的执行效率, 内存的使用以及文件的读取速度都比传统虚拟化的方式来的强. 而且它的启动速度非常快,往往都是在毫秒级的,可以大大的节约了开发测试以及部署的时间.
其实对于开发人员来说, Docker 一个更大的意义就是可以保证拥有一致的运行环境, 程序员最常见的就是在开发测试部署环境不一致的情况下, 经常会触发一些莫名奇妙的BUG, 为了杜绝「这段代码在我机器上没问题啊」这类的问题,这也是我们要去学习 Docker 的理由之一.&lt;/p&gt;&lt;h2 style=&quot;margin: 1.5rem 0px 1rem; padding: 0px; outline: 0px; font-weight: 400; font-size: 24px; max-width: 100%; box-sizing: border-box; color: rgb(21, 153, 87); line-height: 1.35; text-wrap: wrap; text-align: center; visibility: visible; overflow-wrap: break-word !important;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-size: 20px; visibility: visible;&quot;&gt;如何学习 Docker&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; font-size: 16px; white-space: pre-line; line-height: 30px; color: rgb(74, 74, 74); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; visibility: visible; overflow-wrap: break-word !important;&quot;&gt;网上充斥着大量的关于 Docker 各个方面的教程和资料, 而且由于 Docker 的飞速发展, 很多教程其实都过时了, 对于初学者来说很难去分辨把握, 随之而来的就是一系列的坑与问题, 渐渐的磨灭了学习者的动力. 其实学习一门新技术最好的永远都是从官方的文档入手, 然后就是 GitHub 上面一个技术人员的学习笔记, 最重要的是要去摸索实践, 并且做好学习笔记. 其实学习一门新技术, 如果有正确的学习方法是可以少走很多弯路的, 这个有机会会写一篇心得.&lt;/p&gt;&lt;h2 style=&quot;margin: 1.5rem 0px 1rem; padding: 0px; outline: 0px; font-weight: 400; font-size: 24px; max-width: 100%; box-sizing: border-box; color: rgb(21, 153, 87); line-height: 1.35; text-wrap: wrap; text-align: center; visibility: visible; overflow-wrap: break-word !important;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-size: 20px; visibility: visible;&quot;&gt;快速入门&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; font-size: 16px; white-space: pre-line; line-height: 30px; color: rgb(74, 74, 74); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; visibility: visible; overflow-wrap: break-word !important;&quot;&gt;这里限制于篇幅和作者水平, 不会大谈 Docker 底层原理以及技术实现,也不会教你如何写一个繁琐的 Dockerfile, 而是会从一个普通开发者的身份入手, 带你从零搭建一个基于 Docker 的 Laravel 应用.我们的系统环境使用的是 Ubuntu17.04, 其他系统也差不多,当然 Window 的话可能就要另当别论了.&lt;/p&gt;&lt;h2 style=&quot;margin: 1.5rem 0px 1rem; padding: 0px; outline: 0px; font-weight: 400; font-size: 16px; max-width: 100%; box-sizing: border-box; color: rgb(62, 62, 62); text-wrap: wrap; background-color: rgb(255, 255, 255); line-height: 1.35; visibility: visible; overflow-wrap: break-word !important;&quot;&gt;&lt;section class=&quot;&quot; style=&quot;margin: 5px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; color: rgb(255, 255, 255); display: inline-block; line-height: 28px; background-color: rgb(30, 155, 232); visibility: visible;&quot;&gt;&amp;nbsp;&lt;/section&gt;&lt;section style=&quot;margin: 0px; padding: 5px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; display: inline-block; visibility: visible;&quot;&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; color: #1E9BE8; visibility: visible;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-size: 18px; visibility: visible;&quot;&gt;安装 Docker&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/section&gt;&lt;/h2&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; font-size: 16px; white-space: pre-line; line-height: 30px; color: rgb(74, 74, 74); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; visibility: visible; overflow-wrap: break-word !important;&quot;&gt;在 Ubuntu 下 Docker 的安装和常规的软件一样,但是由于中国特色,还有有很多要注意的点,待会会详细说明. Docker 的安装方式有很多种，这里建议使用官方的一键安装脚本来，避免一系列繁琐的操作。&lt;/p&gt;&lt;h4 style=&quot;margin: 1.5rem 0px 1rem; padding: 0px; outline: 0px; font-weight: 400; font-size: 18px; max-width: 100%; box-sizing: border-box; color: rgb(21, 153, 87); line-height: 1.35; text-wrap: wrap; overflow-wrap: break-word !important;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-size: 16px;&quot;&gt;1. 下载安装&lt;/span&gt;&lt;/h4&gt;&lt;pre class=&quot;&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 8px 0px 6px; outline: 0px; max-width: 100%; box-sizing: border-box; background-color: rgb(47, 54, 64); border-radius: 0px; overflow-y: auto; color: rgb(80, 97, 109); font-size: 10px; line-height: 12px; overflow-wrap: break-word !important;&quot;&gt;&amp;nbsp;&amp;nbsp;curl&amp;nbsp;-fsSL&amp;nbsp;get.docker.com&amp;nbsp;-o&amp;nbsp;get-docker.sh&lt;/pre&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; font-size: 16px; white-space: pre-line; line-height: 30px; color: rgb(74, 74, 74); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; overflow-wrap: break-word !important;&quot;&gt;然后安装，并且选择从阿里镜像源下载：&lt;/p&gt;&lt;pre class=&quot;&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 8px 0px 6px; outline: 0px; max-width: 100%; box-sizing: border-box; background-color: rgb(47, 54, 64); border-radius: 0px; overflow-y: auto; color: rgb(80, 97, 109); font-size: 10px; line-height: 12px; overflow-wrap: break-word !important;&quot;&gt;sudo&amp;nbsp;sh&amp;nbsp;get-docker.sh&amp;nbsp;--mirror&amp;nbsp;Aliyun&lt;/pre&gt;&lt;h4 style=&quot;margin: 1.5rem 0px 1rem; padding: 0px; outline: 0px; font-weight: 400; font-size: 18px; max-width: 100%; box-sizing: border-box; color: rgb(21, 153, 87); line-height: 1.35; text-wrap: wrap; overflow-wrap: break-word !important;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-size: 16px;&quot;&gt;2. 基本配置&lt;/span&gt;&lt;/h4&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; font-size: 16px; white-space: pre-line; line-height: 30px; color: rgb(74, 74, 74); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; overflow-wrap: break-word !important;&quot;&gt;其实安装后基本上就可以使用了，主要是配置一些镜像源和用户组。配置镜像源的目的不多说，用户组主要是为了再使用的时候不用使用超级管理员权限即可运行。&lt;/p&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: square;&quot;&gt;&lt;li&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; overflow-wrap: break-word !important;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; color: #4A4A4A; line-height: 22px; overflow-wrap: break-word !important;&quot;&gt;加入用户组&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;pre class=&quot;&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 8px 0px 6px; outline: 0px; max-width: 100%; box-sizing: border-box; background-color: rgb(47, 54, 64); border-radius: 0px; overflow-y: auto; color: rgb(80, 97, 109); font-size: 10px; line-height: 12px; overflow-wrap: break-word !important;&quot;&gt;sudo&amp;nbsp;usermod&amp;nbsp;-aG&amp;nbsp;docker&amp;nbsp;$USER&lt;/pre&gt;&lt;blockquote style=&quot;margin: 1em 0px 1.2em; padding: 15px 15px 15px 1rem; outline: 0px; border-left: 6px solid rgb(220, 230, 240); color: rgb(129, 145, 152); max-width: 100%; box-sizing: border-box; line-height: 22px; background: rgb(242, 247, 251); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; text-wrap: wrap; overflow-wrap: break-word !important;&quot;&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; white-space-collapse: preserve-breaks; line-height: 30px; color: rgb(74, 74, 74); overflow-wrap: break-word !important;&quot;&gt;PS. 配置用户组后，可能还是会出现还是提示没有权限的情况，这时重启机器即可&lt;/p&gt;&lt;/blockquote&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: square;&quot;&gt;&lt;li&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; overflow-wrap: break-word !important;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; color: #4A4A4A; line-height: 22px; overflow-wrap: break-word !important;&quot;&gt;配置镜像源&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;pre class=&quot;&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 8px 0px 6px; outline: 0px; max-width: 100%; box-sizing: border-box; background-color: rgb(47, 54, 64); border-radius: 0px; overflow-y: auto; color: rgb(80, 97, 109); font-size: 10px; line-height: 12px; overflow-wrap: break-word !important;&quot;&gt;sudo&amp;nbsp;mkdir&amp;nbsp;-p&amp;nbsp;/etc/dockersudo&amp;nbsp;tee&amp;nbsp;/etc/docker/daemon.json&amp;nbsp;&amp;lt;&amp;lt;-&amp;#39;EOF&amp;#39;{&amp;nbsp;&amp;nbsp;&amp;quot;registry-mirrors&amp;quot;:&amp;nbsp;[&amp;quot;https://be62qq2e.mirror.aliyuncs.com&amp;quot;]}EOF&lt;/pre&gt;&lt;blockquote style=&quot;margin: 1em 0px 1.2em; padding: 15px 15px 15px 1rem; outline: 0px; border-left: 6px solid rgb(220, 230, 240); color: rgb(129, 145, 152); max-width: 100%; box-sizing: border-box; line-height: 22px; background: rgb(242, 247, 251); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; text-wrap: wrap; overflow-wrap: break-word !important;&quot;&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; white-space-collapse: preserve-breaks; line-height: 30px; color: rgb(74, 74, 74); overflow-wrap: break-word !important;&quot;&gt;PS. 这里的镜像源是我自己阿里云的，同学们可以自行去阿里云获取专有镜像源地址&lt;/p&gt;&lt;/blockquote&gt;&lt;ul class=&quot; list-paddingleft-2&quot; style=&quot;list-style-type: square;&quot;&gt;&lt;li&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; overflow-wrap: break-word !important;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; color: #4A4A4A; line-height: 22px; overflow-wrap: break-word !important;&quot;&gt;重启&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;pre class=&quot;&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 8px 0px 6px; outline: 0px; max-width: 100%; box-sizing: border-box; background-color: rgb(47, 54, 64); border-radius: 0px; overflow-y: auto; color: rgb(80, 97, 109); font-size: 10px; line-height: 12px; overflow-wrap: break-word !important;&quot;&gt;sudo&amp;nbsp;systemctl&amp;nbsp;daemon-reloadsudo&amp;nbsp;systemctl&amp;nbsp;restart&amp;nbsp;docker&lt;/pre&gt;&lt;h4 style=&quot;margin: 1.5rem 0px 1rem; padding: 0px; outline: 0px; font-weight: 400; font-size: 18px; max-width: 100%; box-sizing: border-box; color: rgb(21, 153, 87); line-height: 1.35; text-wrap: wrap; overflow-wrap: break-word !important;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-size: 16px;&quot;&gt;3. 安装docker-compose&lt;/span&gt;&lt;/h4&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; font-size: 16px; white-space: pre-line; line-height: 30px; color: rgb(74, 74, 74); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; overflow-wrap: break-word !important;&quot;&gt;&lt;code class=&quot;&quot; style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; background: rgb(243, 241, 241); color: rgb(88, 88, 88); line-height: 18px;&quot;&gt;&lt;span class=&quot;&quot; style=&quot;margin: 0px; padding: 0px 2px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; display: inline-block; font-size: 14px;&quot;&gt;docker&lt;/span&gt;&lt;span class=&quot;&quot; style=&quot;margin: 0px; padding: 0px 2px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; display: inline-block; font-size: 14px;&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;&quot; style=&quot;margin: 0px; padding: 0px 2px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; display: inline-block; font-size: 14px;&quot;&gt;compose&lt;/span&gt;&lt;/code&gt;类似一个包管理工具，方便我们管理镜像。&lt;/p&gt;&lt;pre class=&quot;&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 8px 0px 6px; outline: 0px; max-width: 100%; box-sizing: border-box; background-color: rgb(47, 54, 64); border-radius: 0px; overflow-y: auto; color: rgb(80, 97, 109); font-size: 10px; line-height: 12px; overflow-wrap: break-word !important;&quot;&gt;curl&amp;nbsp;-L&amp;nbsp;https://github.com/docker/compose/releases/download/1.17.1/run.sh&amp;nbsp;&amp;gt;&amp;nbsp;/usr/local/bin/docker-composechmod&amp;nbsp;+x&amp;nbsp;/usr/local/bin/docker-compose&lt;/pre&gt;&lt;h2 style=&quot;margin: 1.5rem 0px 1rem; padding: 0px; outline: 0px; font-weight: 400; font-size: 16px; max-width: 100%; box-sizing: border-box; text-wrap: wrap; color: rgb(62, 62, 62); background-color: rgb(255, 255, 255); line-height: 1.35; overflow-wrap: break-word !important;&quot;&gt;&lt;section class=&quot;&quot; style=&quot;margin: 5px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; color: rgb(255, 255, 255); display: inline-block; line-height: 28px; background-color: rgb(30, 155, 232);&quot;&gt;&amp;nbsp;&lt;/section&gt;&lt;section style=&quot;margin: 0px; padding: 5px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; display: inline-block;&quot;&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; overflow-wrap: break-word !important;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; color: #1E9BE8;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-size: 18px;&quot;&gt;基本概念&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/section&gt;&lt;/h2&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; font-size: 16px; white-space: pre-line; line-height: 30px; color: rgb(74, 74, 74); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; overflow-wrap: break-word !important;&quot;&gt;Docker 有两个很重要的基本概念就是镜像和容器. 这两个其实就类似面向对象中的类和实例. 镜像构建起来后就是容器,然后容器可以启动停止,对于运行于容器中的应用在运行过程中产生的数据,实际上是可以保留下来的,只要不销毁容器. 如果销毁或者重新构建容器后数据自然就不存在了,所以官方建议用挂载的方式来持久化, 接下来会说到.&lt;/p&gt;&lt;h2 style=&quot;margin: 1.5rem 0px 1rem; padding: 0px; outline: 0px; font-weight: 400; font-size: 16px; max-width: 100%; box-sizing: border-box; text-wrap: wrap; color: rgb(62, 62, 62); background-color: rgb(255, 255, 255); line-height: 1.35; overflow-wrap: break-word !important;&quot;&gt;&lt;section class=&quot;&quot; style=&quot;margin: 5px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; color: rgb(255, 255, 255); display: inline-block; line-height: 28px; background-color: rgb(30, 155, 232);&quot;&gt;&amp;nbsp;&lt;/section&gt;&lt;section style=&quot;margin: 0px; padding: 5px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; display: inline-block;&quot;&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; overflow-wrap: break-word !important;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; color: #1E9BE8;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-size: 18px;&quot;&gt;docker-compose&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/section&gt;&lt;/h2&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; font-size: 16px; white-space: pre-line; line-height: 30px; color: rgb(74, 74, 74); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; overflow-wrap: break-word !important;&quot;&gt;docker-compose 可以说是真正的让 Docker 现代化了. 它就类似于 PHP 的 Composer 包管理工具一样, 是用来管理多个镜像的. 它极大的降低了学习 Docker 的难度. 我们在日常的开发中, 经常会碰到需要多个容器相互配合来完成某项任务的情况,比如 Web 容器和数据库容器之间的通信,我们可以单独的把一个项目中需要的所有容器和配置写到一个 &lt;code class=&quot;&quot; style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; background: rgb(243, 241, 241); color: rgb(88, 88, 88); line-height: 18px;&quot;&gt;&lt;span class=&quot;&quot; style=&quot;margin: 0px; padding: 0px 2px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; display: inline-block; font-size: 14px;&quot;&gt;docker&lt;/span&gt;&lt;span class=&quot;&quot; style=&quot;margin: 0px; padding: 0px 2px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; display: inline-block; font-size: 14px;&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;&quot; style=&quot;margin: 0px; padding: 0px 2px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; display: inline-block; font-size: 14px;&quot;&gt;compose&lt;/span&gt;&lt;span class=&quot;&quot; style=&quot;margin: 0px; padding: 0px 2px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; display: inline-block; font-size: 14px;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;&quot; style=&quot;margin: 0px; padding: 0px 2px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; display: inline-block; font-size: 14px;&quot;&gt;yml&lt;/span&gt;&lt;/code&gt; 文件中,来统一管理.来看一下一个简单的配置文件格式:&lt;/p&gt;&lt;pre class=&quot;&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 8px 0px 6px; outline: 0px; max-width: 100%; box-sizing: border-box; background-color: rgb(47, 54, 64); border-radius: 0px; overflow-y: auto; color: rgb(80, 97, 109); font-size: 10px; line-height: 12px; overflow-wrap: break-word !important;&quot;&gt;version:&amp;nbsp;&amp;#39;3&amp;#39;services:&amp;nbsp;&amp;nbsp;nginx:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;build:&amp;nbsp;.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ports:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;&amp;quot;80:80&amp;quot;&amp;nbsp;&amp;nbsp;redis:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;image:&amp;nbsp;&amp;quot;redis:alpine&amp;quot;&lt;/pre&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; font-size: 16px; white-space: pre-line; line-height: 30px; color: rgb(74, 74, 74); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; overflow-wrap: break-word !important;&quot;&gt;一个项目可以由多个服务(容器)工程，而 docker-compose 是面向项目进行管理.&lt;/p&gt;&lt;h2 style=&quot;margin: 1.5rem 0px 1rem; padding: 0px; outline: 0px; font-weight: 400; font-size: 16px; max-width: 100%; box-sizing: border-box; text-wrap: wrap; color: rgb(62, 62, 62); background-color: rgb(255, 255, 255); line-height: 1.35; overflow-wrap: break-word !important;&quot;&gt;&lt;section class=&quot;&quot; style=&quot;margin: 5px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; color: rgb(255, 255, 255); display: inline-block; line-height: 28px; background-color: rgb(30, 155, 232);&quot;&gt;&amp;nbsp;&lt;/section&gt;&lt;section style=&quot;margin: 0px; padding: 5px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; display: inline-block;&quot;&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; overflow-wrap: break-word !important;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; color: #1E9BE8;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-size: 18px;&quot;&gt;文件系统和网络&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/section&gt;&lt;/h2&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; font-size: 16px; white-space: pre-line; line-height: 30px; color: rgb(74, 74, 74); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; overflow-wrap: break-word !important;&quot;&gt;这是 Docker 比较复杂的一块,简单介绍一下. Docker 里面的文件系统其实很真实宿主机的一样, 可以用同样的命令去操作, 只是要注意的一点就是我们在容器中运行的应用配置文件的路径全部都是基于 Docker 的,不是基于宿主机的,很多文件不存在的问题都是这个引起来的.比如我们在运行一个 Nginx 容器和 PHP-FPM 容器的时候,不仅要把宿主机的项目路径映射到 Nginx 容器中,还要映射到 PHP-FPM 容器中,否则就会是一系列的 File not found.
Docker 中的网络是有多种模式的, 在默认情况下是会创建一个虚拟网桥的, 实际上是 Linux 的一个 bridge，它会在挂载到它的网口之间进行转发。并且会随机分配一个本地未被使用的属于 172.17.0.0/16 网段的 IP 到各个容器中.这是一个网络拓扑图:&lt;/p&gt;&lt;h2 style=&quot;margin: 1.5rem 0px 1rem; padding: 0px; outline: 0px; font-weight: 400; font-size: 24px; max-width: 100%; box-sizing: border-box; color: rgb(21, 153, 87); line-height: 1.35; text-wrap: wrap; text-align: center; overflow-wrap: break-word !important;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-size: 20px;&quot;&gt;部署 Laravel 应用&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; font-size: 16px; white-space: pre-line; line-height: 30px; color: rgb(74, 74, 74); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; overflow-wrap: break-word !important;&quot;&gt;基本介绍后我们会通过一个简单的实例来加深理解, 就是部署一个 Laravel 应用. Web 服务器我们会使用 Nginx, 并且通过 PHP-FPM 来处理动态请求,用 MySQL 来存储数据, Redis 作为我们的缓存和队列驱动. 不同于网上的通过 Supervisor 来把所有服务运行在同一个容器中,我们会把这四个服务运行在四个容器中,这也是官方推荐的一种做法,然后我们会通过 docker-compose 来管理所有的服务(容器).&lt;/p&gt;&lt;h2 style=&quot;margin: 1.5rem 0px 1rem; padding: 0px; outline: 0px; font-weight: 400; font-size: 16px; max-width: 100%; box-sizing: border-box; text-wrap: wrap; color: rgb(62, 62, 62); background-color: rgb(255, 255, 255); line-height: 1.35; overflow-wrap: break-word !important;&quot;&gt;&lt;section class=&quot;&quot; style=&quot;margin: 5px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; color: rgb(255, 255, 255); display: inline-block; line-height: 28px; background-color: rgb(30, 155, 232);&quot;&gt;&amp;nbsp;&lt;/section&gt;&lt;section style=&quot;margin: 0px; padding: 5px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; display: inline-block;&quot;&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; overflow-wrap: break-word !important;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; color: #1E9BE8;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-size: 18px;&quot;&gt;Nginx&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/section&gt;&lt;/h2&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; font-size: 16px; white-space: pre-line; line-height: 30px; color: rgb(74, 74, 74); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; overflow-wrap: break-word !important;&quot;&gt;直接上配置文件：&lt;/p&gt;&lt;pre class=&quot;&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 8px 0px 6px; outline: 0px; max-width: 100%; box-sizing: border-box; background-color: rgb(47, 54, 64); border-radius: 0px; overflow-y: auto; color: rgb(80, 97, 109); font-size: 10px; line-height: 12px; overflow-wrap: break-word !important;&quot;&gt;version:&amp;nbsp;&amp;#39;2&amp;#39;services:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;nginx:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;image:&amp;nbsp;nginx&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ports:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;&amp;quot;8090:80&amp;quot;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;links:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;php-fpm&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;volumes:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;./nginx/www:/var/www/html&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;./nginx/sites:/etc/nginx/sites-enabled&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;./nginx/nginx.conf:/etc/nginx/nginx.conf&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;command:&amp;nbsp;[nginx-debug,&amp;nbsp;&amp;#39;-g&amp;#39;,&amp;nbsp;&amp;#39;daemon&amp;nbsp;off;&amp;#39;]&lt;/pre&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; font-size: 16px; white-space: pre-line; line-height: 30px; color: rgb(74, 74, 74); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; overflow-wrap: break-word !important;&quot;&gt;其中的 services 节点下每一个表示一个服务；然后 nginx 这是个服务名可以随便取；image 指定使用哪个镜像来构建; ports 表示要暴露的端口，其中 8090 是指宿主机的端口，80 是指容器中的端口；volumes 表示挂载的目录和文件，我们这里挂载了代码目录，虚拟主机目录以及配置文件；command 表示容器启动后要运行的命令。我们还要在当前目录下创建一个 nginx 的目录，用来存放一系列的文件，还需要把配置文件新建并且写入配置内容(具体配置内容可以去官网查看，这里不说明)，最后的目录结构是这样&lt;/p&gt;&lt;pre class=&quot;&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 8px 0px 6px; outline: 0px; max-width: 100%; box-sizing: border-box; background-color: rgb(47, 54, 64); border-radius: 0px; overflow-y: auto; color: rgb(80, 97, 109); font-size: 10px; line-height: 12px; overflow-wrap: break-word !important;&quot;&gt;Docker&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;docker-compose.yml&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;nginx&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;www&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;sites&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;nginx.conf&lt;/pre&gt;&lt;blockquote style=&quot;margin: 1em 0px 1.2em; padding: 15px 15px 15px 1rem; outline: 0px; border-left: 6px solid rgb(220, 230, 240); color: rgb(129, 145, 152); max-width: 100%; box-sizing: border-box; line-height: 22px; background: rgb(242, 247, 251); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; text-wrap: wrap; overflow-wrap: break-word !important;&quot;&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; white-space-collapse: preserve-breaks; line-height: 30px; color: rgb(74, 74, 74); overflow-wrap: break-word !important;&quot;&gt;可以把日志一起挂载，这里没有表述出来&lt;/p&gt;&lt;/blockquote&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; font-size: 16px; white-space: pre-line; line-height: 30px; color: rgb(74, 74, 74); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; overflow-wrap: break-word !important;&quot;&gt;然后执行启动容器的命令：&lt;/p&gt;&lt;pre class=&quot;&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 8px 0px 6px; outline: 0px; max-width: 100%; box-sizing: border-box; background-color: rgb(47, 54, 64); border-radius: 0px; overflow-y: auto; color: rgb(80, 97, 109); font-size: 10px; line-height: 12px; overflow-wrap: break-word !important;&quot;&gt;docker-compose&amp;nbsp;up&amp;nbsp;nginx&lt;/pre&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; font-size: 16px; white-space: pre-line; line-height: 30px; color: rgb(74, 74, 74); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; overflow-wrap: break-word !important;&quot;&gt;以上不会在后台启动，而是会直接在当前的 shell 上，然后我们访问应该就可以看到 Welcome to nginx！&lt;/p&gt;&lt;h2 style=&quot;margin: 1.5rem 0px 1rem; padding: 0px; outline: 0px; font-weight: 400; font-size: 16px; max-width: 100%; box-sizing: border-box; text-wrap: wrap; color: rgb(62, 62, 62); background-color: rgb(255, 255, 255); line-height: 1.35; overflow-wrap: break-word !important;&quot;&gt;&lt;section class=&quot;&quot; style=&quot;margin: 5px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; color: rgb(255, 255, 255); display: inline-block; line-height: 28px; background-color: rgb(30, 155, 232);&quot;&gt;&amp;nbsp;&lt;/section&gt;&lt;section style=&quot;margin: 0px; padding: 5px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; display: inline-block;&quot;&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; overflow-wrap: break-word !important;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; color: #1E9BE8;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-size: 18px;&quot;&gt;PHP-FPM、Redis、MySQL&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/section&gt;&lt;/h2&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; font-size: 16px; white-space: pre-line; line-height: 30px; color: rgb(74, 74, 74); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; overflow-wrap: break-word !important;&quot;&gt;同理我们再次配置 PHP-FPM，MySQL 以及 Redis 的容器了，具体过程不多讲，这里贴出配置：&lt;/p&gt;&lt;pre class=&quot;&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 8px 0px 6px; outline: 0px; max-width: 100%; box-sizing: border-box; background-color: rgb(47, 54, 64); border-radius: 0px; overflow-y: auto; color: rgb(80, 97, 109); font-size: 10px; line-height: 12px; overflow-wrap: break-word !important;&quot;&gt;&amp;nbsp;&amp;nbsp;php-fpm:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;image:&amp;nbsp;&amp;#39;bitnami/php-fpm:7.1&amp;#39;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;volumes:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;./nginx/www:/var/www/html&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;./php-fpm/php.ini:/bitnami/php/conf/php.ini&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;links:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;mysql&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;redis&amp;nbsp;&amp;nbsp;mysql:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;image:&amp;nbsp;mysql&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;restart:&amp;nbsp;always&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;environment:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;MYSQL_ROOT_PASSWORD:&amp;nbsp;example&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;volumes:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;/var/lib/mysql:/var/lib/mysql&amp;nbsp;&amp;nbsp;redis:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;image:&amp;nbsp;redis&lt;/pre&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; font-size: 16px; white-space: pre-line; line-height: 30px; color: rgb(74, 74, 74); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; overflow-wrap: break-word !important;&quot;&gt;有一点要注意的是，在配置PHP-FPM容器的时候是需要把代码目录也挂载到容器里面的，这一点很容易被遗忘，网上很多教程都没提到，导致最后虽然按照步骤走了但就是跑不起来。其中的 links 就是配置要连接到哪个容器中。比如配置了 Nginx 容器连接到 PHP-FPM 的容器，这样我们在 Nginx 的容器中就可以直接 ping php-fpm,在配置的时候也可以这样 &lt;code class=&quot;&quot; style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; background: rgb(243, 241, 241); color: rgb(88, 88, 88); line-height: 18px;&quot;&gt;&lt;span class=&quot;&quot; style=&quot;margin: 0px; padding: 0px 2px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; display: inline-block; font-size: 14px;&quot;&gt;php&lt;/span&gt;&lt;span class=&quot;&quot; style=&quot;margin: 0px; padding: 0px 2px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; display: inline-block; font-size: 14px;&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;&quot; style=&quot;margin: 0px; padding: 0px 2px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; display: inline-block; font-size: 14px;&quot;&gt;fpm&lt;/span&gt;&lt;span class=&quot;&quot; style=&quot;margin: 0px; padding: 0px 2px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; display: inline-block; font-size: 14px;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;&quot; style=&quot;margin: 0px; padding: 0px 2px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; display: inline-block; font-size: 14px;&quot;&gt;9000&lt;/span&gt;&lt;/code&gt; 来配置了。&lt;/p&gt;&lt;h2 style=&quot;margin: 1.5rem 0px 1rem; padding: 0px; outline: 0px; font-weight: 400; font-size: 16px; max-width: 100%; box-sizing: border-box; text-wrap: wrap; background-color: rgb(255, 255, 255); line-height: 1.35; overflow-wrap: break-word !important;&quot;&gt;&lt;section class=&quot;&quot; style=&quot;margin: 5px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; color: rgb(255, 255, 255); display: inline-block; line-height: 28px; background-color: rgb(30, 155, 232);&quot;&gt;&amp;nbsp;&lt;/section&gt;&lt;section style=&quot;margin: 0px; padding: 5px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; display: inline-block;&quot;&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; overflow-wrap: break-word !important;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; color: #1E9BE8;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-size: 18px;&quot;&gt;配置文件&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/section&gt;&lt;/h2&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; font-size: 16px; white-space: pre-line; line-height: 30px; color: rgb(74, 74, 74); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; overflow-wrap: break-word !important;&quot;&gt;Nginx 的配置文件，然后还要修改一下本地的 hosts 文件。&lt;/p&gt;&lt;pre class=&quot;&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 8px 0px 6px; outline: 0px; max-width: 100%; box-sizing: border-box; background-color: rgb(47, 54, 64); border-radius: 0px; overflow-y: auto; color: rgb(80, 97, 109); font-size: 10px; line-height: 12px; overflow-wrap: break-word !important;&quot;&gt;server&amp;nbsp;{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;listen&amp;nbsp;80;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;listen&amp;nbsp;[::]:80;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;root&amp;nbsp;/var/www/html/laravel/public;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;index&amp;nbsp;index.html&amp;nbsp;index.php;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;server_name&amp;nbsp;laravel-docker.app;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;location&amp;nbsp;/&amp;nbsp;{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;try_files&amp;nbsp;$uri&amp;nbsp;$uri/&amp;nbsp;/index.php?$query_string;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;location&amp;nbsp;~&amp;nbsp;\.php$&amp;nbsp;{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fastcgi_split_path_info&amp;nbsp;^(.+\.php)(/.+)$;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fastcgi_pass&amp;nbsp;php-fpm:9000;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fastcgi_index&amp;nbsp;index.php;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;include&amp;nbsp;fastcgi_params;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fastcgi_param&amp;nbsp;SCRIPT_FILENAME&amp;nbsp;$document_root$fastcgi_script_name;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;h2 style=&quot;margin: 1.5rem 0px 1rem; padding: 0px; outline: 0px; font-weight: 400; font-size: 16px; max-width: 100%; box-sizing: border-box; text-wrap: wrap; background-color: rgb(255, 255, 255); line-height: 1.35; overflow-wrap: break-word !important;&quot;&gt;&lt;section class=&quot;&quot; style=&quot;margin: 5px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; color: rgb(255, 255, 255); display: inline-block; line-height: 28px; background-color: rgb(30, 155, 232);&quot;&gt;&amp;nbsp;&lt;/section&gt;&lt;section style=&quot;margin: 0px; padding: 5px; outline: 0px; max-width: 100%; box-sizing: border-box; overflow-wrap: break-word !important; display: inline-block;&quot;&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; overflow-wrap: break-word !important;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; color: #1E9BE8;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-size: 18px;&quot;&gt;运行访问&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/section&gt;&lt;/h2&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; overflow-wrap: break-word !important;&quot;&gt;&lt;img data-s=&quot;300,640&quot; data-type=&quot;png&quot; data-src=&quot;https://mmbiz.qpic.cn/mmbiz_png/opjQo1t6Lc5KtMUO0dTqiclTzYx0R4Sul4zicOcF15tibq25XWzoY3hTdFEOoAYU0jrNg68HKHNT1tDUzibu19gspw/0?wx_fmt=png&quot; data-copyright=&quot;0&quot; class=&quot;&quot; data-ratio=&quot;0.5799011532125206&quot; data-w=&quot;1821&quot; data-index=&quot;1&quot; src=&quot;https://mmbiz.qpic.cn/mmbiz_png/opjQo1t6Lc5KtMUO0dTqiclTzYx0R4Sul4zicOcF15tibq25XWzoY3hTdFEOoAYU0jrNg68HKHNT1tDUzibu19gspw/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1&quot; _width=&quot;677px&quot; crossorigin=&quot;anonymous&quot; alt=&quot;图片&quot; data-fail=&quot;0&quot; style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; height: auto !important; width: 677px !important; visibility: visible !important;&quot;/&gt;&lt;/p&gt;&lt;h2 style=&quot;margin: 1.5rem 0px 1rem; padding: 0px; outline: 0px; font-weight: 400; font-size: 24px; max-width: 100%; box-sizing: border-box; color: rgb(21, 153, 87); line-height: 1.35; text-wrap: wrap; text-align: center; overflow-wrap: break-word !important;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-size: 20px;&quot;&gt;附录&lt;/span&gt;&lt;/h2&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box; clear: both; min-height: 1em; font-size: 16px; white-space: pre-line; line-height: 30px; color: rgb(74, 74, 74); font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif; overflow-wrap: break-word !important;&quot;&gt;贴一些常用的 docker-compose 命令，其中的 dc 表示 docker-compose 命令。&lt;/p&gt;&lt;pre class=&quot;&quot; style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 8px 0px 6px; outline: 0px; max-width: 100%; box-sizing: border-box; background-color: rgb(47, 54, 64); border-radius: 0px; overflow-y: auto; color: rgb(80, 97, 109); font-size: 10px; line-height: 12px; overflow-wrap: break-word !important;&quot;&gt;dc&amp;nbsp;&amp;nbsp;stop&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;停止所有容器dc&amp;nbsp;&amp;nbsp;stop&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;nginx&amp;nbsp;&amp;nbsp;&amp;nbsp;停止指定容器dc&amp;nbsp;&amp;nbsp;up&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-d&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;启动容器后台运行dc&amp;nbsp;&amp;nbsp;ps&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;查看当前容器dc&amp;nbsp;&amp;nbsp;logs&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;kafka&amp;nbsp;&amp;nbsp;&amp;nbsp;查看指定容器日志&lt;/pre&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; outline: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; overflow-wrap: break-word !important;&quot;&gt;&lt;br style=&quot;margin: 0px; padding: 0px; outline: 0px; max-width: 100%; color: rgba(0, 0, 0, 0.9); font-family: system-ui, -apple-system, BlinkMacSystemFont, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei UI&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; text-wrap: wrap; background-color: rgb(255, 255, 255); box-sizing: border-box !important; overflow-wrap: break-word !important;&quot;/&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Fri, 05 Jan 2024 23:11:38 +0800</pubDate></item><item><title>未命名</title><link>https://lxf.net/?id=80</link><description>&lt;p&gt;&lt;img src=&quot;http://www.k7.org/images/me.jpg&quot;/&gt;&lt;/p&gt;</description><pubDate>Sun, 21 May 2023 19:21:51 +0800</pubDate></item><item><title>PHP接入chatGpt API </title><link>https://lxf.net/?id=79</link><description>&lt;pre class=&quot;prism-highlight prism-language-php&quot;&gt;蹭个热度，写个chatGPT&amp;nbsp;API&amp;nbsp;PHP接入

$query&amp;nbsp;=&amp;nbsp;&amp;quot;Hello,&amp;nbsp;ChatGPT!&amp;quot;;&amp;nbsp;&amp;nbsp;//&amp;nbsp;查询内容
$api_key&amp;nbsp;=&amp;nbsp;&amp;quot;your_api_key&amp;quot;;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;API&amp;nbsp;Key

//&amp;nbsp;准备请求数据
$data&amp;nbsp;=&amp;nbsp;array(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;query&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;$query,
);

//&amp;nbsp;发送HTTP请求
$ch&amp;nbsp;=&amp;nbsp;curl_init();
curl_setopt($ch,&amp;nbsp;CURLOPT_URL,&amp;nbsp;&amp;quot;https://api.chatgpt.com/v1/gpt3&amp;quot;);
curl_setopt($ch,&amp;nbsp;CURLOPT_POST,&amp;nbsp;1);
curl_setopt($ch,&amp;nbsp;CURLOPT_POSTFIELDS,&amp;nbsp;$data);
curl_setopt($ch,&amp;nbsp;CURLOPT_RETURNTRANSFER,&amp;nbsp;1);
curl_setopt($ch,&amp;nbsp;CURLOPT_HTTPHEADER,&amp;nbsp;array(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;API-KEY:&amp;nbsp;&amp;#39;.$api_key,
));
$response&amp;nbsp;=&amp;nbsp;curl_exec($ch);
curl_close($ch);

//&amp;nbsp;处理API响应
if&amp;nbsp;($response&amp;nbsp;===&amp;nbsp;false)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;echo&amp;nbsp;&amp;quot;API请求失败！&amp;quot;;
}&amp;nbsp;else&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;将API响应转换为PHP数组
&amp;nbsp;&amp;nbsp;&amp;nbsp;$result&amp;nbsp;=&amp;nbsp;json_decode($response,&amp;nbsp;true);
&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;($result&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;isset($result[&amp;quot;success&amp;quot;])&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;$result[&amp;quot;success&amp;quot;]&amp;nbsp;==&amp;nbsp;true)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;处理API成功响应的数据
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$data&amp;nbsp;=&amp;nbsp;$result[&amp;quot;data&amp;quot;];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;保存对话历史记录
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;saveDialogue($query,&amp;nbsp;$data[&amp;quot;text&amp;quot;]);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查敏感词汇
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(checkSensitiveWords($data[&amp;quot;text&amp;quot;]))&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;如果检测到敏感词汇，做出相应处理
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;handleSensitiveWords($data[&amp;quot;text&amp;quot;]);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;else&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;输出生成的对话文本
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;echo&amp;nbsp;$data[&amp;quot;text&amp;quot;];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;else&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;处理API响应错误信息
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$error&amp;nbsp;=&amp;nbsp;$result[&amp;quot;error&amp;quot;][&amp;quot;message&amp;quot;];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;echo&amp;nbsp;&amp;quot;API请求错误：&amp;quot;.$error;
&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}

//&amp;nbsp;保存对话历史记录
function&amp;nbsp;saveDialogue($query,&amp;nbsp;$response)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;TODO:&amp;nbsp;保存对话历史记录
&amp;nbsp;&amp;nbsp;&amp;nbsp;$file&amp;nbsp;=&amp;nbsp;fopen(&amp;quot;dialogue_history.txt&amp;quot;,&amp;nbsp;&amp;quot;a&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;fwrite($file,&amp;nbsp;&amp;quot;Query:&amp;quot;.$query.&amp;quot;\tResponse:&amp;quot;.$response.&amp;quot;\n&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;fclose($file);
}

//&amp;nbsp;检查敏感词汇
function&amp;nbsp;checkSensitiveWords($text)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;TODO:&amp;nbsp;检查敏感词汇
&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(strpos($text,&amp;nbsp;&amp;quot;敏感词汇&amp;quot;)&amp;nbsp;!==&amp;nbsp;false)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;else&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}

//&amp;nbsp;处理敏感词汇
function&amp;nbsp;handleSensitiveWords($text)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;TODO:&amp;nbsp;处理敏感词汇
&amp;nbsp;&amp;nbsp;&amp;nbsp;echo&amp;nbsp;&amp;quot;您的请求包含敏感词汇，请重新输入。&amp;quot;;
}&lt;/pre&gt;</description><pubDate>Wed, 22 Mar 2023 20:46:33 +0800</pubDate></item><item><title>Linux进程间管道通信</title><link>https://lxf.net/?id=77</link><description>&lt;p&gt;无名管道：&lt;/p&gt;&lt;p&gt;无名管道的特点：&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;只能用于具有亲缘关系间的通信。【父子进程 或 兄弟进程】&lt;/p&gt;&lt;p&gt;半双工通信。【只能由一方发送，另一方接收】&lt;/p&gt;&lt;p&gt;通信端口固定。【fd[0]:读管道 ，fd[1]:写管道】&lt;/p&gt;&lt;p&gt;管道也是一种特殊的文件，对于它的读写，也可以使用普通的read(),write()函数。&lt;/p&gt;&lt;p&gt;管道不属于任何文件系统，只存在于内存中。&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://img-blog.csdnimg.cn/cfc20a8aa932412c8c8bc15061d176c1.png&quot; alt=&quot;在这里插入图片描述&quot; style=&quot;font-size: medium; white-space: normal;&quot;/&gt;&lt;br/&gt;&lt;/p&gt;&lt;h5 style=&quot;white-space: normal; box-sizing: border-box; outline: 0px; margin: 8px 0px 16px; padding: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 16px; color: rgb(79, 79, 79); line-height: 24px; overflow-wrap: break-word; font-variant-ligatures: no-common-ligatures; background-color: rgb(255, 255, 255);&quot;&gt;无名管道的创建&lt;/h5&gt;&lt;p style=&quot;white-space: normal; box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; overflow: auto hidden; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: no-common-ligatures; background-color: rgb(255, 255, 255);&quot;&gt;无名管道是基于&amp;nbsp;&lt;span style=&quot;color:black;box-sizing: border-box; outline: 0px; overflow-wrap: break-word;&quot;&gt;&lt;span style=&quot;box-sizing: border-box; outline: 0px; font-weight: 700; overflow-wrap: break-word;&quot;&gt;文件描述符&lt;/span&gt;&lt;/span&gt;&amp;nbsp;的通信方式,当一个管道被建立时，它会创建&lt;span style=&quot;color:red;box-sizing: border-box; outline: 0px; overflow-wrap: break-word;&quot;&gt;&lt;span style=&quot;box-sizing: border-box; outline: 0px; font-weight: 700; overflow-wrap: break-word;&quot;&gt;两个&lt;/span&gt;&lt;/span&gt;文件描述符：fd[0]、fd[1].&lt;br style=&quot;box-sizing: border-box; outline: 0px; overflow-wrap: break-word;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box; outline: 0px; font-weight: 700; overflow-wrap: break-word;&quot;&gt;fd[0]&lt;/span&gt;:读文件描述符，用于固定读管道&lt;br style=&quot;box-sizing: border-box; outline: 0px; overflow-wrap: break-word;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box; outline: 0px; font-weight: 700; overflow-wrap: break-word;&quot;&gt;fd[1]&lt;/span&gt;:写文件描述符，用于固定写管道&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://img-blog.csdnimg.cn/ca2457107b5a400580d2b52e76b1b9d7.png&quot; alt=&quot;在这里插入图片描述&quot; style=&quot;font-size: medium; white-space: normal;&quot;/&gt;&lt;br/&gt;&lt;/p&gt;&lt;h3 style=&quot;white-space: normal; box-sizing: border-box; outline: 0px; margin: 8px 0px 16px; padding: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 20px; color: rgb(79, 79, 79); line-height: 28px; overflow-wrap: break-word; font-variant-ligatures: no-common-ligatures; background-color: rgb(255, 255, 255);&quot;&gt;无名管道的相关函数&lt;/h3&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;头文件：#include&amp;lt;unistd.h&amp;gt;&lt;/p&gt;&lt;p&gt;函数名：pipe&lt;/p&gt;&lt;p&gt;参数：int&amp;nbsp; pipefd[]&amp;nbsp; :包含两个元素的整型数组，存&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 放管道对应的文件描述符&lt;/p&gt;&lt;p&gt;返回值：成功--&amp;gt; 0&amp;nbsp; &amp;nbsp;失败--&amp;gt; -1&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;int&amp;nbsp; pipe(int&amp;nbsp; pipefd[]);&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt; pipe函数创建的管道两端处于同一个进程中。由于管道主要是用于不同进程间的通信，所以首先会fork()一个子进程，该子进程会继承父进程所创建的管道。此时父子进程就都拥有了一个管道，所以会产生两个fd[0],fd[1]。&lt;/p&gt;&lt;p&gt;  根据需要，若是父进程发消息，子进程收消息。那么久关闭父进程的fd[1]，关闭子进程的fd[0]。此时父进程就只有fd[0],子进程也就只有fd[1]了。他们俩就能通过无名管道来进行单向通信。&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://img-blog.csdnimg.cn/3357028bba0a4454bea027845ed4a1f0.png&quot; alt=&quot;在这里插入图片描述&quot; style=&quot;font-size: medium; white-space: normal;&quot;/&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;box-sizing: border-box; outline: 0px; font-weight: 700; overflow-wrap: break-word; color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #FFFFFF;&quot;&gt;同理，若是需要子进程发送数据，父进程接收数据，就关闭对应的文件描述符即可。&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;&lt;h2 style=&quot;white-space: normal; box-sizing: border-box; outline: 0px; margin: 8px 0px 16px; padding: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 22px; color: rgb(79, 79, 79); line-height: 30px; overflow-wrap: break-word; font-variant-ligatures: no-common-ligatures; background-color: rgb(255, 255, 255);&quot;&gt;举个栗子&lt;/h2&gt;&lt;p&gt;&lt;img src=&quot;https://img-blog.csdnimg.cn/54e551a5f61340f9ad5e14c0098ababb.png&quot; alt=&quot;在这里插入图片描述&quot; style=&quot;font-size: medium; white-space: normal;&quot;/&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;注意事项：&lt;/p&gt;&lt;p&gt;&amp;nbsp;只有管道的读端存在时，向管道内写入数据才有意义。否则，向管道内写入的数据的进程会收到内核传来的SIGPIPE信号。【通常为Broken Pipe(管道破裂) 错误】&lt;/p&gt;&lt;p&gt;&amp;nbsp;向管道内写入数据时，Linux不保证写入的原子性，管道缓冲区只要有空间，写进程就会向管道写入数据；若管道已满，则写操作会阻塞等待&lt;/p&gt;&lt;p&gt;&amp;nbsp;父子进程在运行时，他们的先后次序不能保证。 为确保父子进程已经关闭了相应的文件描述符，可以在两个进程中调用 sleep()函数&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;h5 style=&quot;white-space: normal; box-sizing: border-box; outline: 0px; margin: 8px 0px 16px; padding: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 16px; color: rgb(79, 79, 79); line-height: 24px; overflow-wrap: break-word; font-variant-ligatures: no-common-ligatures; background-color: rgb(255, 255, 255);&quot;&gt;【附】上述例子的源码：&lt;/h5&gt;&lt;blockquote&gt;&lt;p&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/p&gt;&lt;p&gt;#include&amp;lt;unistd.h&amp;gt;&lt;/p&gt;&lt;p&gt;#include&amp;lt;string.h&amp;gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;int main(void)&lt;/p&gt;&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;pid_t pid = -1;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;int pipefd[2];&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;//创建无名管道&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;if(0 &amp;gt; pipe(pipefd))&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;perror(&amp;quot;pipe error!\n&amp;quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;return -1;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;}&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;puts(&amp;quot;pipe success!&amp;quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;/*pipe[0]读端 , pipe[1]写端*/&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;pid = fork();&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;//创建子进程&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;//判断是否创建成功&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;if(0 &amp;gt; pid)&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;//pid错误&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;perror(&amp;quot;fork error!\n&amp;quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;return -1;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;}&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;else if(0 &amp;lt; pid)&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;//父进程 发&amp;nbsp; 子进程 收&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;close(pipefd[0]);&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;//关闭父进程的读端fd[0]&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;//发送数据&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;char buf[20] = {0};&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;//从键盘输入小于20的字符串&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;gets(buf , sizeof(buf) , stdin);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;//将获得的字符串通过管道传递给子进程(pipefd[1]是子进程的接收端)&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;write(pipefd[1] , buf , strlen(buf));&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;//关闭父进程的写文件描述符&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;close(pipefd[1]);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;}&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;else if(0 == pid)&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;//子进程&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;close(pipefd[1]);&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;//关闭子进程的写端fd[1]&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;//接收数据&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;char buf1[20] = {0};&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;read(pipefd[0] , buf1 , sizeof(buf1));&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;printf(&amp;quot;read data : %s\n&amp;quot; , buf1);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;//关闭读端&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;close(pipefd[0]);&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;}&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space:pre&quot;&gt;&lt;/span&gt;return 0;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/p&gt;&lt;p&gt;#include &amp;lt;unistd.h&amp;gt;&lt;/p&gt;&lt;p&gt;#include &amp;lt;string.h&amp;gt;&lt;/p&gt;&lt;p&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;//-----------------------------------------------示例二--------------------------------------------//&lt;/p&gt;&lt;p&gt;int main()&lt;/p&gt;&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;int fd[2];&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;int pid;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;char readbuf[128];&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if(pipe(fd) == -1){&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&amp;quot;creat pipe fail\n&amp;quot;);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;pid = fork();&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if(pid &amp;lt; 0){&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&amp;quot;creat child fail\n&amp;quot;);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;else if(pid &amp;gt; 0){&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&amp;quot;this is father\n&amp;quot;);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sleep(3);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; close(fd[0]);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; write(fd[1],&amp;quot;hellow this father&amp;quot;,strlen(&amp;quot;hellow this father&amp;quot;));&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; wait();&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}else{&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&amp;quot;this is child\n&amp;quot;);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; close(fd[1]);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; read(fd[0],readbuf,128);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&amp;quot;this is from father:%s\n&amp;quot;,readbuf);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; exit(0);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;return 0;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/blockquote&gt;</description><pubDate>Fri, 28 Oct 2022 10:41:14 +0800</pubDate></item></channel></rss><!--14.24 ms , 6 query , 904kb memory , 0 error-->