【容器编排魔法】Docker容器编排神器Componse完全解析!

{“type”:”doc”,”content”:[{“type”:”heading”,”attrs”:{“id”:”eaaddd88-46fd-457a-ab28-305a656b26dc”,”textalign”:”justify”,”indent”:0,”level”:1,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”一、前言”}]},{“type”:”paragraph”,”attrs”:{“id”:”ab5e411c-3800-4114-93bc-1dc036eac6fd”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”docker compose是docker官方提供的一个定义和运行多个docker容器的工具。用yaml文件来配置应用的服务,一个文件定义一组相关联的容器化应用,然后用一条命令即可用该文件来创建、启动、停止以及删除整个应用的容器,非常适合开发、测试和部署环境。”}]},{“type”:”paragraph”,”attrs”:{“id”:”b2693ceb-0f95-4a0f-9bed-bd5f139161a3″,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”相关文档:”}]},{“type”:”bulletlist”,”attrs”:{“id”:”8860ea61-09de-4d0a-beb5-5ee322037493″,”ishoverdraghandle”:false},”content”:[{“type”:”listitem”,”attrs”:{“id”:”a40bb46d-79b4-4b95-84ed-e8ac53b956df”},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”d3bf9ad4-dd01-4a9f-aef3-74bf39381198″,”textalign”:”inherit”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”docker-compose 命令行:https://docs.docker.com/compose/reference/”}]}]},{“type”:”listitem”,”attrs”:{“id”:”b210c33a-5914-4488-ae2d-8dcabfcd866d”},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”1e55b074-a945-442a-b6bd-2d8150855e92″,”textalign”:”inherit”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”docker-compose 配置文件:https://docs.docker.com/compose/compose-file/”}]}]}]},{“type”:”image”,”attrs”:{“id”:”78ac880f-148e-4be5-b01d-8d105f171516″,”src”:”https://developer.qcloudimg.com/http-save/audit-11218869/954ce9c15dee1fbeffeabc159d463a6e.png”,”extension”:”png”,”align”:”center”,”alt”:””,”showalt”:false,”href”:””,”boxshadow”:””,”width”:1100,”aspectratio”:”1.777778″,”status”:”success”,”showtext”:true,”ispercentage”:false,”percentage”:0,”ishoverdraghandle”:false}},{“type”:”paragraph”,”attrs”:{“id”:”9d95d98e-2a08-4fe1-9d21-b0299f4c2d2f”,”textalign”:”inherit”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false}},{“type”:”heading”,”attrs”:{“id”:”a4eb4eb3-e229-49cd-9ecd-4a7f5e694b63″,”textalign”:”justify”,”indent”:0,”level”:1,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”二、compose 简介”}]},{“type”:”paragraph”,”attrs”:{“id”:”162c9d2c-6fbd-40a3-b5f7-94ba7e981ada”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”docker compose 是 docker 官方编排(orchestration)项目之一,负责快速的部署分布式应用。”},{“type”:”hardbreak”,”attrs”:{“id”:”d381aece-1b08-4030-99b9-c58f3d9a003d”}},{“type”:”text”,”text”:”compose 项目是 docker 官方的开源项目,负责实现对 docker 容器集群的快速编排。代码目前在github(https://github.com/docker/compose)上开源。”},{“type”:”hardbreak”,”attrs”:{“id”:”04e1af8d-51b8-424e-9486-0301966643c5″}},{“type”:”text”,”text”:”compose 定位是 【定义和运行多个 docker 容器的应用(defining and running multi-container docker applications)】,前身是开源项目 fig。”}]},{“type”:”paragraph”,”attrs”:{“id”:”78fbd591-32fd-44ec-b8fb-740c7d6312f8″,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”我们知道用一个 dockerfile 模板文件,可以让用户很方便的定义一个单独的应用容器。但是,日常工作经常会碰到要多个容器相互配合来完成某项任务的情况。例如要实现一个 web 项目,除web 服务容器本身,往往还要再加上后端的数据库服务容器,甚至还包括负载均衡容器等。”},{“type”:”hardbreak”,”attrs”:{“id”:”dc5df6b7-36ae-402b-9bad-9ddeb8737cd3″}},{“type”:”text”,”text”:”compose 恰好满足这样的需求。用户用一个单独的 “},{“type”:”text”,”marks”:[{“type”:”code”}],”text”:”docker-compose.yml”},{“type”:”text”,”text”:” 模板文件(yaml 格式)来定义一组相关联的应用容器为一个项目(project)。”}]},{“type”:”paragraph”,”attrs”:{“id”:”ff752a36-a852-4704-bc8c-aed548ed463c”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”compose 有两个重要的概念:”}]},{“type”:”bulletlist”,”attrs”:{“id”:”44640487-222e-49d7-ba2b-37af442e4e42″,”ishoverdraghandle”:false},”content”:[{“type”:”listitem”,”attrs”:{“id”:”4864b3b3-7a07-46cd-af2b-449937b28acf”},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”20b9e1f9-227b-4b51-8533-5227c18db317″,”textalign”:”inherit”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”服务 (service):一个应用的容器,实际可以包括若干运行相同镜像的容器实例。”}]}]},{“type”:”listitem”,”attrs”:{“id”:”00a4d133-0c70-4c2d-b35c-bc4061858b5b”},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”275cbf0f-e35d-43d3-bcf6-2fd7fbcd4923″,”textalign”:”inherit”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”项目 (project):由一组关联的应用容器组成的一个完整业务单元,在 docker-compose.yml 文件中定义。”}]}]}]},{“type”:”paragraph”,”attrs”:{“id”:”3ec344a2-92aa-4cc4-8d59-56857c8e826f”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”compose的默认管理对象是项目,用子命令对项目中的一组容器进行生命周期管理。”}]},{“type”:”paragraph”,”attrs”:{“id”:”53f5dfde-a447-4502-b833-7c50ed126565″,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”compose 项目用 python 编写,实现调用 docker 服务提供的 api 来对容器进行管理。所以,只要所操作的平台支持 docker api,就可以在其上利用 compose 来进行编排管理。”}]},{“type”:”heading”,”attrs”:{“id”:”2a3e05db-4194-4800-9410-c59efcb5bf16″,”textalign”:”justify”,”indent”:0,”level”:1,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”三、compose的安装和卸载”}]},{“type”:”heading”,”attrs”:{“id”:”2b3a8bef-75b0-46df-85f6-44c84a2997c3″,”textalign”:”justify”,”indent”:0,”level”:2,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”3.1、安装”}]},{“type”:”paragraph”,”attrs”:{“id”:”8da69a46-147c-4499-a58d-bf8c1add1c5a”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”linux 的安装十分简单,从 github release处直接下载编译好的二进制文件即可。”}]},{“type”:”paragraph”,”attrs”:{“id”:”e66c826d-7eb4-49d5-8e9e-f550b5c31f41″,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”例如,在 linux 64 位系统上直接下载对应的二进制包。”}]},{“type”:”paragraph”,”attrs”:{“id”:”b54e41d9-6178-48fe-98ba-43c7dd125ba4″,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”(1)先把docker-compose文件下载到当前目录:”}]},{“type”:”codeblock”,”attrs”:{“id”:”172f0686-e083-4cf6-b922-150295f8e2ff”,”language”:”bash”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”txt”},”content”:[{“type”:”text”,”text”:”wget https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-linux-x86_64″}]},{“type”:”paragraph”,”attrs”:{“id”:”aa71dbcb-7390-4693-9640-ef246c0426e7″,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”(2)然后拷贝到”},{“type”:”text”,”marks”:[{“type”:”code”}],”text”:”/usr/bin/ “},{“type”:”text”,”text”:”。”}]},{“type”:”codeblock”,”attrs”:{“id”:”23d09ab2-9790-4fd8-968c-0642e25ce264″,”language”:”bash”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”shell”},”content”:[{“type”:”text”,”text”:”sudo cp -arf docker-compose-linux-x86_64 /usr/bin/docker-composesudo chmod +x /usr/bin/docker-compose”}]},{“type”:”heading”,”attrs”:{“id”:”9a89b464-9b43-4ff0-abb5-975da9d40e91″,”textalign”:”justify”,”indent”:0,”level”:2,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”3.2、卸载”}]},{“type”:”paragraph”,”attrs”:{“id”:”7c4aa2ed-22f3-4d08-b21d-a49cea1dfc8d”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”如果是二进制包方式安装的,删除二进制文件即可。”}]},{“type”:”codeblock”,”attrs”:{“id”:”c19d962f-8366-4930-9207-b56e3cf34065″,”language”:”bash”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”shell”},”content”:[{“type”:”text”,”text”:”sudo rm /usr/bin/docker-compose”}]},{“type”:”heading”,”attrs”:{“id”:”73cd7abd-7f48-43ae-b9f4-ad0105fee7b3″,”textalign”:”justify”,”indent”:0,”level”:2,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”3.3、使用”}]},{“type”:”paragraph”,”attrs”:{“id”:”c9158a35-46b5-4618-b164-6bd489d5ad4c”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”选项:”}]},{“type”:”codeblock”,”attrs”:{“id”:”6612b33f-9247-45ca-8735-bf88c028f11e”,”language”:”bash”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”txt”},”content”:[{“type”:”text”,”text”:”usage: docker compose [options] commanddocker composeoptions: –ansi string control when to print ansi control characters (“never”|”always”|”auto”) (default “auto”) –compatibility run compose in backward compatibility mode –env-file string specify an alternate environment file. -f, –file stringarray compose configuration files –profile stringarray specify a profile to enable –project-directory string specify an alternate working directory (default: the path of the, first specified, compose file) -p, –project-name string project namecommands: build build or rebuild services convert converts the compose file to platform’s canonical format cp copy files/folders between a service container and the local filesystem create creates containers for a service. down stop and remove containers, networks events receive real time events from containers. exec execute a command in a running container. images list images used by the created containers kill force stop service containers. logs view output from containers ls list running compose projects pause pause services port print the public port for a port binding. ps list containers pull pull service images push push service images restart restart service containers rm removes stopped service containers run run a one-off command on a service. start start services stop stop services top display the running processes unpause unpause services up create and start containers version show the docker compose version informationrun ‘docker compose command –help’ for more information on a command.”}]},{“type”:”paragraph”,”attrs”:{“id”:”e79d1316-6540-49ec-a07e-88ba8efed2cf”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”compose的关键选项:”}]},{“type”:”bulletlist”,”attrs”:{“id”:”1cb17cad-a038-4ba0-a781-c01ccb114f63″,”ishoverdraghandle”:false},”content”:[{“type”:”listitem”,”attrs”:{“id”:”03884ed2-ada4-430b-b3ac-cdf61e666251″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”da622f1a-901c-43a0-9002-f66adf78ebc3″,”textalign”:”inherit”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”-p:指定项目名称。”}]}]},{“type”:”listitem”,”attrs”:{“id”:”d40e3038-4dd9-4432-84ad-e7a9658f7694″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”2e7f1401-5942-4a8d-b33a-ef569622f370″,”textalign”:”inherit”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”-f:指定配置文件。”}]}]}]},{“type”:”paragraph”,”attrs”:{“id”:”8b58a10c-a390-407a-b5d6-2ccb82cc8922″,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”建议:单独的项目放在一个文件夹下,而不指定-p和-f参数,这样用起来比较方便;因为如果指定这两个选项,那么在项目操作过程中需要每次都要指定这两个参数,否则compose指令就识别不到项目。所以直接以默认的方式(以当前文件夹作为项目名称,当前文件夹下的docker-compose.yml作为配置文件)执行。”}]},{“type”:”heading”,”attrs”:{“id”:”bcc4fbdb-463e-47de-9d77-e92042223bfb”,”textalign”:”justify”,”indent”:0,”level”:1,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”四、yml 配置指令参考”}]},{“type”:”paragraph”,”attrs”:{“id”:”9b388f15-0c75-4a20-8938-438bcc8d57b6″,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”以下内容只作为参考;具体参见官方文档。”}]},{“type”:”paragraph”,”attrs”:{“id”:”574c8738-9ba5-40f8-b3b6-0ef1c26f50dd”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”(1)”},{“type”:”text”,”marks”:[{“type”:”textstyle”,”attrs”:{“color”:””,”background”:””}},{“type”:”bold”}],”text”:”version”},{“type”:”text”,”text”:”;compose 文件格式有3个版本,分别为1, 2.x 和 3.x 目前主流的为 3.x 其支持 docker 1.13.0 及其以上的版本。”}]},{“type”:”paragraph”,”attrs”:{“id”:”eb33a112-09ad-46a3-bcf2-92ac64b8bc7c”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”(2)”},{“type”:”text”,”marks”:[{“type”:”textstyle”,”attrs”:{“color”:””,”background”:””}},{“type”:”bold”}],”text”:”build”},{“type”:”text”,”text”:”;指定镜像构建参数,其作用与docker build 命令一样。”},{“type”:”hardbreak”,”attrs”:{“id”:”4495ddf3-2478-4fc0-a897-a7bbb3601358″}},{“type”:”text”,”text”:”比如:”}]},{“type”:”codeblock”,”attrs”:{“id”:”439ca46a-5f76-45ea-b370-b5de0b9e9f47″,”language”:”bash”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”txt”},”content”:[{“type”:”text”,”text”:”build: ./dir”}]},{“type”:”paragraph”,”attrs”:{“id”:”4c32ef2e-e8e7-4178-9139-f5c21dae2bab”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”或”}]},{“type”:”codeblock”,”attrs”:{“id”:”2752cae2-2e54-4a23-8780-8db789efff3f”,”language”:”yaml”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”yaml”},”content”:[{“type”:”text”,”text”:”build:# 上下文路径context: .# 指定构建镜像的 dockerfile 文件名dockerfile: dockerfile-compose# 添加构建参数,这是只能在构建过程中访问的环境变量。args:- http_proxy: https://proxy.golang.com.cn,https://goproxy.cn,direct# 设置构建镜像的标签。labels:- “myhello:1.0”- “com.example.description=accounting webapp”# target:多层构建,可以指定构建哪一层。# tags:指定镜像的tagstags:- “myhello:1.0.0”- “localhost:5000/myhello:1.0.0″”}]},{“type”:”paragraph”,”attrs”:{“id”:”4779c631-0aa3-4137-9d79-6bda029e23cb”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”(3)”},{“type”:”text”,”marks”:[{“type”:”textstyle”,”attrs”:{“color”:””,”background”:””}},{“type”:”bold”}],”text”:”command”},{“type”:”text”,”text”:”;覆盖容器启动的默认命令。”}]},{“type”:”codeblock”,”attrs”:{“id”:”01f6909e-da40-4f74-9f00-b1d4f4a39fe1″,”language”:”yaml”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”yaml”},”content”:[{“type”:”text”,”text”:”command: [“bundle”, “exec”, “thin”, “-p”, “3000”]”}]},{“type”:”paragraph”,”attrs”:{“id”:”7df88f02-0de2-4417-a36f-5ee72e533647″,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”(4)”},{“type”:”text”,”marks”:[{“type”:”textstyle”,”attrs”:{“color”:””,”background”:””}},{“type”:”bold”}],”text”:”container_name”},{“type”:”text”,”text”:”;指定自定义容器名称,而不是生成的默认名称。”}]},{“type”:”codeblock”,”attrs”:{“id”:”9521e346-17d0-47ae-bf3f-ba40dad861ff”,”language”:”yaml”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”yaml”},”content”:[{“type”:”text”,”text”:”container_name: my-web-container”}]},{“type”:”paragraph”,”attrs”:{“id”:”376f521d-dd0f-4c4b-8202-a137b7635630″,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”(5)”},{“type”:”text”,”marks”:[{“type”:”textstyle”,”attrs”:{“color”:””,”background”:””}},{“type”:”bold”}],”text”:”depends_on”},{“type”:”text”,”text”:”;设置依赖关系。”}]},{“type”:”bulletlist”,”attrs”:{“id”:”56038816-7e5f-4b8e-855b-41cd981eb925″,”ishoverdraghandle”:false},”content”:[{“type”:”listitem”,”attrs”:{“id”:”106963e3-0cad-4a90-a346-5b4d7a387d0f”},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”ce92dd12-f47e-4679-a6cb-ae1393e845f1″,”textalign”:”inherit”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”docker-compose up :以依赖性顺序启动服务。在以下示例中,先启动 db 和 redis ,才会启动web。”}]}]},{“type”:”listitem”,”attrs”:{“id”:”c802e81b-59ab-4e5f-9d50-b913bd47e4fd”},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”96c7136b-5d5c-4dad-af7d-c8a02babdf65″,”textalign”:”inherit”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”docker-compose up service :自动包含 service 的依赖项。在以下示例中,docker-compose up web 还将创建并启动 db 和 redis。”}]}]},{“type”:”listitem”,”attrs”:{“id”:”997182f0-ca46-49d7-96af-93e78dd797b4″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”eac21146-3f9b-4e46-a91a-780acd1eef72″,”textalign”:”inherit”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”docker-compose stop :按依赖关系顺序停止服务。在以下示例中,web 在 db 和 redis 之前停止。”}]}]}]},{“type”:”codeblock”,”attrs”:{“id”:”54eba7db-aba8-4e55-aa70-ef03e358b7cf”,”language”:”yaml”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”yaml”},”content”:[{“type”:”text”,”text”:”version: “3.7”services:web:\tbuild: .\tdepends_on:\tt- db\tt- redisredis:\timage: redisdb:\timage: postgres”}]},{“type”:”paragraph”,”attrs”:{“id”:”d3a962ed-fa3b-4d12-9acf-804e7603066c”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”注意:web 服务不会等待 redis、db 完全启动 之后才启动。”}]},{“type”:”paragraph”,”attrs”:{“id”:”26fc2552-bf23-4513-92b4-d0763ffea9f6″,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”(6)”},{“type”:”text”,”marks”:[{“type”:”textstyle”,”attrs”:{“color”:””,”background”:””}},{“type”:”bold”}],”text”:”entrypoint”},{“type”:”text”,”text”:”;覆盖容器默认的 entrypoint。”}]},{“type”:”codeblock”,”attrs”:{“id”:”e8be4c79-7894-4145-8f75-4daec9a13579″,”language”:”yaml”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”yaml”},”content”:[{“type”:”text”,”text”:”entrypoint: /code/entrypoint.sh”}]},{“type”:”paragraph”,”attrs”:{“id”:”4486cb49-3c51-443a-9a76-02248c1231ca”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”也可以是以下格式:”}]},{“type”:”codeblock”,”attrs”:{“id”:”bb560542-2b0c-4dae-890b-0f41cc93f0bf”,”language”:”yaml”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”yaml”},”content”:[{“type”:”text”,”text”:”entrypoint:- php- -d- zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-t20100525/xdebug.so- -d- memory_limit=-1- vendor/bin/phpunit”}]},{“type”:”paragraph”,”attrs”:{“id”:”bfd3a0b8-c3b6-429e-bde9-4553aa5a5ec9″,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”(7)”},{“type”:”text”,”marks”:[{“type”:”textstyle”,”attrs”:{“color”:””,”background”:””}},{“type”:”bold”}],”text”:”env_file”},{“type”:”text”,”text”:”;从文件添加环境变量,可以是单个值或列表的多个值。”}]},{“type”:”codeblock”,”attrs”:{“id”:”207f86f1-5f22-4ef0-b54f-e3d2315f9a7b”,”language”:”yaml”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”txt”},”content”:[{“type”:”text”,”text”:”env_file: .env”}]},{“type”:”paragraph”,”attrs”:{“id”:”c572a19f-7e78-4d73-9068-ccbaf739e38c”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”也可以是列表格式:”}]},{“type”:”codeblock”,”attrs”:{“id”:”4ceeedff-f4ae-4f7b-b710-95bdbedee009″,”language”:”yaml”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”yaml”},”content”:[{“type”:”text”,”text”:”env_file:- ./common.env- ./apps/web.env- /opt/secrets.env”}]},{“type”:”paragraph”,”attrs”:{“id”:”e50f5fe3-0eed-446d-acb7-5ed6283f7900″,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”(8)”},{“type”:”text”,”marks”:[{“type”:”textstyle”,”attrs”:{“color”:””,”background”:””}},{“type”:”bold”}],”text”:”environment”},{“type”:”text”,”text”:”;添加环境变量。您可以使用数组或字典、任何布尔值,布尔值需要用引号引起来,以确保 yml 解析器不会将其转换为 true 或 false。”}]},{“type”:”codeblock”,”attrs”:{“id”:”aa9b2ed8-6a6a-4b1e-9be6-6b9d90c26d70″,”language”:”yaml”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”yaml”},”content”:[{“type”:”text”,”text”:”environment:rack_env: developmentshow: ‘true'”}]},{“type”:”paragraph”,”attrs”:{“id”:”870507bd-a001-4b6d-92dd-01240913a08e”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”(9)”},{“type”:”text”,”marks”:[{“type”:”textstyle”,”attrs”:{“color”:””,”background”:””}},{“type”:”bold”}],”text”:”expose”},{“type”:”text”,”text”:”;暴露端口,但不映射到宿主机,只被连接的服务访问。”},{“type”:”hardbreak”,”attrs”:{“id”:”19f944c1-d307-4336-a775-959f18e63373″}},{“type”:”text”,”text”:”仅可以指定内部端口为参数:”}]},{“type”:”codeblock”,”attrs”:{“id”:”29c41c5f-e5d6-4af4-8bfb-2222ed059929″,”language”:”yaml”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”yaml”},”content”:[{“type”:”text”,”text”:”expose:- “3000”- “8000””}]},{“type”:”paragraph”,”attrs”:{“id”:”ad2e3224-559a-4e0c-b8a6-eb2f7d1f87d5″,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”(10)”},{“type”:”text”,”marks”:[{“type”:”textstyle”,”attrs”:{“color”:””,”background”:””}},{“type”:”bold”}],”text”:”extra_hosts”},{“type”:”text”,”text”:”;添加主机名映射。类似 docker run –add-host。”}]},{“type”:”codeblock”,”attrs”:{“id”:”afe28a96-dd64-42e5-b25a-96b7ebe25431″,”language”:”yaml”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”yaml”},”content”:[{“type”:”text”,”text”:”extra_hosts:- “somehost:162.242.195.82”- “otherhost:50.31.209.229″”}]},{“type”:”paragraph”,”attrs”:{“id”:”0f005709-3a13-45aa-b860-11cfff125f8b”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”以上会在此服务的内部容器中 /etc/hosts 创建一个具有 ip 地址和主机名的映射关系:”}]},{“type”:”codeblock”,”attrs”:{“id”:”20054c31-e010-4bb0-acb9-5d48749dff66″,”language”:”yaml”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”txt”},”content”:[{“type”:”text”,”text”:”162.242.195.82 somehost(.31.209.229 otherhost”}]},{“type”:”paragraph”,”attrs”:{“id”:”e6e4e068-b7b3-4ef5-9a80-bddf50381d8e”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”(11)”},{“type”:”text”,”marks”:[{“type”:”textstyle”,”attrs”:{“color”:””,”background”:””}},{“type”:”bold”}],”text”:”healthcheck”},{“type”:”text”,”text”:”;用于检测 docker 服务是否健康运行。”}]},{“type”:”codeblock”,”attrs”:{“id”:”ad88ebc4-8e92-4ce8-9d32-42f3a3d5ddf2″,”language”:”yaml”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”yaml”},”content”:[{“type”:”text”,”text”:”healthcheck:test: [“cmd”, “curl”, “-f”, “http://localhost”] # 设置检测程序interval: 1m30s # 设置检测间隔timeout: 10s # 设置检测超时时间retries: 3 # 设置重试次数start_period: 40s # 启动后,多少秒开始启动检测程序”}]},{“type”:”paragraph”,”attrs”:{“id”:”2f131260-bdb0-4d59-a196-466a8bf1f2fe”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”(12)”},{“type”:”text”,”marks”:[{“type”:”textstyle”,”attrs”:{“color”:””,”background”:””}},{“type”:”bold”}],”text”:”image”},{“type”:”text”,”text”:”;指定容器运行的镜像。”},{“type”:”hardbreak”,”attrs”:{“id”:”995b76bd-abe8-41cb-ba98-dfd30e129b7c”}},{“type”:”text”,”text”:”以下格式都可以:”}]},{“type”:”codeblock”,”attrs”:{“id”:”ba1704be-6319-4c66-a132-0fbdee03a41e”,”language”:”yaml”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”yaml”},”content”:[{“type”:”text”,”text”:”image: redisimage: ubuntu:14.04image: tutum/influxdbimage: example-registry.com:4000/postgresqlimage: a4bc65fd # 镜像id”}]},{“type”:”paragraph”,”attrs”:{“id”:”5d9280ed-c0b3-42a5-9987-3dfa75871ba0″,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”(13)”},{“type”:”text”,”marks”:[{“type”:”textstyle”,”attrs”:{“color”:””,”background”:””}},{“type”:”bold”}],”text”:”logging”},{“type”:”text”,”text”:”;服务的日志记录配置。”},{“type”:”hardbreak”,”attrs”:{“id”:”c9fcb247-3f1f-4726-94a4-551441e92293″}},{“type”:”text”,”text”:”driver:指定服务容器的日志记录驱动程序,默认值为json-file。有以下三个选项。”}]},{“type”:”codeblock”,”attrs”:{“id”:”5ae3c5cb-f9a5-4d48-9e1d-696d97b079e6″,”language”:”yaml”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”yaml”},”content”:[{“type”:”text”,”text”:”driver: “json-file”driver: “syslog”driver: “none””}]},{“type”:”paragraph”,”attrs”:{“id”:”7c3dfd0a-8e81-4002-86dc-9ad47f9418df”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”仅在 json-file 驱动程序下,可以使用以下参数,限制日志得数量和大小。”}]},{“type”:”codeblock”,”attrs”:{“id”:”cab9ad50-9d89-4b29-8451-2535cbc8bff2″,”language”:”yaml”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”yaml”},”content”:[{“type”:”text”,”text”:”logging:driver: json-fileoptions:\tmax-size: “200k” # 单个文件大小为200k\tmax-file: “10” # 最多10个文件”}]},{“type”:”paragraph”,”attrs”:{“id”:”198f8650-5db3-4276-8542-88411ceb1394″,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”当达到文件限制上限,会自动删除旧得文件。”},{“type”:”hardbreak”,”attrs”:{“id”:”6c516edb-63c5-4d1a-98b2-445307da2cca”}},{“type”:”text”,”text”:”syslog 驱动程序下,可以使用 syslog-address 指定日志接收地址。”}]},{“type”:”codeblock”,”attrs”:{“id”:”c2733ad9-9b83-4b04-8bea-5ef47d2d53be”,”language”:”yaml”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”yaml”},”content”:[{“type”:”text”,”text”:”logging:driver: syslogoptions:\tsyslog-address: “tcp://192.168.0.106:123″”}]},{“type”:”paragraph”,”attrs”:{“id”:”43d1963a-d47f-4750-b824-5c4a289c23cf”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”(14)”},{“type”:”text”,”marks”:[{“type”:”textstyle”,”attrs”:{“color”:””,”background”:””}},{“type”:”bold”}],”text”:”restart。”}]},{“type”:”bulletlist”,”attrs”:{“id”:”25c7cf85-6111-4214-9aa7-0c4c2065725c”,”ishoverdraghandle”:false},”content”:[{“type”:”listitem”,”attrs”:{“id”:”1211a96b-143e-4770-96c7-90a459d66966″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”366005b6-4968-4f9b-94ab-db8470bc9968″,”textalign”:”inherit”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”no:当容器退出时,不要自动重新启动”}]}]},{“type”:”listitem”,”attrs”:{“id”:”fb68f199-5fa1-44fc-8423-c1531baa7b60″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”e839316d-71af-4023-b37d-5793e6ae132f”,”textalign”:”inherit”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”on-failure[:max-retries]:仅当容器以非零退出状态退出时才重新启动。”}]}]},{“type”:”listitem”,”attrs”:{“id”:”d7a6bad2-2b32-4f9b-aa91-37181b5ce567″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”95bb1601-c33a-497b-8451-4346812189e8″,”textalign”:”inherit”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”always:无论退出状态如何,始终重新启动容器。无论容器的当前状态如何,容器也将始终在守护程序启动时启动”}]}]},{“type”:”listitem”,”attrs”:{“id”:”7c080cc3-9faf-496f-81dc-79e02d017882″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”aa86c1a6-3598-41d7-bf7f-50e005870a90″,”textalign”:”inherit”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”unless-stopped:论退出状态如何,始终重新启动容器,包括守护程序启动时,除非容器在docker守护程序停止之前处于停止状态。”}]}]}]},{“type”:”codeblock”,”attrs”:{“id”:”0df9882f-bb17-4fc6-a19b-f677b34b85d0″,”language”:”yaml”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”yaml”},”content”:[{“type”:”text”,”text”:”restart: “no”estart: alwaysestart: on-failureestart: unless-stopped”}]},{“type”:”paragraph”,”attrs”:{“id”:”bc1af163-4db2-4d14-91f5-a89f5eecac78″,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”(15)”},{“type”:”text”,”marks”:[{“type”:”textstyle”,”attrs”:{“color”:””,”background”:””}},{“type”:”bold”}],”text”:”volumes”},{“type”:”text”,”text”:”;将主机的数据卷或着文件挂载到容器里。”}]},{“type”:”codeblock”,”attrs”:{“id”:”a632bf2e-ffe6-42d0-9e00-6c27bb17c863″,”language”:”yaml”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”yaml”},”content”:[{“type”:”text”,”text”:”version: “3.7”services:db:\timage: postgres:latest\tvolumes:\tt- “/localhost/postgres.sock:/var/run/postgres/postgres.sock”\tt- “/localhost/data:/var/lib/postgresql/data””}]},{“type”:”paragraph”,”attrs”:{“id”:”e9ede087-d317-4d1c-bed0-c2941903fe7a”,”textalign”:”justify”,”indent”:0,”color”:null,”background”:null,”ishoverdraghandle”:false},”content”:[{“type”:”text”,”text”:”(16)”},{“type”:”text”,”marks”:[{“type”:”textstyle”,”attrs”:{“color”:””,”background”:””}},{“type”:”bold”}],”text”:”networks”},{“type”:”text”,”text”:”;为容器指定网络。”}]},{“type”:”codeblock”,”attrs”:{“id”:”a1a0e38c-d3e3-4785-9c84-565638961b91″,”language”:”yaml”,”theme”:”atom-one-dark”,”runtimes”:0,”ishoverdraghandle”:false,”key”:””,”languagebyai”:”yaml”},”content”:[{“type”:”text”,”text”:”services:frontend:\timage: awesome/webapp\tnetworks:\ttfront-tier:\tttipv4_address: 172.16.238.10\tttipv6_address: 2001:3984:3989::10

etworks:front-tier:\tipam:\ttdriver: default\ttconfig:\ttt- subnet: “172.16.238.0/24″\ttt- subnet: “2001:3984:3989::/64″”}]},{“type”:”heading”,”attrs”:{“id”:”9dcae815-5380-499d-8432-3ca70cc7bf72″,”textAlign”:”justify”,”indent”:0,”level”:1,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”五、Compose 命令说明”}]},{“type”:”heading”,”attrs”:{“id”:”2bbdaf1a-2bd3-4f96-881d-1ed8c4f5db0f”,”textAlign”:”justify”,”indent”:0,”level”:2,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”5.1、命令对象与格式”}]},{“type”:”paragraph”,”attrs”:{“id”:”f782b1ef-89d2-49b8-bcaa-45b6fa8343c6″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”官方文档。”}]},{“type”:”paragraph”,”attrs”:{“id”:”3e46d92d-9179-428a-8ba1-7043e7969a09″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”对于 Compose 来说,大部分命令的对象既可以是项目本身,也可以指定为项目中的服务或者容器。如果没有特别的说明,命令对象将是项目,这意味着项目中所有的服务都会受到命令影响。”},{“type”:”hardBreak”,”attrs”:{“id”:”93892200-1a3b-4961-b854-63e1fe61875c”}},{“type”:”text”,”text”:”执行 docker-compose [COMMAND] –help 或者 docker-compose help [COMMAND] 可以查看具体某个”},{“type”:”hardBreak”,”attrs”:{“id”:”24cde885-ecb7-459f-8c12-217a2033ee51″}},{“type”:”text”,”text”:”命令的使用格式。”},{“type”:”hardBreak”,”attrs”:{“id”:”76fccf4d-d6ef-4c53-af4d-eba76d91d3bf”}},{“type”:”text”,”text”:”docker-compose 命令的基本的使用格式是”}]},{“type”:”codeBlock”,”attrs”:{“id”:”b0fd950b-9aa5-4a13-9a79-4e8a6718bcbd”,”language”:”bash”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”txt”},”content”:[{“type”:”text”,”text”:”docker-compose [-f=u003cargu003e…] [options] [COMMAND] [ARGS…]”}]},{“type”:”heading”,”attrs”:{“id”:”3ee678b4-c8bd-450e-b32c-612bf4d0db74″,”textAlign”:”justify”,”indent”:0,”level”:2,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”5.2、命令选项”}]},{“type”:”bulletList”,”attrs”:{“id”:”9316009f-38b8-44fa-8365-e8115d42c3f1″,”isHoverDragHandle”:false},”content”:[{“type”:”listItem”,”attrs”:{“id”:”9cfc608e-6ac5-409e-9ff9-0e22a922003f”},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”f284db81-ab0d-41b4-8bee-9650923557f0″,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”-f, –file FILE 指定使用的 Compose 模板文件,默认为 docker-compose.yml ,可以多次指定。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”e3dd4492-d257-4ac6-bd69-cc5a90cb77d7″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”8f587f81-9b0b-4b3a-bffb-a7865d0715a3″,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”-p, –project-name NAME 指定项目名称,默认将使用所在目录名称作为项目名。”}]}]}]},{“type”:”heading”,”attrs”:{“id”:”4f4e5a88-f909-4d82-8c19-5cd91ea48db3″,”textAlign”:”justify”,”indent”:0,”level”:2,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”5.3、命令使用详细说明”}]},{“type”:”paragraph”,”attrs”:{“id”:”3f6237aa-40b4-491a-8fb6-4fc423bfea5f”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”marks”:[{“type”:”textStyle”,”attrs”:{“color”:””,”background”:””}},{“type”:”bold”}],”text”:”(1)build。”},{“type”:”text”,”text”:” 格式为:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”a901d6b3-f1a2-40bd-a903-291183ae72c0″,”language”:”bash”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”bash”},”content”:[{“type”:”text”,”text”:”docker-compose build [options] [SERVICE…]”}]},{“type”:”paragraph”,”attrs”:{“id”:”2997be89-a95d-4db4-a3b4-0e9927e5ca6a”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”构建或重新构建项目中service的镜像。构建之后镜像不会被应用到容器,必须将项目down之后,再重新up方能使用最新镜像。构建的镜像会被加上项目名称的前缀。”},{“type”:”hardBreak”,”attrs”:{“id”:”b3a5ff49-96f3-4d1a-9a29-57caff4bb621″}},{“type”:”text”,”text”:”选项包括:”}]},{“type”:”bulletList”,”attrs”:{“id”:”17d58129-bc60-4dd9-8acc-cc59a39ca4e0″,”isHoverDragHandle”:false},”content”:[{“type”:”listItem”,”attrs”:{“id”:”b063b8fe-bc4b-460f-bdd4-d95aeba41247″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”9a487fdc-9555-46ee-bf19-f1a793d3a4c7″,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”–force-rm :删除构建过程中的临时容器。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”15f85dc4-ca86-4aec-bfbc-2d3991a6a697″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”a06413fc-2592-4158-8282-098c87841ef9″,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”–no-cache :构建镜像过程中不使用 cache(这将加长构建过程)。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”90a9b5af-2424-4f0c-82fe-0829c59f2679″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”93516f0a-6888-4a68-b5ef-3e246be5a1fc”,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”–pull :始终尝试通过 pull 来获取更新版本的镜像。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”1094dece-43b0-49b3-acd4-9f7880ff15e3″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”2f115f29-f222-48fb-ab52-18c44a888693″,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”–build-arg :设置构建参数”}]}]}]},{“type”:”paragraph”,”attrs”:{“id”:”7fb7c43f-7dde-4b21-aecf-077b474dea1d”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”(2)config。验证 Compose 文件格式是否正确,若正确则显示配置,若格式错误显示错误原因。”},{“type”:”hardBreak”,”attrs”:{“id”:”888f36d2-cd1b-4e6f-b9d7-07dad546d977″}},{“type”:”text”,”text”:”(3)down。此命令将会停止 up 命令所启动的容器,并移除网络。”},{“type”:”hardBreak”,”attrs”:{“id”:”9aae193d-f729-40b8-b7cd-74528030aaf2″}},{“type”:”text”,”text”:”(4)exec。进入指定的容器。”},{“type”:”hardBreak”,”attrs”:{“id”:”6f07f784-cf41-4ca7-8ca6-d72ee015a818″}},{“type”:”text”,”text”:”(5)help。获得一个命令的帮助。”},{“type”:”hardBreak”,”attrs”:{“id”:”10ebe4df-1d38-4f99-808b-f931b13dbab6″}},{“type”:”text”,”text”:”(6)images。列出 Compose 文件中包含的镜像。”},{“type”:”hardBreak”,”attrs”:{“id”:”cc140037-55d2-4f90-beed-b54a29cf1ed1″}},{“type”:”text”,”text”:”(7)kill。通过发送 SIGKILL 信号来强制停止服务容器。格式为:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”3a119483-7f1c-4945-81d2-7c778f0eb1d9″,”language”:”bash”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”powershell”},”content”:[{“type”:”text”,”text”:”docker-compose kill [options] [SERVICE…]”}]},{“type”:”paragraph”,”attrs”:{“id”:”b6e6840f-f2de-4c23-90cc-2692f31b820f”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”支持通过 -s 参数来指定发送的信号,例如通过如下指令发送 SIGINT 信号。”}]},{“type”:”codeBlock”,”attrs”:{“id”:”f9fdb8f9-d3a8-4642-a7e8-526f28597051″,”language”:”bash”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”bash”},”content”:[{“type”:”text”,”text”:”docker-compose kill -s SIGINT”}]},{“type”:”paragraph”,”attrs”:{“id”:”804d7534-d04e-4883-91dd-70e416219848″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”(8)logs。查看服务容器的输出。格式为:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”6d9f8f63-822f-4c9b-877d-3be594843853″,”language”:”bash”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”txt”},”content”:[{“type”:”text”,”text”:”docker-compose logs [options] [SERVICE…] “}]},{“type”:”paragraph”,”attrs”:{“id”:”f3d381b1-c504-44ff-bb22-c376e8f1139b”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”默认情况下,docker-compose 将对不同的服务输出使用不同的颜色来区分。”},{“type”:”hardBreak”,”attrs”:{“id”:”dd156919-1fa8-4c33-a114-c8f795a23da1″}},{“type”:”text”,”text”:”可以通过 –no-color 来关闭颜色。”},{“type”:”hardBreak”,”attrs”:{“id”:”9b8fa27d-80ce-49e7-855c-ed2045f1da4d”}},{“type”:”text”,”text”:”该命令在调试问题的时候十分有用。”}]},{“type”:”paragraph”,”attrs”:{“id”:”e7048113-572a-4469-8072-ac99928493ea”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”(9)pause。暂停一个服务容器。格式为:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”55730796-8a86-44b4-8ab9-d07d4c5c28c1″,”language”:”bash”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”bash”},”content”:[{“type”:”text”,”text”:”docker-compose pause [SERVICE…] “}]},{“type”:”paragraph”,”attrs”:{“id”:”40eb9760-4ff6-47fb-aac7-cf69e13f2285″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”(10)port。打印某个容器端口所映射的公共端口。格式为:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”693d6d01-4e40-4f36-959e-944e5d6cd1d5″,”language”:”bash”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”bash”},”content”:[{“type”:”text”,”text”:”docker-compose port [options] SERVICE PRIVATE_PORT”}]},{“type”:”paragraph”,”attrs”:{“id”:”465614ce-6c60-431e-881e-2837db99b948″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”选项:”}]},{“type”:”bulletList”,”attrs”:{“id”:”01d86ff5-ec0c-40bb-b9a7-294b0d704fd4″,”isHoverDragHandle”:false},”content”:[{“type”:”listItem”,”attrs”:{“id”:”5a0e30b3-6506-4acb-b90c-c7c5f4a1655b”},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”43b6eda3-cd4d-4c48-ba21-f869f532c33d”,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”–protocol=proto 指定端口协议,tcp(默认值)或者 udp。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”f4de65b6-042c-4e61-bdba-bea3b9e6573a”},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”bae8698f-03db-41d2-8351-0c9b91c327d2″,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”–index=index 如果同一服务存在多个容器,指定命令对象容器的序号(默认为 1)。”}]}]}]},{“type”:”paragraph”,”attrs”:{“id”:”8bcdd406-710b-49d1-8f34-df252885929b”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”(11)ps。列出项目中目前的所有容器。格式为:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”1af6d641-c0c9-46f0-a7fa-638160b1e54a”,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”docker-compose ps [options] [SERVICE…]”}]},{“type”:”paragraph”,”attrs”:{“id”:”d24bde7e-d458-4ad7-97d3-a4ad728867e2″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”选项:-“},{“type”:”text”,”marks”:[{“type”:”textStyle”,”attrs”:{“color”:”rgba(0, 0, 0, 0.9)”,”background”:””}}],”text”:”q 只打印容器的 ID 信息。”}]},{“type”:”paragraph”,”attrs”:{“id”:”ca868bc1-46ec-46c2-a545-b29fad68ef6f”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”(12)pull。拉取服务依赖的镜像。格式为:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”880d739c-a237-4bbe-a356-f424bc4bafc8″,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”docker-compose pull [options] [SERVICE…] “}]},{“type”:”paragraph”,”attrs”:{“id”:”b30b6fc2-ea33-4959-bd6a-e109d34fbc2f”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”marks”:[{“type”:”textStyle”,”attrs”:{“color”:”rgba(0, 0, 0, 0.9)”,”background”:””}}],”text”:”  –ignore-pull-failures选项:忽略拉取镜像过程中的错误。”}]},{“type”:”paragraph”,”attrs”:{“id”:”3d29329b-5143-4837-a809-ab11a7ba306d”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”(13)push。推送服务依赖的镜像到 Docker 镜像仓库。”}]},{“type”:”paragraph”,”attrs”:{“id”:”11d1752c-500b-4f28-9a6e-97d5e93634cf”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”(14)restart。重启项目中的服务。格式为:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”b85b911f-0bf4-4e77-b51e-9684d26c08c9″,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”docker-compose restart [options] [SERVICE…] “}]},{“type”:”paragraph”,”attrs”:{“id”:”48e0848b-2bba-423a-947f-f3451bfd1692″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”-“},{“type”:”text”,”marks”:[{“type”:”textStyle”,”attrs”:{“color”:”rgba(0, 0, 0, 0.9)”,”background”:””}}],”text”:”t, –timeout TIMEOUT”},{“type”:”text”,”marks”:[{“type”:”textStyle”,”attrs”:{“color”:”rgb(77, 77, 77)”,”background”:””}}],”text”:”选项”},{“type”:”text”,”marks”:[{“type”:”textStyle”,”attrs”:{“color”:”rgba(0, 0, 0, 0.9)”,”background”:””}}],”text”:”:指定重启前停止容器的超时(默认为 10 秒)。”}]},{“type”:”paragraph”,”attrs”:{“id”:”27c2b2b5-26ad-49dc-97f2-3eb90fcccc05″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”(15)rm。删除所有(停止状态的)服务容器。推荐先执行 docker-compose stop 命令来停止容器。格式为:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”7f567032-bbe0-4ba7-bccc-5d8ae78ed00c”,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”docker-compose rm [options] [SERVICE…] “}]},{“type”:”paragraph”,”attrs”:{“id”:”6d6bdcda-cf9e-472e-99f3-e7cf38aa1a14″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”选项:”}]},{“type”:”bulletList”,”attrs”:{“id”:”2f9e49b8-ed1f-4de7-856f-d814375059c3″,”isHoverDragHandle”:false},”content”:[{“type”:”listItem”,”attrs”:{“id”:”1c763d84-d7c6-464d-b4a4-cfeea3a0e2e6″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”d0803ec4-6bfc-4442-8d58-a8018b7fe401″,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”-f, –force 强制直接删除,包括非停止状态的容器。一般尽量不要使用该选项。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”f434e15a-945b-45ec-8f23-671a9dd25658″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”12817822-0888-49d0-aa09-9bf8ddc87e1f”,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”-v 删除容器所挂载的数据卷。”}]}]}]},{“type”:”paragraph”,”attrs”:{“id”:”27f167f9-a5b1-41ee-95b9-6da4bb097cd1″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”marks”:[{“type”:”textStyle”,”attrs”:{“color”:””,”background”:””}},{“type”:”bold”}],”text”:”(16)run”},{“type”:”text”,”text”:”。在指定服务上执行一个命令,类似docker run指令。格式为:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”ba482838-f793-4f7d-8567-8f5d89ce8200″,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”docker-compose run [options] [-p PORT…] [-e KEY=VAL…] SERVICE [COMMAND] [ARGS…] “}]},{“type”:”paragraph”,”attrs”:{“id”:”9e2da5de-30a4-4eeb-8f74-80b2f8c2f467″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”示例:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”37119717-e945-4c2d-aebb-561e3e1919a2″,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”docker-compose run redis pwd”}]},{“type”:”paragraph”,”attrs”:{“id”:”0a95b3a1-c7aa-484b-afb4-1dfacb9f40f3″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”将会基于指定的service的镜像启动一个新的容器,并且运行指定命令。”},{“type”:”hardBreak”,”attrs”:{“id”:”895f197c-71c2-4c18-8214-f21e4bd70484″}},{“type”:”text”,”text”:”默认情况下,如果存在关联,则所有关联的服务将会自动被启动,除非这些服务已经在运行中。”},{“type”:”hardBreak”,”attrs”:{“id”:”59b93a15-1c6e-40f3-a385-c63141b2182f”}},{“type”:”text”,”text”:”该命令类似启动容器后运行指定的命令,相关卷、链接等等都将会按照配置自动创建。”},{“type”:”hardBreak”,”attrs”:{“id”:”6516547b-d871-47ac-95fc-c8c1843928bb”}},{“type”:”text”,”text”:”两个不同点:”}]},{“type”:”bulletList”,”attrs”:{“id”:”52c14b6e-c870-4c59-90bb-c651910ab567″,”isHoverDragHandle”:false},”content”:[{“type”:”listItem”,”attrs”:{“id”:”741d796f-9c66-4dce-bd4f-4d3c23cac195″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”ead7fc4e-08b1-4ca9-adc0-159aa313a13e”,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”给定命令将会覆盖原有的自动运行命令;”}]}]},{“type”:”listItem”,”attrs”:{“id”:”da52b5fc-bac0-483f-8ac1-83d0495f6f30″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”bd02ff0d-80d3-4a51-b9e6-26c201ef8970″,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”不会自动创建端口,以避免冲突。”}]}]}]},{“type”:”paragraph”,”attrs”:{“id”:”49465a4d-1827-4949-91fd-50b5e7f22862″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”如果不希望自动启动关联的容器,可以使用 –no-deps 选项,例如:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”ec348936-45f7-4e21-a827-db2e1788ee1b”,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”# 该操作为伪操作docker-compose run –no-deps web pwd”}]},{“type”:”paragraph”,”attrs”:{“id”:”32ebda07-d42f-470b-8fce-219584511481″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”将不会启动 web 容器所关联的其它容器。”},{“type”:”hardBreak”,”attrs”:{“id”:”46f4ffbb-8018-499b-8f3e-472c931d7bfe”}},{“type”:”text”,”text”:”选项:”}]},{“type”:”bulletList”,”attrs”:{“id”:”1c919bab-fa7e-475d-9bf3-2d37765428a8″,”isHoverDragHandle”:false},”content”:[{“type”:”listItem”,”attrs”:{“id”:”a296db19-353f-4ade-a26f-34abefaea2e9″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”b81a7d39-d1b9-4d64-a5c7-f981724f3440″,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”-d 后台运行容器。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”df21d62f-6491-4f15-8d14-2ac71bcf548e”},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”3d7184c9-a333-4962-a127-c752e6a10f71″,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”–name NAME 为容器指定一个名字。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”021a6590-5ba9-4a1e-93bc-263a5be25c75″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”950d313b-a9a7-4824-9c72-45c6e7b0814c”,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”–entrypoint CMD 覆盖默认的容器启动指令。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”45f9a09a-a80e-42d2-b625-78aaaf5e8301″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”9295d6b2-61d3-4222-a07b-a5c380896280″,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”–e KEY=VAL 设置环境变量值,可多次使用选项来设置多个环境变量。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”3f80358d-44ab-4e2f-9645-69d34dcf88ea”},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”c3c59d87-7e0c-435c-88f1-771dfcdf7475″,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”-u, –user=“” 指定运行容器的用户名或者 uid。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”0a3b4f64-cd77-4dc8-a049-f25baff771a2″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”aad36cb9-0880-4498-ad8e-a75ee5862bc7″,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”–no-deps 不自动启动关联的服务容器。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”1e5158ad-9592-4dfb-92e8-789f98a2c2da”},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”0b0c9c70-9771-41d8-bc20-0216bb44054e”,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”–rm 运行命令后自动删除容器, d 模式下将忽略。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”4c4f8874-04d6-4cc2-8717-9a853b932238″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”95ec8e3d-f4db-4dfa-a863-2c75c39bdea2″,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”-p, –publish=[] 映射容器端口到本地主机。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”89439ebb-0450-46cf-9772-9c410ff1a87a”},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”20d6f82d-9284-48eb-b2cb-12f55f33b82c”,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”–service-ports 配置服务端口并映射到本地主机。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”c3357104-ea47-4f9a-8311-39766f18b070″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”bfec73d7-48f8-423d-a531-bc5a0bc40a73″,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”-T 不分配伪 tty,意味着依赖 tty 的指令将无法运行。”}]}]}]},{“type”:”paragraph”,”attrs”:{“id”:”363fd0b5-38d9-49fb-a640-e4b21ec077a4″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”(17 )start。启动已经存在的服务。格式为:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”548f09a0-a755-4ed0-89b4-8e1d78a30d98″,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”docker-compose start [SERVICE…]”}]},{“type”:”paragraph”,”attrs”:{“id”:”79146e32-1ede-4958-9071-02db3e02402f”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”(18)stop。停止已经处于运行状态的服务,但不删除它。通过 docker-compose start 可以再次启动这些服务。格式为:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”cd351581-9e89-480d-98de-b31f183c0dfc”,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”docker-compose stop [options] [SERVICE…] “}]},{“type”:”paragraph”,”attrs”:{“id”:”ab14e29e-bfb5-48c1-b876-9929becd42cd”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”marks”:[{“type”:”textStyle”,”attrs”:{“color”:”rgba(0, 0, 0, 0.9)”,”background”:””}}],”text”:”-t, –timeout TIMEOUT “},{“type”:”text”,”marks”:[{“type”:”textStyle”,”attrs”:{“color”:”rgb(77, 77, 77)”,”background”:””}}],”text”:”选项:”},{“type”:”text”,”marks”:[{“type”:”textStyle”,”attrs”:{“color”:”rgba(0, 0, 0, 0.9)”,”background”:””}}],”text”:”停止容器时候的超时(默认为 10 秒)。”}]},{“type”:”paragraph”,”attrs”:{“id”:”027e8e8d-a6e8-4bc4-befc-dc740b9cdcc1″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”(19)top。查看各个服务内运行的进程。”},{“type”:”hardBreak”,”attrs”:{“id”:”ea944268-5456-4267-880e-1844d8f0812d”}},{“type”:”text”,”text”:”(20)unpause。恢复处于暂停状态中的服务。格式为:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”7178ab65-f063-4f84-ba0b-30c4b62c0a70″,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”docker-compose unpause [SERVICE…] “}]},{“type”:”paragraph”,”attrs”:{“id”:”ee4a12b3-9e93-4527-9ad5-4699dc26be79″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”(21)version。打印版本信息。格式为:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”a954891c-da1d-4852-bea9-4b65948bf28e”,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”docker-compose version”}]},{“type”:”paragraph”,”attrs”:{“id”:”be720a08-f302-40e5-8140-f48c9c771623″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”marks”:[{“type”:”textStyle”,”attrs”:{“color”:””,”background”:””}},{“type”:”bold”}],”text”:”(22)up。”},{“type”:”text”,”text”:” 该命令十分强大,它将尝试自动完成包括构建镜像,(重新)创建服务,启动服务,并关联服务相关容”},{“type”:”hardBreak”,”attrs”:{“id”:”a39a4d2e-35fc-4433-80e4-bc1877ce32f5″}},{“type”:”text”,”text”:”器的一系列操作。”},{“type”:”hardBreak”,”attrs”:{“id”:”45040b42-dd33-4cae-8913-472f62e3de86″}},{“type”:”text”,”text”:”格式为:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”37c84b67-731c-484a-b910-6fdf302915c4″,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”docker-compose up [options] [SERVICE…] “}]},{“type”:”paragraph”,”attrs”:{“id”:”94c4ea47-e3ed-4142-bd12-88d67084d6fe”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”链接的服务都将会被自动启动,除非已经处于运行状态。”},{“type”:”hardBreak”,”attrs”:{“id”:”35d540ff-ef41-41e6-8abe-b91f6eabc758″}},{“type”:”text”,”text”:”可以说,大部分时候都可以直接通过该命令来启动一个项目。”}]},{“type”:”paragraph”,”attrs”:{“id”:”fb05541b-6ad2-4883-98cb-9fd61c796f1f”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”默认情况, docker-compose up 启动的容器都在前台,控制台将会同时打印所有容器的输出信息,可以很方便进行调试。”},{“type”:”hardBreak”,”attrs”:{“id”:”0f55a3a2-ea6e-46ba-afa1-5cd528e0c7d6″}},{“type”:”text”,”text”:”当通过 Ctrl-C 停止命令时,所有容器将会停止。”}]},{“type”:”paragraph”,”attrs”:{“id”:”42426956-d00d-4002-988e-73f3b720c7a0″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”如果使用 docker-compose up -d ,将会在后台启动并运行所有的容器。一般推荐生产环境下使用该选项。”}]},{“type”:”paragraph”,”attrs”:{“id”:”0a755c42-209d-4926-95ea-987be217ea86″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”默认情况,如果服务容器已经存在, docker-compose up 将会尝试停止容器,然后重新创建(保持使用 volumes-from 挂载的卷),以保证新启动的服务匹配 docker-compose.yml 文件的最新内容。如果用户不希望容器被停止并重新创建,可以使用 docker-compose up –no-recreate 。这样将只会启动处于停止状态的容器,而忽略已经运行的服务。如果用户只想重新部署某个服务,可以使用 docker-compose up –no-deps -d u003c SERVICE_NAME u003e 来重新创建服务并后台停止旧服务,启动新服务,并不会影响到其所依赖的服务。”}]},{“type”:”paragraph”,”attrs”:{“id”:”f84090ce-0523-4726-ae6a-986c925cea0d”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”选项:”}]},{“type”:”bulletList”,”attrs”:{“id”:”4046bced-37ac-4b73-b880-eeefa298d92f”,”isHoverDragHandle”:false},”content”:[{“type”:”listItem”,”attrs”:{“id”:”c134fd8f-0efa-472e-980e-45e14dab5434″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”9a3f4db1-54ec-480c-b82f-158505e58050″,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”-d 在后台运行服务容器。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”9f0227a5-a357-4996-b387-0d40f936d6a7″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”d6fff5df-c016-4dc6-8aa1-c51aae17553e”,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”–no-color 不使用颜色来区分不同的服务的控制台输出。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”ab97de6c-3f68-496e-b51f-734a1b725182″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”d59c05a6-5646-47cf-89f2-bb0e6da71146″,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”–no-deps 不启动服务所链接的容器。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”43b4613d-e0e1-4c96-852b-c685b6081579″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”8abde6cb-765e-4690-8c51-93b812e5f72f”,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”–force-recreate 强制重新创建容器,不能与 –no-recreate 同时使用。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”6ea15d9f-22fe-4349-b1d4-45c31a251cf2″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”f27d8a3f-9759-4ea9-8e99-322bf1b10a99″,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”–no-recreate 如果容器已经存在了,则不重新创建,不能与 –force-recreate 同时使用。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”a7c47c55-19e0-46b9-b014-e90fc2be3062″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”62a8d9d4-61f7-4d9a-b5f8-4e63530e59eb”,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”–no-build 不自动构建缺失的服务镜像。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”3426fa75-7308-40ed-8a1f-f683af44a7fe”},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”e3c55254-830b-47ab-848b-8b03e84b5e0f”,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”-t, –timeout TIMEOUT 停止容器时候的超时(默认为 10 秒)。”}]}]}]},{“type”:”heading”,”attrs”:{“id”:”f30daa8d-1ca7-4d85-bca1-6d4d77e02d8d”,”textAlign”:”justify”,”indent”:0,”level”:1,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”六、compose使用案例”}]},{“type”:”heading”,”attrs”:{“id”:”d9db4ece-2e44-4f80-a92d-256459488baa”,”textAlign”:”justify”,”indent”:0,”level”:2,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”6.1、准备”}]},{“type”:”paragraph”,”attrs”:{“id”:”f18cdf93-f669-4888-a427-bede1e536112″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”获取代码:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”8a9c2579-9d8c-4016-97ff-6ef10ac3f405″,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”git clone https://gitee.com/long-xu/helloworld.git”}]},{“type”:”heading”,”attrs”:{“id”:”25c8459f-3ac7-49fd-a03d-8984f5215451″,”textAlign”:”justify”,”indent”:0,”level”:2,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”6.2、Dockerfile 文件”}]},{“type”:”paragraph”,”attrs”:{“id”:”de8897bc-0773-4ca9-8666-3e7fac8cf1d3″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”在 helloworld 目录中,创建一个名为的文件 Dockerfile,内容如下:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”b9992fe0-2031-46fd-9846-caae0eaba1cf”,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”FROM golang:1.18ADD ./ /go/src/helloworld/WORKDIR /go/src/helloworldRUN go env -w GOPROXY=$http_proxy# RUN go env -w GOPROXY=https://proxy.golang.com.cn,https://goproxy.cn,directRUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o app .FROM ubuntu:latestCOPY ./curl-amd64 /usr/bin/curlRUN chmod +x /usr/bin/curlENV env1=env1valueENV env2=env2valueMAINTAINER nickWORKDIR /app/COPY –from=0 /go/src/helloworld/app ./EXPOSE 80ENTRYPOINT [“./app”]CMD [“–param1=p1″,”–param2=p2″]”}]},{“type”:”paragraph”,”attrs”:{“id”:”ff39faef-7ddf-464a-8c90-2afc7a22baaa”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”构建镜像:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”6f5401fe-1f85-472d-b609-80627dbfffdf”,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”docker build -t hello:1.0.0 -f Dockerfile –build-args http_proxy=https://proxy.golang.com.cn,https://goproxy.cn,direct .”}]},{“type”:”heading”,”attrs”:{“id”:”7e9ed792-de38-4410-aba3-fa4475de7d1d”,”textAlign”:”justify”,”indent”:0,”level”:2,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”6.3、docker-compose.yml”}]},{“type”:”paragraph”,”attrs”:{“id”:”00c40114-76e2-44a9-9318-0bf2b314e488″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”注意:以两个空格分层级。”}]},{“type”:”codeBlock”,”attrs”:{“id”:”74f640ab-2255-4720-8f1e-bb21ab8674bf”,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”version: ‘3.7’# 定义项目中的服务services: # 名为web的服务 web: # 根据配置构建镜像 build: # 构建镜像的上下文 context: . #构建镜像的dockerfile dockerfile: Dockerfile.compose # 构建参数 args: http_proxy: https://proxy.golang.com.cn,https://goproxy.cn,direct # 设置labels元数据 labels: myhello: 1.0 com.example.description: “Accounting webapp” # 为构建的镜像指定tags tags: – “myhello:1.0.0” – “localhost:5000/myhello:1.0.0” # 指定容器名称 container_name: “myweb” # 设置容器依赖关系,表示web服务依赖于redis服务 depends_on: – redis # 运行容器的端口映射 ports: – “80:80” # 覆盖容器的cmd指令 command: [“–param1=1″,”–param2=2″] # 设置环境变量 environment: env1: “a” env2: “b” # 健康检查 healthcheck: # 检查命令 #test: [“CMD”,”curl”,”http://localhost/health”] test: [“CMD-SHELL”,”statuscode=`curl -o /dev/null -s -w %{http_code} http://localhost/health`; [ $$statuscode -le 400 ] || exit 1″] # 检查时间间隔 interval: 5s # 检查超时时间 timeout: 1s # 重试次数,即连续失败指定次数则判定为不健康 retries: 5 # 设置容器初始化时间,再次期间不报告健康检查状态 start_period: 5s # 使用定义的网络 networks: – mynetwork – net1 # 名为 redis的服务 redis: # 服务启动镜像 image: “redis:latest” container_name: “myredis” # 容器暴露端口 expose: – 6379 # 指定容器启动命令,即覆盖cmd指令 command: redis-server –requirepass 123456 # 数据卷设置 volumes: – /data networks: – mynetwork – net2# 定义网络

etworks: net1: {} net2: {} mynetwork: ipam: driver: default config: – subnet: “172.16.238.0/24″”}]},{“type”:”paragraph”,”attrs”:{“id”:”a35ced9a-500b-4150-9ccb-7646382cdc22″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”检查配置文件的有效性:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”1aeff5f1-69d8-4e48-ae97-916718a21fc6″,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”docker-compose -f docker-compose.yml config”}]},{“type”:”heading”,”attrs”:{“id”:”2fddfb35-61bc-4602-8f3e-170008010cac”,”textAlign”:”justify”,”indent”:0,”level”:2,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”6.4、使用 Compose 命令构建和运行应用”}]},{“type”:”paragraph”,”attrs”:{“id”:”4588d0da-549a-442b-85f6-91c767cb3065″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”先将刚才写的Dockerfile重命令为Dockerfile.compose:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”df6e7317-d924-45c1-becc-1bef4a7b20a4″,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”cp Dockerfile Dockerfile.compose”}]},{“type”:”paragraph”,”attrs”:{“id”:”dc7806e9-0f1e-4c1a-ba28-4761458cb75b”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”在helloworld目录中,执行以下命令来启动应用程序:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”f811ef9e-88a9-49b8-992f-573bcc7c98f0″,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”docker-compose up”}]},{“type”:”paragraph”,”attrs”:{“id”:”aff91c89-a5af-4232-bdf6-d37bb1f3f9fd”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”如果你想在后台执行该服务可以加上 -d 参数:docker-compose up -d”},{“type”:”hardBreak”,”attrs”:{“id”:”b0bf98bf-b1f8-48d1-83de-c1e156b5e3a3″}},{“type”:”text”,”text”:”运行后的效果:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”562c797d-b394-44a1-9318-955fcb651b35″,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”[+] Building 20.6s (15/16) =u003e [internal] load build definition from Dockerfile.compose 0.0s =u003e =u003e transferring dockerfile: 527B 0.0s =u003e [internal] load .dockerignore 0.0s =u003e =u003e transferring context: 2B 0.0s =u003e [internal] load metadata for docker.io/library/ubuntu:latest 0.0s =u003e [internal] load metadata for docker.io/library/golang:1.18 0.0s =u003e [stage-0 1/5] FROM docker.io/library/golang:1.18 20.5s =u003e [stage-1 1/5] FROM docker.io/library/ubuntu:latest 0.0s =u003e [internal] load build context 0.1s =u003e =u003e transferring context: 5.43MB 0.1s =u003e [stage-0 2/5] ADD ./helloworld /go/src/helloworld/ 0.1s =u003e [stage-1 2/5] COPY ./helloworld/curl-amd64 /usr/bin/curl 0.1s =u003e [stage-0 3/5] WORKDIR /go/src/helloworld 0.1s =u003e [stage-1 3/5] RUN chmod +x /usr/bin/curl 1.1s =u003e [stage-0 4/5] RUN go env -w GOPROXY=https://proxy.golang.com.cn,https://goproxy.cn,direct 1.1s =u003e [stage-1 4/5] WORKDIR /app/ 0.0s =u003e [stage-0 5/5] RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o app ./ 19.0s =u003e [stage-1 5/5] COPY –from=0 /go/src/helloworld/app ./ 0.1s =u003e exporting to image 0.1s =u003e =u003e exporting layers 0.1s =u003e =u003e writing image sha256:807800f9f2eef849451f4107c1b422550f2ec0afea34831cee05389aa5670b96 0.0s =u003e =u003e naming to docker.io/library/compose-web 0.0s =u003e =u003e naming to docker.io/library/myhello:1.0.0 0.0s =u003e =u003e naming to localhost:5000/myhello:1.0.0 0.0s[+] Running 5/5 ⠿ Network compose_mynetwork Created 0.1s ⠿ Network compose_net1 Created 0.1s ⠿ Network compose_net2 Created 0.1s ⠿ Container myredis Started 1.1s ⠿ Container myweb Started”}]},{“type”:”paragraph”,”attrs”:{“id”:”59ed3e01-573c-4f4e-8bff-d97451708362″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”启动之后可以使用docker命令操作我们的容器,也可以用docker-compose操作(前提是在当前项目文件夹下,如果离开文件夹,docker-compose就会找不到项目;当然,也可以用-f和-p指定项目,但是略显麻烦)。”}]},{“type”:”paragraph”,”attrs”:{“id”:”c28bf18b-2763-42f1-bc32-5d62528dfd5d”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”以上创建了一个网络,一个Redis 和 一个web;postman调用接口访问redis。”}]},{“type”:”paragraph”,”attrs”:{“id”:”db53a468-aa7f-4d12-9d15-7c9dac216b51″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”进入redis容器,查看redis数据:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”a98c1fec-5dcf-4066-86fb-aac67d516595″,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”fly@fly:~/wokspace/compose$ docker-compose exec -t redis bashoot@e964e083eb70:/data# redis-cli 7.0.0.1:6379u003e auth 123456OK7.0.0.1:6379u003e set fly 100OK7.0.0.1:6379u003e get fly”100″7.0.0.1:6379u003e “}]},{“type”:”paragraph”,”attrs”:{“id”:”476f2341-4ce3-47f2-928f-6ffaa0784b55″,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”查看docker 网络信息:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”6a0a0901-2499-4982-995c-41f0a13597be”,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”docker network lsdocker network inspect compose_mynetwork”}]},{“type”:”paragraph”,”attrs”:{“id”:”39f28810-0a83-4541-957f-4f6677bd660f”,”textAlign”:”justify”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”示例:”}]},{“type”:”codeBlock”,”attrs”:{“id”:”09c95b95-fbaa-4940-8cd0-79accce55398″,”language”:”javascript”,”theme”:”atom-one-dark”,”runtimes”:0,”isHoverDragHandle”:false,”key”:””,”languageByAi”:”javascript”},”content”:[{“type”:”text”,”text”:”fly@fly:~/wokspace/compose$ docker network lsNETWORK ID NAME DRIVER SCOPE0d6cdc5d9c2 bridge bridge local19d219e8db compose_mynetwork bridge locald16736c9b2b2 compose_net1 bridge localc35403e62f compose_net2 bridge localf3915547ea host host local1b056f00f28 none null locally@fly:~/wokspace/compose$ docker network inspect compose_mynetwork[ { “Name”: “compose_mynetwork”, “Id”: “4919d219e8dbb590184068aee81a300ef743c2ce394814a731b6039afb375fae”, “Created”: “2023-03-13T08:16:41.008573796Z”, “Scope”: “local”, “Driver”: “bridge”, “EnableIPv6”: false, “IPAM”: { “Driver”: “default”, “Options”: null, “Config”: [ { “Subnet”: “172.16.238.0/24” } ] }, “Internal”: false, “Attachable”: false, “Ingress”: false, “ConfigFrom”: { “Network”: “” }, “ConfigOnly”: false, “Containers”: { “e964e083eb705147ae4bafe90b737efabb873d6ee13f574279650f67118f4f12”: { “Name”: “myredis”, “EndpointID”: “2fc0d07deff5002a28491cd9daa5308dbb8253914f3d8d104bcc196ad43f4a3b”, “MacAddress”: “02:42:ac:10:ee:02”, “IPv4Address”: “172.16.238.2/24”, “IPv6Address”: “” }, “fdacf2b5ce8eb9c5c8a90ec52333b5e68674cb30f5569feede7a4ed58238e5af”: { “Name”: “myweb”, “EndpointID”: “0118db8855a2b668f8c2cfc13042c28e339cde3e2d2ed18f63447d4752c608bf”, “MacAddress”: “02:42:ac:10:ee:03”, “IPv4Address”: “172.16.238.3/24”, “IPv6Address”: “” } }, “Options”: {}, “Labels”: { “com.docker.compose.network”: “mynetwork”, “com.docker.compose.project”: “compose”, “com.docker.compose.version”: “2.12.2” } }]”}]},{“type”:”heading”,”attrs”:{“id”:”9d977565-2a04-4ed6-8252-0c5a24f82370″,”textAlign”:”justify”,”indent”:0,”level”:1,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”七、总结”}]},{“type”:”orderedList”,”attrs”:{“id”:”14f16374-563e-4ad8-ac2e-9d186b7d3809″,”start”:1,”isHoverDragHandle”:false},”content”:[{“type”:”listItem”,”attrs”:{“id”:”27fea550-4e41-49e0-93bf-2acc2dc2cd8c”},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”e633175c-214f-42fc-a3af-8058eae4f6ad”,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”重点1,学会compose.yml文件如何配置。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”4b1b9853-ebc4-434e-b225-97d234b3ee71″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”23caadb9-de16-49fc-b0a6-b3c5bb2ad20b”,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”重点2,compose命令的使用。”}]}]},{“type”:”listItem”,”attrs”:{“id”:”edb7ab3a-af75-482e-abcd-814a206416d5″},”content”:[{“type”:”paragraph”,”attrs”:{“id”:”ae5afd46-2321-4d43-b93b-bed8dff7808d”,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false},”content”:[{“type”:”text”,”text”:”compose针对的目标对象是项目service。”}]}]}]},{“type”:”image”,”attrs”:{“id”:”7d2231f8-1d0b-449a-8169-651a332cfeac”,”src”:”https://developer.qcloudimg.com/http-save/audit-11218869/8975f4e5296b4625bdf6f179d3ae113a.png”,”extension”:”png”,”align”:”center”,”alt”:””,”showAlt”:false,”href”:””,”boxShadow”:””,”width”:1080,”aspectRatio”:”3.600000″,”status”:”success”,”showText”:true,”isPercentage”:false,”percentage”:0,”isHoverDragHandle”:false}},{“type”:”paragraph”,”attrs”:{“id”:”c6506e15-433f-43c3-9052-9ba4eb020756″,”textAlign”:”inherit”,”indent”:0,”color”:null,”background”:null,”isHoverDragHandle”:false}}]}

Creatext AI Creatext AI

专为销售人员提供的 AI 咨询辅助工具

Creatext AI 39 查看详情 Creatext AI

以上就是【容器编排魔法】Docker容器编排神器Componse完全解析!的详细内容,更多请关注php中文网其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/986597.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2025年12月1日 21:29:31
下一篇 2025年12月1日 21:29:53

相关推荐

  • AO3镜像站备用镜像网址_AO3镜像站快速访问官网

    AO3镜像站备用网址包括ao3mirror.com和xiaozhan.icu,当主站archiveofourown.org无法访问时可切换使用,二者均同步更新内容并支持多语言检索与离线下载功能。 AO3镜像站备用镜像网址在哪里?这是不少网友都关注的,接下来由PHP小编为大家带来AO3镜像站快速访问官…

    2025年12月6日 软件教程
    200
  • Pboot插件缓存机制的详细解析_Pboot插件缓存清理的命令操作

    插件功能异常或页面显示陈旧内容可能是缓存未更新所致。PbootCMS通过/runtime/cache/与/runtime/temp/目录缓存插件配置、模板解析结果和数据库查询数据,提升性能但影响调试。解决方法包括:1. 手动删除上述目录下所有文件;2. 后台进入“系统工具”-“缓存管理”,勾选插件、…

    2025年12月6日 软件教程
    400
  • Linux中如何安装Nginx服务_Linux安装Nginx服务的完整指南

    首先更新系统软件包,然后通过对应包管理器安装Nginx,启动并启用服务,开放防火墙端口,最后验证欢迎页显示以确认安装成功。 在Linux系统中安装Nginx服务是搭建Web服务器的第一步。Nginx以高性能、低资源消耗和良好的并发处理能力著称,广泛用于静态内容服务、反向代理和负载均衡。以下是在主流L…

    2025年12月6日 运维
    000
  • Linux journalctl与systemctl status结合分析

    先看 systemctl status 确认服务状态,再用 journalctl 查看详细日志。例如 nginx 启动失败时,systemctl status 显示 Active: failed,journalctl -u nginx 发现端口 80 被占用,结合两者可快速定位问题根源。 在 Lin…

    2025年12月6日 运维
    100
  • TikTok视频无法下载怎么办 TikTok视频下载异常修复方法

    先检查链接格式、网络设置及工具版本。复制以https://www.tiktok.com/@或vm.tiktok.com开头的链接,删除?后参数,尝试短链接;确保网络畅通,可切换地区节点或关闭防火墙;更新工具至最新版,优先选用yt-dlp等持续维护的工具。 遇到TikTok视频下载不了的情况,别急着换…

    2025年12月6日 软件教程
    100
  • Linux如何防止缓冲区溢出_Linux防止缓冲区溢出的安全措施

    缓冲区溢出可通过栈保护、ASLR、NX bit、安全编译选项和良好编码实践来防范。1. 使用-fstack-protector-strong插入canary检测栈破坏;2. 启用ASLR(kernel.randomize_va_space=2)随机化内存布局;3. 利用NX bit标记不可执行内存页…

    2025年12月6日 运维
    000
  • Linux如何优化系统性能_Linux系统性能优化的实用方法

    优化Linux性能需先监控资源使用,通过top、vmstat等命令分析负载,再调整内核参数如TCP优化与内存交换,结合关闭无用服务、选用合适文件系统与I/O调度器,持续按需调优以提升系统效率。 Linux系统性能优化的核心在于合理配置资源、监控系统状态并及时调整瓶颈环节。通过一系列实用手段,可以显著…

    2025年12月6日 运维
    000
  • Pboot插件数据库连接的配置教程_Pboot插件数据库备份的自动化脚本

    首先配置PbootCMS数据库连接参数,确保插件正常访问;接着创建auto_backup.php脚本实现备份功能;然后通过Windows任务计划程序或Linux Cron定时执行该脚本,完成自动化备份流程。 如果您正在开发或维护一个基于PbootCMS的网站,并希望实现插件对数据库的连接配置以及自动…

    2025年12月6日 软件教程
    000
  • Linux命令行中wc命令的实用技巧

    wc命令可统计文件的行数、单词数、字符数和字节数,常用-l统计行数,如wc -l /etc/passwd查看用户数量;结合grep可分析日志,如grep “error” logfile.txt | wc -l统计错误行数;-w统计单词数,-m统计字符数(含空格换行),-c统计…

    2025年12月6日 运维
    000
  • 今日头条官方主页入口 今日头条平台直达网址官方链接

    今日头条官方主页入口是www.toutiao.com,该平台通过个性化信息流推送图文、短视频等内容,具备分类导航、便捷搜索及跨设备同步功能。 今日头条官方主页入口在哪里?这是不少网友都关注的,接下来由PHP小编为大家带来今日头条平台直达网址官方链接,感兴趣的网友一起随小编来瞧瞧吧! www.tout…

    2025年12月6日 软件教程
    100
  • Linux命令行中fc命令的使用方法

    fc 是 Linux 中用于管理命令历史的工具,可查看、编辑并重新执行历史命令。输入 fc 直接编辑最近一条命令,默认调用 $EDITOR 打开编辑器修改后自动执行;通过 fc 100 110 或 fc -5 -1 可批量编辑指定范围的历史命令,保存后按序重跑;使用 fc -l 列出命令历史,支持起…

    2025年12月6日 运维
    000
  • 「世纪传奇刀片新篇」飞利浦影音双11声宴开启

    百年声学基因碰撞前沿科技,一场有关声音美学与设计美学的影音狂欢已悄然引爆2025“双十一”! 当绝大多数影音数码品牌还在价格战中挣扎时,飞利浦影音已然开启了一场跨越百年的“声”活革命。作为拥有深厚技术底蕴的音频巨头,飞利浦影音及配件此次“双十一”精准聚焦“传承经典”与“设计美学”两大核心,为热爱生活…

    2025年12月6日 行业动态
    000
  • Vue.js应用中配置环境变量:灵活管理后端通信地址

    在%ignore_a_1%应用中,灵活配置后端api地址等参数是开发与部署的关键。本文将详细介绍两种主要的环境变量配置方法:推荐使用的`.env`文件,以及通过`cross-env`库在命令行中设置环境变量。通过这些方法,开发者可以轻松实现开发、测试、生产等不同环境下配置的动态切换,提高应用的可维护…

    2025年12月6日 web前端
    000
  • VSCode选择范围提供者实现

    Selection Range Provider是VSCode中用于实现层级化代码选择的API,通过注册provideSelectionRanges方法,按光标位置从内到外逐层扩展选择范围,如从变量名扩展至函数体;需结合AST解析构建准确的SelectionRange链式结构以提升选择智能性。 在 …

    2025年12月6日 开发工具
    000
  • JavaScript动态生成日历式水平日期布局的优化实践

    本教程将指导如何使用javascript高效、正确地动态生成html表格中的日历式水平日期布局。重点解决直接操作`innerhtml`时遇到的标签闭合问题,通过数组构建html字符串来避免浏览器解析错误,并利用事件委托机制优化动态生成元素的事件处理,确保生成结构清晰、功能完善的日期展示。 在前端开发…

    2025年12月6日 web前端
    000
  • VSCode终端美化:功率线字体配置

    首先需安装Powerline字体如Nerd Fonts,再在VSCode设置中将terminal.integrated.fontFamily设为’FiraCode Nerd Font’等支持字体,最后配合oh-my-zsh的powerlevel10k等Shell主题启用完整美…

    2025年12月6日 开发工具
    000
  • JavaScript响应式编程与Observable

    Observable是响应式编程中处理异步数据流的核心概念,它允许随时间推移发出多个值,支持订阅、操作符链式调用及统一错误处理,广泛应用于事件监听、状态管理和复杂异步逻辑,提升代码可维护性与可读性。 响应式编程是一种面向数据流和变化传播的编程范式。在前端开发中,尤其面对复杂的用户交互和异步操作时,J…

    2025年12月6日 web前端
    000
  • Linux命令行中locate命令的快速查找方法

    locate命令通过查询数据库快速查找文件,使用-i可忽略大小写,-n限制结果数量,-c统计匹配项,-r支持正则表达式精确匹配,刚创建的文件需运行sudo updatedb更新数据库才能查到。 在Linux命令行中,locate 命令是快速查找文件和目录路径的高效工具。它不直接扫描整个文件系统,而是…

    2025年12月6日 运维
    000
  • JavaScript生成器与迭代器协议实现

    生成器和迭代器基于统一协议实现惰性求值与数据遍历,通过next()方法返回{value, done}对象,生成器函数简化了迭代器创建过程,提升处理大数据序列的效率与代码可读性。 JavaScript中的生成器(Generator)和迭代器(Iterator)是处理数据序列的重要机制,尤其在处理惰性求…

    2025年12月6日 web前端
    000
  • 环境搭建docker环境下如何快速部署mysql集群

    使用Docker Compose部署MySQL主从集群,通过配置文件设置server-id和binlog,编写docker-compose.yml定义主从服务并组网,启动后创建复制用户并配置主从连接,最后验证数据同步是否正常。 在Docker环境下快速部署MySQL集群,关键在于合理使用Docker…

    2025年12月6日 数据库
    000

发表回复

登录后才能评论
关注微信