【容器编排魔法】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)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
天眼查App怎样查看分支机构_天眼查App查看分支机构详细方法
上一篇 2025年12月1日 21:29:41
Java并发二叉搜索树死锁问题深度解析与ReentrantLock正确实践
下一篇 2025年12月1日 21:29:43

相关推荐

  • Java Collections.singletonList如何创建单元素集合

    Collections.singletonList(T item) 返回只含一个元素的不可变列表,传入指定对象后生成轻量级只读集合,适用于需高效传递单元素场景。该列表禁止修改操作,否则抛出异常,允许 null 元素,内部优化减少内存开销,常用于 API 参数传递或流处理中的临时数据构造。 Java …

    2026年9月21日
    000
  • VSCode编写Java代码方法_VSCode搭建Java开发环境实战教程

    答案:在VSCode中配置Java开发环境需安装JDK并设置环境变量,再安装VSCode及Java扩展包,即可实现Java项目的创建、编写、运行与调试。它轻量、启动快,支持多语言和丰富扩展,集成Maven/Gradle,适合日常开发。 在VSCode里编写Java代码,说白了,就是把这个轻量级的代码…

    2026年9月21日
    000
  • JavaScript中的模块联邦如何实现微前端的代码共享?

    模块联邦通过运行时动态加载实现微前端代码共享,无需打包公共依赖。使用 ModuleFederationPlugin 配置 name、remotes、exposes 和 shared,使应用可暴露或引入远程模块,支持组件、工具函数及状态管理共享,提升复用性并减少冗余。 模块联邦通过在构建时让不同应用直…

    2026年9月21日
    200
  • Swoole如何实现一个UDP服务器

    答案:使用Swoole可轻松创建高性能UDP服务器。通过new SwooleServer()设置UDP套接字,监听Packet事件接收数据,利用sendto()回复客户端;结合set()配置worker_num等参数优化性能,配合PHP UDP客户端测试通信,适用于高并发、低延迟场景。 使用Swoo…

    2026年9月21日
    000
  • 如何通过tracert命令追踪数据包从本地到目标服务器的完整路径?

    打开命令提示符,输入cmd并回车;2. 执行tracert 目标地址命令追踪路径;3. 查看每跳响应时间与IP,分析延迟变化定位网络瓶颈;4. 注意部分节点可能因防火墙不响应导致超时。 使用 tracert(Windows 系统)命令可以追踪数据包从你的计算机到目标服务器所经过的每一跳网络节点,帮助…

    2026年9月21日
    900
  • windows怎么清除dns缓存_dns缓存刷新命令详解

    1、刷新DNS缓存可解决网页无法加载或域名解析错误问题。2、通过命令提示符执行ipconfig /flushdns清除系统DNS缓存。3、以管理员身份运行命令提示符并重启DNS Client服务(net stop dnscache和net start dnscache)恢复服务功能。4、在Chrom…

    2026年9月21日
    000
  • Linux interfaces 虚拟网络类型了解01

    Linux interfaces 虚拟网络类型了解01Linux interfaces 虚拟网络类型了解01Linux interfaces 虚拟网络类型了解01Linux interfaces 虚拟网络类型了解01

    在osi模型的定义中,数据链路层和物理层,以及传输层和网络层执行的任务在概念上相似:它们都提供了数据传输的方式,即沿着特定路径将数据从源点传输到目的地的方法。然而,数据链路层和物理层负责跨物理路径的通信服务,而传输层和网络层则提供由多个数据链路组成的逻辑路径或虚拟路径的通信服务。 Bridge操作指…

    2026年9月21日 用户投稿
    000
  • PHP简易路由框架构建:从URL解析到动态控制器加载的实践指南

    本文旨在指导读者构建一个基础的PHP路由系统,实现URL路径到控制器方法的高效映射。内容涵盖URL解析、控制器动态加载、方法调用以及关键的错误处理机制,特别强调如何避免常见的“未定义变量”错误和文件包含路径问题,确保路由系统稳定且易于维护。 一、路由系统核心原理 构建一个简单的php路由系统,其核心…

    2026年9月21日
    100
  • 如何在Java中理解Java I/O与NIO机制

    传统I/O是阻塞式流模型,适用于低并发场景;NIO基于缓冲区与通道,支持非阻塞和多路复用,适合高并发网络应用,核心区别在于线程模型与资源利用率。 Java中的I/O(输入/输出)与NIO(New I/O)是处理数据读写的核心机制,理解它们的区别和使用场景对开发高性能应用至关重要。传统I/O基于流模型…

    2026年9月21日
    100
  • UC浏览器网页上的文字无法选中复制怎么办 UC浏览器解决网页文字禁止复制问题

    答案:可通过开发者工具、阅读模式、打印预览、OCR识别或自定义脚本解除UC浏览器网页复制限制。具体操作依次为:开启开发者工具并执行JavaScript代码解除限制;启用阅读模式净化页面内容;使用打印预览重新渲染页面以选中文字;对截图应用OCR技术提取文本;添加书签脚本自动移除禁用选择的代码,从而实现…

    2026年9月21日
    100
  • JavaScript中的尾调用优化(TCO)在ES6中如何工作?

    尾调用是指函数的最后一个动作调用另一个函数,ES6引入尾调用优化以重用栈帧、避免内存溢出,支持真正的尾递归,如阶乘函数通过累积参数实现。 尾调用优化(Tail Call Optimization, TCO)是ES6引入的一项语言特性,目的是在特定条件下重用函数调用栈帧,避免不必要的内存增长,从而支持…

    2026年9月21日
    200
  • 为什么iPhoneSE2022屏幕无响应如何强制重启?快速按音量键后长按电源键

    首先尝试强制重启,若无效则检查充电状态,最后可通过恢复模式重装系统。具体为:1. 按音量+、音量-后长按电源键10秒以上;2. 充电15分钟观察是否响应;3. 连电脑进入恢复模式恢复系统。 如果您尝试唤醒或操作您的iPhone SE(2022款),但屏幕无响应或显示黑屏,可能是系统临时卡死或软件冲突…

    2026年9月21日
    000
  • Java语法基础有哪些新手必学的核心知识

    掌握Java基本数据类型与变量声明,如int、double、char和boolean,并理解强类型语言特性;2. 熟悉运算符与表达式,包括算术、比较和逻辑运算符,奠定程序逻辑基础。 Java语法基础是每个初学者必须掌握的内容,只有打好根基,才能顺利进阶面向对象编程和实际项目开发。以下是新手必学的核心…

    2026年9月21日
    300
  • VSCode侧边栏怎么去掉_VSCode侧边栏隐藏教程

    隐藏VSCode侧边栏可通过Ctrl + B(Windows/Linux)或Cmd + B(macOS)快捷键快速切换,也可通过菜单栏“视图 > 外观 > 切换侧边栏可见性”或命令面板执行“View: Toggle Sidebar Visibility”实现。推荐使用快捷键操作,效率最高…

    2026年9月21日
    000
  • php switch语句怎么用_php中switch条件判断语句的用法示例

    答案:PHP中switch语句用于多条件判断,语法为switch(表达式){case值:代码;break;},通过松散比较匹配case值,执行对应代码块,遇到break跳出避免穿透,default处理无匹配情况。示例根据$day输出星期几,注意事项包括case值不可为表达式、需注意类型松散比较、省略…

    2026年9月21日
    100
  • MobileCLIP2— 苹果开源的端侧多模态模型

    MobileCLIP2— 苹果开源的端侧多模态模型MobileCLIP2— 苹果开源的端侧多模态模型MobileCLIP2— 苹果开源的端侧多模态模型MobileCLIP2— 苹果开源的端侧多模态模型

    ☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 DeepSeek R1 模型☜☜☜ 可图大模型 可图大模型(Kolors)是快手大模型团队自研打造的文生图AI大模型 32 查看详情 MobileCLIP2是什么 mobileclip2是由苹果研究团队开发的新一代高效多模态模型,…

    2026年9月21日 用户投稿
    100
  • 如何限制Linux用户cron任务 /etc/cron.deny使用技巧

    如何限制Linux用户cron任务 /etc/cron.deny使用技巧如何限制Linux用户cron任务 /etc/cron.deny使用技巧如何限制Linux用户cron任务 /etc/cron.deny使用技巧如何限制Linux用户cron任务 /etc/cron.deny使用技巧

    要限制linux用户执行cron任务,可编辑/etc/cron.deny文件,每行添加一个需禁止的用户名,保存后立即生效;若需更细粒度控制,可使用pam_time模块;此外,还可通过sudoers文件、chroot环境、linux capabilities、apparmor或selinux等方法限制…

    2026年9月21日 用户投稿
    200
  • MySQL用户权限体系配置思路_Sublime中编辑多用户分权管理脚本

    MySQL用户权限体系配置思路_Sublime中编辑多用户分权管理脚本MySQL用户权限体系配置思路_Sublime中编辑多用户分权管理脚本MySQL用户权限体系配置思路_Sublime中编辑多用户分权管理脚本MySQL用户权限体系配置思路_Sublime中编辑多用户分权管理脚本

    最小权限原则是mysql用户权限配置的核心,确保每个用户仅拥有必要权限以提升安全性与可维护性。1.明确需求:根据用户角色分配如只读、增删改查或结构修改权限;2.创建用户并编写sql脚本进行权限管理,替代手动输入命令,提高效率与一致性;3.使用sublime text等编辑器提升脚本编写效率,利用语法…

    2026年9月21日 用户投稿
    000
  • 升级X86架构性能大提升!极空间Z2 Ultra图赏

    升级X86架构性能大提升!极空间Z2 Ultra图赏升级X86架构性能大提升!极空间Z2 Ultra图赏升级X86架构性能大提升!极空间Z2 Ultra图赏升级X86架构性能大提升!极空间Z2 Ultra图赏

    10月23日,极空间正式推出全新双盘位nas产品——极空间z2 ultra,官方售价为1899元,参与国家补贴后仅需1457元,性价比进一步提升。 此次发布的Z2 Ultra最大的亮点在于采用X86架构处理器,相较以往使用的ARM平台,性能实现飞跃式提升,运行速度显著加快。更重要的是,新架构对Doc…

    2026年9月21日 用户投稿
    200
  • 数据库分库分表(Sharding)策略

    在现代应用程序中,随着数据量的增长,单一数据库的性能和容量往往难以满足需求。这时,数据库分库分表(Sharding)策略就成了一个关键的解决方案。那么,如何设计和实现一个有效的分库分表策略呢?让我们深入探讨一下。 在我的职业生涯中,我曾多次参与大型项目的数据库优化,其中分库分表是常见的挑战之一。我记…

    2026年9月21日
    000

发表回复

登录后才能评论
关注微信