{"id":7353,"date":"2018-04-13T09:59:04","date_gmt":"2018-04-13T01:59:04","guid":{"rendered":"http:\/\/rmohan.com\/?p=7353"},"modified":"2018-04-13T09:59:04","modified_gmt":"2018-04-13T01:59:04","slug":"docker-swarm","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7353","title":{"rendered":"docker swarm"},"content":{"rendered":"<p>Docker Engine Starting from version 1.12.0, Docker Swarm is integrated natively. The operation of the cluster can be directly controlled by the docker service command, which is very convenient and the operation process is greatly simplified.\u00a0Docker Swarm For the average developer, the biggest advantage lies in the native support of the load balancing mechanism, which can effectively scale the service up. With the help of the Raft Consensus algorithm, the robustness of the system is very good and can be tolerated as much as possible (n -1)\/2 fault nodes.<br \/>\nBuild Swarm Cluster<\/p>\n<p>Install the latest docker<\/p>\n<pre><code class=\"hljs groovy\"><span style=\"color: #333333;\">curl -sSL <span class=\"hljs-string\">https:<\/span><span class=\"hljs-comment\">\/\/get.docker.com\/ | sh<\/span><\/span><\/code><\/pre>\n<pre><code class=\"hljs nginx\"><span class=\"hljs-attribute\"><a title=\"CentOS\" href=\"https:\/\/www.linuxidc.com\/topicnews.aspx?tid=14\" target=\"_blank\" rel=\"noopener\">CentOS<\/a><\/span><span style=\"color: #333333;\"> <span class=\"hljs-number\">7<\/span>?????<\/span><\/code><\/pre>\n<pre><code class=\"hljs lua\"><span style=\"color: #333333;\">firewall-cmd <span class=\"hljs-comment\">--permanent --zone=trusted --add-port=2377\/tcp &amp;&amp; \\<\/span><\/span>\r\n<span style=\"color: #333333;\">firewall-cmd <span class=\"hljs-comment\">--permanent --zone=trusted --add-port=7946\/tcp &amp;&amp; \\<\/span><\/span>\r\n<span style=\"color: #333333;\">firewall-cmd <span class=\"hljs-comment\">--permanent --zone=trusted --add-port=7946\/udp &amp;&amp; \\<\/span><\/span>\r\n<span style=\"color: #333333;\">firewall-cmd <span class=\"hljs-comment\">--permanent --zone=trusted --add-port=4789\/udp &amp;&amp; \\<\/span><\/span>\r\n<span style=\"color: #333333;\">firewall-cmd <span class=\"hljs-comment\">--reload <\/span><\/span><\/code><\/pre>\n<p>Create a management node<\/p>\n<pre><code class=\"hljs vbnet\"><span style=\"color: #333333;\">$ docker swarm init --advertise-addr <span class=\"hljs-number\">192.168<\/span><span class=\"hljs-number\">.99<\/span><span class=\"hljs-number\">.100<\/span><\/span>\r\n<span style=\"color: #333333;\">Swarm initialized: current node (dxn1zf6l61qsb1josjja83ngz) <span class=\"hljs-keyword\">is<\/span> now a manager.<\/span>\r\n\r\n<span style=\"color: #333333;\"><span class=\"hljs-keyword\">To<\/span> add a worker <span class=\"hljs-keyword\">to<\/span> this swarm, run the following command:<\/span>\r\n<span style=\"color: #333333;\">    docker swarm <span class=\"hljs-keyword\">join<\/span> \\<\/span>\r\n<span style=\"color: #333333;\">    --token SWMTKN<span class=\"hljs-number\">-1<\/span><span class=\"hljs-number\">-49<\/span>nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv<span class=\"hljs-number\">-8<\/span>vxv8rssmk743ojnwacrr2e7c \\<\/span>\r\n<span style=\"color: #333333;\">    <span class=\"hljs-number\">192.168<\/span><span class=\"hljs-number\">.99<\/span><span class=\"hljs-number\">.100<\/span>:<span class=\"hljs-number\">2377<\/span><\/span>\r\n\r\n<span style=\"color: #333333;\"><span class=\"hljs-keyword\">To<\/span> add a manager <span class=\"hljs-keyword\">to<\/span> this swarm, run the following command:<\/span>\r\n<span style=\"color: #333333;\">    docker swarm <span class=\"hljs-keyword\">join<\/span> \\<\/span>\r\n<span style=\"color: #333333;\">    --token SWMTKN<span class=\"hljs-number\">-1<\/span><span class=\"hljs-number\">-61<\/span>ztec5kyafptydic6jfc1i33t37flcl4nuipzcusor96k7kby<span class=\"hljs-number\">-5<\/span>vy9t8u35tuqm7vh67lrz9xp6 \\<\/span>\r\n<span style=\"color: #333333;\">    <span class=\"hljs-number\">192.168<\/span><span class=\"hljs-number\">.99<\/span><span class=\"hljs-number\">.100<\/span>:<span class=\"hljs-number\">2377<\/span><\/span><\/code><\/pre>\n<p>When the management node is created, we can view the node creation status through the docker info and docker node ls commands.<\/p>\n<pre><code class=\"hljs yaml\"><span style=\"color: #333333;\">$ docker info<\/span>\r\n\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\">Containers:<\/span> <span class=\"hljs-number\">2<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\">Running:<\/span> <span class=\"hljs-number\">0<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\">Paused:<\/span> <span class=\"hljs-number\">0<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\">Stopped:<\/span> <span class=\"hljs-number\">2<\/span><\/span>\r\n<span style=\"color: #333333;\">  ...snip...<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\">Swarm:<\/span> active<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\">  NodeID:<\/span> dxn1zf6l61qsb1josjja83ngz<\/span>\r\n<span style=\"color: #333333;\">  Is Manager: <span class=\"hljs-literal\">true<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\">  Managers:<\/span> <span class=\"hljs-number\">1<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\">  Nodes:<\/span> <span class=\"hljs-number\">1<\/span><\/span>\r\n<span style=\"color: #333333;\">  ...snip...<\/span><\/code><\/pre>\n<pre><code class=\"hljs fortran\"><span style=\"color: #333333;\">$ docker node ls<\/span>\r\n\r\n<span style=\"color: #333333;\">ID                           HOSTNAME  <span class=\"hljs-keyword\">STATUS<\/span>  AVAILABILITY  MANAGER <span class=\"hljs-keyword\">STATUS<\/span><\/span>\r\n<span style=\"color: #333333;\">dxn1zf6l61qsb1josjja83ngz *  manager1  Ready   Active        Leader<\/span>\r\n<span style=\"color: #333333;\">??worker??<\/span><\/code><\/pre>\n<p>According to the previous command line output result prompt, two workers are now added to the cluster.\u00a0Remember to replace the corresponding token and IP address with the actual value during execution.<\/p>\n<pre><code class=\"hljs swift\"><span style=\"color: #333333;\">$ docker swarm <span class=\"hljs-built_in\">join<\/span> \\<\/span>\r\n<span style=\"color: #333333;\">  --token  <span class=\"hljs-type\">SWMTKN<\/span>-<span class=\"hljs-number\">1<\/span>-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \\<\/span>\r\n<span style=\"color: #333333;\">  <span class=\"hljs-number\">192.168<\/span>.<span class=\"hljs-number\">99.100<\/span>:<span class=\"hljs-number\">2377<\/span><\/span>\r\n\r\n<span style=\"color: #333333;\"><span class=\"hljs-type\">This<\/span> node joined a swarm <span class=\"hljs-keyword\">as<\/span> a worker.<\/span>\r\n<span style=\"color: #333333;\">$ docker swarm <span class=\"hljs-built_in\">join<\/span> \\<\/span>\r\n<span style=\"color: #333333;\">  --token <span class=\"hljs-type\">SWMTKN<\/span>-<span class=\"hljs-number\">1<\/span>-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \\<\/span>\r\n<span style=\"color: #333333;\">  <span class=\"hljs-number\">192.168<\/span>.<span class=\"hljs-number\">99.100<\/span>:<span class=\"hljs-number\">2377<\/span><\/span>\r\n\r\n<span style=\"color: #333333;\"><span class=\"hljs-type\">This<\/span> node joined a swarm <span class=\"hljs-keyword\">as<\/span> a worker.<\/span>\r\n<span style=\"color: #333333;\">#????????hostname `hoshnamectl <span class=\"hljs-keyword\">set<\/span>-hostname worker2`<\/span><\/code><\/pre>\n<p>Now we can see all the nodes in the cluster on the manager1 node<\/p>\n<pre><code class=\"hljs fortran\"><span style=\"color: #333333;\">$ docker node ls<\/span>\r\n\r\n<span style=\"color: #333333;\">ID                           HOSTNAME  <span class=\"hljs-keyword\">STATUS<\/span>  AVAILABILITY  MANAGER <span class=\"hljs-keyword\">STATUS<\/span><\/span>\r\n<span style=\"color: #333333;\">3g1y59jwfg7cf99w4lt0f662    worker2   Ready   Active<\/span>\r\n<span style=\"color: #333333;\">j68exjopxe7wfl6yuxml7a7j    worker1   Ready   Active<\/span>\r\n<span style=\"color: #333333;\">dxn1zf6l61qsb1josjja83ngz *  manager1  Ready   Active        Leader<\/span><\/code><\/pre>\n<p>So far, the cluster environment has been set up.<\/p>\n<p>Deployment Test Service<\/p>\n<p>We deployed nginx as an example to test the Swarm cluster we built.<\/p>\n<pre><code class=\"hljs sql\"><span style=\"color: #333333;\">$ docker service <span class=\"hljs-keyword\">create<\/span> <span class=\"hljs-comment\">--replicas 3 --publish 8080:80 --name helloworld nginx<\/span><\/span><\/code><\/pre>\n<p>The &#8211;replicas parameter here is used to indicate how many instances nginx needs to deploy because there are three physical machines. If replicas is set to 3, swarm will deploy one instance on each of the three machines.\u00a0If you want to rescale the number of instances, you can use the following command.<\/p>\n<pre><code class=\"hljs fortran\"><span style=\"color: #333333;\">docker service <span class=\"hljs-built_in\">scale<\/span> helloworld=<span class=\"hljs-number\">5<\/span><\/span><\/code><\/pre>\n<p>We can check the deployment of nginx through a series of commands, such as<\/p>\n<pre><code class=\"hljs lua\"><span style=\"color: #333333;\">$ docker service inspect <span class=\"hljs-comment\">--pretty helloworld<\/span><\/span>\r\n<span style=\"color: #333333;\">$ docker service ps helloworld<\/span><\/code><\/pre>\n<p>Deleting a service is also very simple and you can simply execute rm.<\/p>\n<pre><code class=\"hljs smalltalk\"><span style=\"color: #333333;\"><span class=\"hljs-string\">$ <\/span>docker service rm helloworld<\/span><\/code><\/pre>\n<p>Let&#8217;s look at a docker-compose.yml file first. It doesn&#8217;t matter what this is doing. It&#8217;s just a format that is easy to explain:<\/p>\n<pre><code class=\"hljs dts\"><span style=\"color: #333333;\"><span class=\"hljs-symbol\">version:<\/span> <span class=\"hljs-string\">'2'<\/span><\/span>\r\n<span class=\"hljs-symbol\"><span style=\"color: #333333;\">services:<\/span><\/span>\r\n<span class=\"hljs-symbol\"><span style=\"color: #333333;\">  web:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-symbol\">    image:<\/span> dockercloud\/hello-world<\/span>\r\n<span class=\"hljs-symbol\"><span style=\"color: #333333;\">    ports:<\/span><\/span>\r\n<span style=\"color: #333333;\">      - <span class=\"hljs-number\">8080<\/span><\/span>\r\n<span class=\"hljs-symbol\"><span style=\"color: #333333;\">    networks:<\/span><\/span>\r\n<span style=\"color: #333333;\">      - front-tier<\/span>\r\n<span style=\"color: #333333;\">      - back-tier<\/span>\r\n<span class=\"hljs-symbol\">\r\n<span style=\"color: #333333;\">  redis:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-symbol\">    image:<\/span> redis<\/span>\r\n<span class=\"hljs-symbol\"><span style=\"color: #333333;\">    links:<\/span><\/span>\r\n<span style=\"color: #333333;\">      - web<\/span>\r\n<span class=\"hljs-symbol\"><span style=\"color: #333333;\">    networks:<\/span><\/span>\r\n<span style=\"color: #333333;\">      - back-tier<\/span>\r\n<span class=\"hljs-symbol\">\r\n<span style=\"color: #333333;\">  lb:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-symbol\">    image:<\/span> dockercloud\/haproxy<\/span>\r\n<span class=\"hljs-symbol\"><span style=\"color: #333333;\">    ports:<\/span><\/span>\r\n<span style=\"color: #333333;\">      - <span class=\"hljs-number\">80<\/span>:<span class=\"hljs-number\">80<\/span><\/span>\r\n<span class=\"hljs-symbol\"><span style=\"color: #333333;\">    links:<\/span><\/span>\r\n<span style=\"color: #333333;\">      - web<\/span>\r\n<span class=\"hljs-symbol\"><span style=\"color: #333333;\">    networks:<\/span><\/span>\r\n<span style=\"color: #333333;\">      - front-tier<\/span>\r\n<span style=\"color: #333333;\">      - back-tier<\/span>\r\n<span class=\"hljs-symbol\"><span style=\"color: #333333;\">    volumes:<\/span><\/span>\r\n<span style=\"color: #333333;\">      - <span class=\"hljs-meta-keyword\">\/var\/<\/span>run\/docker.sock:<span class=\"hljs-meta-keyword\">\/var\/<\/span>run\/docker.sock <\/span>\r\n<span class=\"hljs-symbol\">\r\n<span style=\"color: #333333;\">networks:<\/span><\/span>\r\n<span style=\"color: #333333;\">  front-tier:<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-symbol\">    driver:<\/span> bridge<\/span>\r\n<span style=\"color: #333333;\">  back-tier:<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-symbol\">driver:<\/span> bridge<\/span><\/code><\/pre>\n<p>It can be seen that a standard configuration file should contain three major parts: version, services, and networks. The most critical part is services and networks. Let&#8217;s first look at the rules for writing services.<\/p>\n<ol>\n<li>Image\n<pre><code class=\"hljs yaml\"><span class=\"hljs-attr\"><span style=\"color: #333333;\">services:<\/span><\/span>\r\n<span class=\"hljs-attr\"><span style=\"color: #333333;\">  web:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\">image:<\/span> hello-world<\/span><\/code><\/pre>\n<p>The second-level tag under the services tab is web. The name is customized by the user. It is the service name.<br \/>\nImage is the image name or image ID of the specified service.\u00a0If the image does not exist locally, Compose will try to pull the image.<br \/>\nFor example, the following formats are all possible:<\/p>\n<pre><code class=\"hljs groovy\"><span style=\"color: #333333;\"><span class=\"hljs-string\">image:<\/span> redis<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-string\">image:<\/span> <\/span><span class=\"hljs-string\"><a title=\"Ubuntu\" href=\"https:\/\/www.linuxidc.com\/topicnews.aspx?tid=2\" target=\"_blank\" rel=\"noopener\">Ubuntu<\/a><span style=\"color: #333333;\">:<\/span><\/span><span class=\"hljs-number\"><span style=\"color: #333333;\">14.04<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-string\">image:<\/span> tutum\/influxdb<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-string\">image:<\/span> example-registry.<span class=\"hljs-string\">com:<\/span><span class=\"hljs-number\">4000<\/span>\/postgresql<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-string\">image:<\/span> a4bc65fd<\/span><\/code><\/pre>\n<\/li>\n<li>Build<\/li>\n<\/ol>\n<p>The service can be based on a specified image, or it can be based on a Dockerfile. When you use up to start a build task, this build tag is the build, which specifies the path to the Dockerfile folder.\u00a0Compose will use it to automatically build this image and then use this image to start the service container.<\/p>\n<pre><code class=\"hljs dts\"><span style=\"color: #333333;\"><span class=\"hljs-symbol\">build:<\/span> <span class=\"hljs-meta-keyword\">\/path\/<\/span>to<span class=\"hljs-meta-keyword\">\/build\/<\/span>dir<\/span><\/code><\/pre>\n<p>It can also be a relative path, and the Dockerfile can be read as long as the context is determined.<\/p>\n<pre><code class=\"hljs yaml\"><span style=\"color: #333333;\"><span class=\"hljs-attr\">build:<\/span> .\/dir<\/span><\/code><\/pre>\n<p>Set the context root and specify the Dockerfile as the target.<\/p>\n<pre><code class=\"hljs dts\"><span class=\"hljs-symbol\"><span style=\"color: #333333;\">build:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-symbol\">  context:<\/span> ..\/<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-symbol\">  dockerfile:<\/span> path<span class=\"hljs-meta-keyword\">\/of\/<\/span>Dockerfile<\/span><\/code><\/pre>\n<p>Note that build is a directory, if you want to specify the Dockerfile file you need to use the dockerfile tag in the child tag of the build tag, as in the above example.<br \/>\nIf you specify both the image and build tags, Compose will build the image and name the image after the image.<\/p>\n<pre><code class=\"hljs groovy\"><span style=\"color: #333333;\"><span class=\"hljs-string\">build:<\/span> .\/dir<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-string\">image:<\/span> <span class=\"hljs-string\">webapp:<\/span>tag<\/span><\/code><\/pre>\n<p>Since you can define the build task in docker-compose.yml, you must have the arg tag. Just like the ARG directive in the Dockerfile, it can specify the environment variables during the build process, but cancel after the build succeeds, at docker-compose. The yml file also supports this notation:<\/p>\n<pre><code class=\"hljs yaml\"><span class=\"hljs-attr\"><span style=\"color: #333333;\">build:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\">  context:<\/span> .<\/span>\r\n<span class=\"hljs-attr\"><span style=\"color: #333333;\">  args:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\">    buildno:<\/span> <span class=\"hljs-number\">1<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\">    password:<\/span> secret<\/span><\/code><\/pre>\n<p>The following writing is also supported. In general, the following wording is more suitable for reading.<\/p>\n<pre><code class=\"hljs yaml\"><span class=\"hljs-attr\"><span style=\"color: #333333;\">build:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\">  context:<\/span> .<\/span>\r\n<span class=\"hljs-attr\"><span style=\"color: #333333;\">  args:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-bullet\">    -<\/span> buildno=<span class=\"hljs-number\">1<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-bullet\">    -<\/span> password=secret<\/span><\/code><\/pre>\n<p>Unlike ENV, ARG allows null values.\u00a0E.g:<\/p>\n<pre><code class=\"hljs makefile\"><span class=\"hljs-section\"><span style=\"color: #333333;\">args:<\/span><\/span>\r\n<span style=\"color: #333333;\">  - buildno<\/span>\r\n<span style=\"color: #333333;\">  - password<\/span><\/code><\/pre>\n<p>This way the build process can assign values ??to them.<\/p>\n<p>Note: YAML Boolean values ??(true, false, yes, no, on, off) must be quoted (either single or double quotes), otherwise they will be parsed as strings.<\/p>\n<ol>\n<li>Command<\/li>\n<\/ol>\n<p>Use command to override the default command executed after the container starts.<\/p>\n<pre><code class=\"hljs bash\"><span style=\"color: #333333;\"><span class=\"hljs-built_in\">command<\/span>: bundle <span class=\"hljs-built_in\">exec<\/span> thin -p 3000<\/span><\/code><\/pre>\n<p>It can also be written in a format similar to Dockerfile:<\/p>\n<pre><code class=\"hljs bash\"><span style=\"color: #333333;\"><span class=\"hljs-built_in\">command<\/span>: [bundle, <span class=\"hljs-built_in\">exec<\/span>, thin, -p, 3000]<\/span><\/code><\/pre>\n<p>4.container_name<\/p>\n<p>As mentioned earlier, Compose&#8217;s container name format is: &lt;project name&gt; &lt;service name&gt; &lt;serial number&gt;<br \/>\nAlthough you can customize the project name, service name, but if you want to fully control the container&#8217;s name, you can use this tag to specify:<\/p>\n<pre><code class=\"hljs yaml\"><span style=\"color: #333333;\"><span class=\"hljs-attr\">container_name:<\/span> app<\/span><\/code><\/pre>\n<p>The name of this container is specified as app.<\/p>\n<p>5.depends_on<\/p>\n<p>In the use of Compose, the biggest advantage is to use less to start the command, but the order of the general project container startup is required, if you start the container directly from top to bottom, it will inevitably fail because of container dependency problems.<br \/>\nFor example, if the application container is started when the database container is not started, the application container will exit because it cannot find the database. In order to avoid this situation, we need to add a label, namely depends_on, which resolves the container&#8217;s dependency and startup sequence. The problem.<br \/>\nFor example, the following container will start two services redis and db, and finally start the web service:<\/p>\n<pre><code class=\"hljs dts\"><span style=\"color: #333333;\"><span class=\"hljs-symbol\">version:<\/span> <span class=\"hljs-string\">'2'<\/span><\/span>\r\n<span class=\"hljs-symbol\"><span style=\"color: #333333;\">services:<\/span><\/span>\r\n<span class=\"hljs-symbol\"><span style=\"color: #333333;\">  web:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-symbol\">    build:<\/span> .<\/span>\r\n<span class=\"hljs-symbol\"><span style=\"color: #333333;\">    depends_on:<\/span><\/span>\r\n<span style=\"color: #333333;\">      - db<\/span>\r\n<span style=\"color: #333333;\">      - redis<\/span>\r\n<span class=\"hljs-symbol\"><span style=\"color: #333333;\">  redis:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-symbol\">    image:<\/span> redis<\/span>\r\n<span class=\"hljs-symbol\"><span style=\"color: #333333;\">  db:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-symbol\">    image:<\/span> postgres<\/span><\/code><\/pre>\n<p>Note that when launching a web service using the docker-compose up web method by default, both the redis and db services are started because the dependencies are defined in the configuration file.<\/p>\n<p>6.dns<\/p>\n<p>The same as the &#8211;dns parameter, the format is as follows:<\/p>\n<p>Dns: 8.8.8.8<br \/>\ncan also be a list:<\/p>\n<pre><code class=\"hljs css\"><span style=\"color: #333333;\"><span class=\"hljs-selector-tag\">dns<\/span>:<\/span>\r\n<span style=\"color: #333333;\">  <span class=\"hljs-selector-tag\">-<\/span> 8<span class=\"hljs-selector-class\">.8<\/span><span class=\"hljs-selector-class\">.8<\/span><span class=\"hljs-selector-class\">.8<\/span><\/span>\r\n<span style=\"color: #333333;\">  <span class=\"hljs-selector-tag\">-<\/span> 9<span class=\"hljs-selector-class\">.9<\/span><span class=\"hljs-selector-class\">.9<\/span><span class=\"hljs-selector-class\">.9<\/span><\/span><\/code><\/pre>\n<p>In addition, the configuration of dns_search is similar:<\/p>\n<pre><code class=\"hljs css\"><span style=\"color: #333333;\"><span class=\"hljs-selector-tag\">dns_search<\/span>: <span class=\"hljs-selector-tag\">example<\/span><span class=\"hljs-selector-class\">.com<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-selector-tag\">dns_search<\/span>:<\/span>\r\n<span style=\"color: #333333;\">  <span class=\"hljs-selector-tag\">-<\/span> <span class=\"hljs-selector-tag\">dc1<\/span><span class=\"hljs-selector-class\">.example<\/span><span class=\"hljs-selector-class\">.com<\/span><\/span>\r\n<span style=\"color: #333333;\">  <span class=\"hljs-selector-tag\">-<\/span> <span class=\"hljs-selector-tag\">dc2<\/span><span class=\"hljs-selector-class\">.example<\/span><span class=\"hljs-selector-class\">.com<\/span><\/span><\/code><\/pre>\n<ol>\n<li>Tmpfs<\/li>\n<\/ol>\n<p>Mounting a temporary directory inside the container has the same effect as the run parameter:<\/p>\n<pre><code class=\"hljs yaml\"><span style=\"color: #333333;\"><span class=\"hljs-attr\">tmpfs:<\/span> \/run<\/span>\r\n<span class=\"hljs-attr\"><span style=\"color: #333333;\">tmpfs:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-bullet\">  -<\/span> \/run<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-bullet\">  -<\/span> \/tmp<\/span><\/code><\/pre>\n<ol>\n<li>Entrypoint<\/li>\n<\/ol>\n<p>In the Dockerfile there is an instruction called the ENTRYPOINT directive that specifies the access point, and Chapter 4 has the difference compared to the CMD.<br \/>\nThe access point can be defined in docker-compose.yml, overriding the definition in the Dockerfile:<\/p>\n<p>Entrypoint: The \/code\/entrypoint.sh<br \/>\nformat is similar to Docker, but can also be written like this:<\/p>\n<pre><code class=\"hljs dts\"><span class=\"hljs-symbol\"><span style=\"color: #333333;\">entrypoint:<\/span><\/span>\r\n<span style=\"color: #333333;\">    - php<\/span>\r\n<span style=\"color: #333333;\">    - -d<\/span>\r\n<span style=\"color: #333333;\">    - zend_extension=<span class=\"hljs-meta-keyword\">\/usr\/<\/span>local<span class=\"hljs-meta-keyword\">\/lib\/<\/span>php<span class=\"hljs-meta-keyword\">\/extensions\/<\/span>no-debug-non-zts<span class=\"hljs-number\">-20100525<\/span>\/xdebug.so<\/span>\r\n<span style=\"color: #333333;\">    - -d<\/span>\r\n<span style=\"color: #333333;\">    - memory_limit=<span class=\"hljs-number\">-1<\/span><\/span>\r\n<span style=\"color: #333333;\">    - vendor<span class=\"hljs-meta-keyword\">\/bin\/<\/span>phpunit<\/span><\/code><\/pre>\n<p>9.env_file<\/p>\n<p>Remember the .env file mentioned earlier. This file can set Compose variables.\u00a0In docker-compose.yml, you can define a file that stores variables.<br \/>\nIf the configuration file is specified with docker-compose -f FILE, the path to the env_file uses the configuration file path.<\/p>\n<p>If there is a conflict between the variable name and the environment instruction, the latter will prevail.\u00a0The format is as follows:<\/p>\n<p>Env_file: .env<br \/>\nor set multiple according to docker-compose.yml:<\/p>\n<pre><code class=\"hljs dts\"><span class=\"hljs-symbol\"><span style=\"color: #333333;\">env_file:<\/span><\/span>\r\n<span style=\"color: #333333;\">  - .\/common.env<\/span>\r\n<span style=\"color: #333333;\">  - .<span class=\"hljs-meta-keyword\">\/apps\/<\/span>web.env<\/span>\r\n<span style=\"color: #333333;\">  - <span class=\"hljs-meta-keyword\">\/opt\/<\/span>secrets.env<\/span><\/code><\/pre>\n<p>Note that the environment variable mentioned here is for the host&#8217;s Compose. If there is a build operation in the configuration file, these variables will not enter the build process. If you want to use variables in your build, it is still preferred. The arg tag.<\/p>\n<ol>\n<li>Environment<\/li>\n<\/ol>\n<p>Unlike the above env_file tag, which is somewhat similar to arg, the effect of this tag is to set the mirror variable, which can save the variable to the image, which means that the starting container will also contain these variable settings. This is the same as arg. The biggest difference.<br \/>\nGeneral arg tag variables are used only during the build process.\u00a0The ENV instruction in environment and Dockerfile will keep the variables in the image and container, similar to the effect of docker run -e.<\/p>\n<pre><code class=\"hljs yaml\"><span class=\"hljs-attr\"><span style=\"color: #333333;\">environment:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\">  RACK_ENV:<\/span> development<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\">  SHOW:<\/span> <span class=\"hljs-string\">'true'<\/span><\/span>\r\n<span class=\"hljs-attr\"><span style=\"color: #333333;\">  SESSION_SECRET:<\/span><\/span>\r\n\r\n<span class=\"hljs-attr\"><span style=\"color: #333333;\">environment:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-bullet\">  -<\/span> RACK_ENV=development<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-bullet\">  -<\/span> SHOW=<span class=\"hljs-literal\">true<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-bullet\">  -<\/span> SESSION_SECRET<\/span><\/code><\/pre>\n<ol>\n<li>The expose<\/li>\n<\/ol>\n<p>This tag is the same as the EXPOSE directive in the Dockerfile. It is used to specify the exposed port, but only as a reference. In fact, the port mapping of docker-compose.yml still has a tag like ports.<\/p>\n<pre><code class=\"hljs dts\"><span class=\"hljs-symbol\"><span style=\"color: #333333;\">expose:<\/span><\/span>\r\n<span style=\"color: #333333;\"> - <span class=\"hljs-string\">\"3000\"<\/span><\/span>\r\n<span style=\"color: #333333;\"> - <span class=\"hljs-string\">\"8000\"<\/span><\/span><\/code><\/pre>\n<ol>\n<li>External_links<\/li>\n<\/ol>\n<p>In the Docker process, we have a lot of containers that are started using docker run alone. To make Compose connect to containers that are not defined in docker-compose.yml, we need a special label, external_links, which allows the Compose project to work. The containers inside are connected to containers outside of the project configuration (provided that at least one container in the external container is connected to the same network as the service in the project).<br \/>\nThe format is as follows:<\/p>\n<pre><code class=\"hljs yaml\"><span class=\"hljs-attr\"><span style=\"color: #333333;\">external_links:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-bullet\"> -<\/span> redis_1<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\"> - project_db_1:<\/span>mysql<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\"> - project_db_1:<\/span>postgresql<\/span><\/code><\/pre>\n<ol>\n<li>Extra_hosts<\/li>\n<\/ol>\n<p>Add the host name tag, which is to add some records to the \/etc\/hosts file, similar to the &#8211;add-host of the Docker client:<\/p>\n<pre><code class=\"hljs dts\"><span class=\"hljs-symbol\"><span style=\"color: #333333;\">extra_hosts:<\/span><\/span>\r\n<span style=\"color: #333333;\"> - <span class=\"hljs-string\">\"somehost:162.242.195.82\"<\/span><\/span>\r\n<span style=\"color: #333333;\"> - <span class=\"hljs-string\">\"otherhost:50.31.209.229\"<\/span><\/span><\/code><\/pre>\n<p>View the internal hosts of the container after startup:<\/p>\n<pre><code class=\"hljs css\"><span style=\"color: #333333;\">162<span class=\"hljs-selector-class\">.242<\/span><span class=\"hljs-selector-class\">.195<\/span><span class=\"hljs-selector-class\">.82<\/span>  <span class=\"hljs-selector-tag\">somehost<\/span><\/span>\r\n<span style=\"color: #333333;\">50<span class=\"hljs-selector-class\">.31<\/span><span class=\"hljs-selector-class\">.209<\/span><span class=\"hljs-selector-class\">.229<\/span>   <span class=\"hljs-selector-tag\">otherhost<\/span><\/span><\/code><\/pre>\n<ol>\n<li>Labels<\/li>\n<\/ol>\n<p>Add metadata to the container, and the meaning of the Dockerfile&#8217;s LABEL directive is as follows:<\/p>\n<pre><code class=\"hljs groovy\"><span class=\"hljs-string\"><span style=\"color: #333333;\">labels:<\/span><\/span>\r\n<span style=\"color: #333333;\">  com.example.<span class=\"hljs-string\">description:<\/span> <span class=\"hljs-string\">\"Accounting webapp\"<\/span><\/span>\r\n<span style=\"color: #333333;\">  com.example.<span class=\"hljs-string\">department:<\/span> <span class=\"hljs-string\">\"Finance\"<\/span><\/span>\r\n<span style=\"color: #333333;\">  com.example.label-with-empty-<span class=\"hljs-string\">value:<\/span> <span class=\"hljs-string\">\"\"<\/span><\/span>\r\n<span class=\"hljs-string\"><span style=\"color: #333333;\">labels:<\/span><\/span>\r\n<span style=\"color: #333333;\">  - <span class=\"hljs-string\">\"com.example.description=Accounting webapp\"<\/span><\/span>\r\n<span style=\"color: #333333;\">  - <span class=\"hljs-string\">\"com.example.department=Finance\"<\/span><\/span>\r\n<span style=\"color: #333333;\">  - <span class=\"hljs-string\">\"com.example.label-with-empty-value\"<\/span><\/span><\/code><\/pre>\n<ol>\n<li>Links<\/li>\n<\/ol>\n<p>Remember the above depends_on, that the tag solves the startup sequence problem, this tag resolves the container connection problem, and is the same as the docker client&#8217;s &#8211;link, which connects to containers in other services.<br \/>\nThe format is as follows:<\/p>\n<pre><code class=\"hljs yaml\"><span class=\"hljs-attr\"><span style=\"color: #333333;\">links:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-bullet\"> -<\/span> db<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\"> - db:<\/span>database<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-bullet\"> -<\/span> redis<\/span><\/code><\/pre>\n<p>The alias used will be automatically created in \/etc\/hosts in the service container.\u00a0E.g:<\/p>\n<pre><code class=\"hljs css\"><span style=\"color: #333333;\">172<span class=\"hljs-selector-class\">.12<\/span><span class=\"hljs-selector-class\">.2<\/span><span class=\"hljs-selector-class\">.186<\/span>  <span class=\"hljs-selector-tag\">db<\/span><\/span>\r\n<span style=\"color: #333333;\">172<span class=\"hljs-selector-class\">.12<\/span><span class=\"hljs-selector-class\">.2<\/span><span class=\"hljs-selector-class\">.186<\/span>  <span class=\"hljs-selector-tag\">database<\/span><\/span>\r\n<span style=\"color: #333333;\">172<span class=\"hljs-selector-class\">.12<\/span><span class=\"hljs-selector-class\">.2<\/span><span class=\"hljs-selector-class\">.187<\/span>  <span class=\"hljs-selector-tag\">redis<\/span><\/span><\/code><\/pre>\n<p>The corresponding environment variable will also be created.<\/p>\n<ol>\n<li>Logging<\/li>\n<\/ol>\n<p>This tag is used to configure the log service.\u00a0The format is as follows:<\/p>\n<pre><code class=\"hljs yaml\"><span class=\"hljs-attr\"><span style=\"color: #333333;\">logging:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\">  driver:<\/span> syslog<\/span>\r\n<span class=\"hljs-attr\"><span style=\"color: #333333;\">  options:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\">    syslog-address:<\/span> <span class=\"hljs-string\">\"tcp:\/\/192.168.0.42:123\"<\/span><\/span><\/code><\/pre>\n<p>The default driver is json-file.\u00a0Only json-file and journald can display logs through docker-compose logs. There are other ways to view logs, but Compose does not support them.\u00a0For optional values, use options.<br \/>\nFor more information on this you can read the official documentation:<br \/>\n<a class=\"uri\" href=\"https:\/\/docs.docker.com\/engine\/admin\/logging\/overview\/\">https:\/\/docs.docker.com\/engine\/admin\/logging\/overview\/<\/a><\/p>\n<ol>\n<li>Pid<\/li>\n<\/ol>\n<p>Pid: &#8220;host&#8221;<br \/>\nsets the PID mode to host PID mode, sharing the process namespace with the host system.\u00a0Containers using this tag will be able to access and manipulate the namespaces of other containers and hosts.<\/p>\n<ol>\n<li>Ports<\/li>\n<\/ol>\n<p>Map the port&#8217;s tag.<br \/>\nUsing the HOST:CONTAINER format or just specifying the port of the container, the host randomly maps ports.<\/p>\n<pre><code class=\"hljs css\"><span style=\"color: #333333;\"><span class=\"hljs-selector-tag\">ports<\/span>:<\/span>\r\n<span style=\"color: #333333;\"> <span class=\"hljs-selector-tag\">-<\/span> \"3000\"<\/span>\r\n<span style=\"color: #333333;\"> <span class=\"hljs-selector-tag\">-<\/span> \"8000<span class=\"hljs-selector-pseudo\">:8000\"<\/span><\/span>\r\n<span style=\"color: #333333;\"> <span class=\"hljs-selector-tag\">-<\/span> \"49100<span class=\"hljs-selector-pseudo\">:22\"<\/span><\/span>\r\n<span style=\"color: #333333;\"> <span class=\"hljs-selector-tag\">-<\/span> \"127<span class=\"hljs-selector-class\">.0<\/span><span class=\"hljs-selector-class\">.0<\/span><span class=\"hljs-selector-class\">.1<\/span><span class=\"hljs-selector-pseudo\">:8001<\/span><span class=\"hljs-selector-pseudo\">:8001\"<\/span><\/span><\/code><\/pre>\n<p>Note: When using HOST:CONTAINER format to map ports, if you use a container port less than 60 you may get a wrong result, because YAML will parse xx:yy this number format is hexadecimal.\u00a0Therefore, it is recommended to use a string format.<\/p>\n<ol>\n<li>Security_opt<\/li>\n<\/ol>\n<p>Override the default label for each container.\u00a0Simply put, it is the label for managing all services.\u00a0For example, set the user tag for all services to USER.<\/p>\n<pre><code class=\"hljs groovy\"><span class=\"hljs-string\"><span style=\"color: #333333;\">security_opt:<\/span><\/span>\r\n<span style=\"color: #333333;\">  - <span class=\"hljs-string\">label:<\/span><span class=\"hljs-string\">user:<\/span>USER<\/span>\r\n<span style=\"color: #333333;\">  - <span class=\"hljs-string\">label:<\/span><span class=\"hljs-string\">role:<\/span>ROLE<\/span><\/code><\/pre>\n<ol>\n<li>Stop_signal<\/li>\n<\/ol>\n<p>Set another signal to stop the container.\u00a0The SIGTERM stop container is used by default.\u00a0Set another signal to use the stop_signal tag.<\/p>\n<p>Stop_signal: SIGUSR1<\/p>\n<ol>\n<li>Volumes<\/li>\n<\/ol>\n<p>Mount a directory or an existing data volume container, either directly using the format [HOST:CONTAINER], or using the format [HOST:CONTAINER:ro], which is read-only for containers This can effectively protect the host&#8217;s file system.<br \/>\nThe Compose data volume designation path can be a relative path, using . or .. to specify the relative directory.<br \/>\nThe format of the data volume can be in the following forms:<\/p>\n<p>Volumes:<br \/>\n\/\/ Just specify a path, Docker will automatically create a data volume (this path is inside the container).<\/p>\n<pre><code class=\"hljs swift\"><span style=\"color: #333333;\">- \/<span class=\"hljs-keyword\">var<\/span>\/lib\/mysql<\/span><\/code><\/pre>\n<p>\/\/ Mount data volume using absolute path<\/p>\n<pre><code class=\"hljs ruby\"><span style=\"color: #333333;\">  - <span class=\"hljs-regexp\">\/opt\/data<\/span><span class=\"hljs-symbol\">:\/var\/lib\/mysql<\/span><\/span><\/code><\/pre>\n<p>\/\/ The relative path centered on the Compose configuration file is mounted as a data volume to the container.<\/p>\n<pre><code class=\"hljs sql\"><span style=\"color: #333333;\">- .\/<span class=\"hljs-keyword\">cache<\/span>:\/tmp\/<span class=\"hljs-keyword\">cache<\/span><\/span><\/code><\/pre>\n<p>\/\/ Use the relative path of the user (the directory represented by ~\/ is \/home\/&lt;user directory&gt;\/ or \/root\/).<\/p>\n<pre><code class=\"hljs ruby\"><span style=\"color: #333333;\"> - ~<span class=\"hljs-regexp\">\/configs:\/etc<\/span><span class=\"hljs-regexp\">\/configs\/<\/span><span class=\"hljs-symbol\">:ro<\/span><\/span><\/code><\/pre>\n<p>\/\/ An existing named data volume.<\/p>\n<pre><code class=\"hljs groovy\"><span style=\"color: #333333;\">- <span class=\"hljs-string\">datavolume:<\/span><span class=\"hljs-regexp\">\/var\/<\/span>lib\/mysql<\/span><\/code><\/pre>\n<p>If you do not use the host&#8217;s path, you can specify a volume_driver.<\/p>\n<pre><code class=\"hljs yaml\"><span style=\"color: #333333;\"><span class=\"hljs-attr\">volume_driver:<\/span> mydriver<\/span><\/code><\/pre>\n<ol>\n<li>Volumes_from<\/li>\n<\/ol>\n<p>Mount data volumes from other containers or services. Optional parameters are: ro or :rw. The former indicates that the container is read-only and the latter indicates that the container is readable and writeable to the data volume.\u00a0It is readable and writable by default.<\/p>\n<pre><code class=\"hljs groovy\"><span class=\"hljs-string\"><span style=\"color: #333333;\">volumes_from:<\/span><\/span>\r\n<span style=\"color: #333333;\">  - service_name<\/span>\r\n<span style=\"color: #333333;\">  - <span class=\"hljs-string\">service_name:<\/span>ro<\/span>\r\n<span style=\"color: #333333;\">  - <span class=\"hljs-string\">container:<\/span>container_name<\/span>\r\n<span style=\"color: #333333;\">  - <span class=\"hljs-string\">container:<\/span><span class=\"hljs-string\">container_name:<\/span>rw<\/span><\/code><\/pre>\n<ol>\n<li>Cap_add, cap_drop<\/li>\n<\/ol>\n<p>Add or remove the container&#8217;s kernel features.\u00a0Detailed information is explained in the previous section of the container and will not be repeated here.<\/p>\n<pre><code class=\"hljs makefile\"><span class=\"hljs-section\"><span style=\"color: #333333;\">cap_add:<\/span><\/span>\r\n<span style=\"color: #333333;\">  - ALL<\/span>\r\n\r\n<span class=\"hljs-section\"><span style=\"color: #333333;\">cap_drop:<\/span><\/span>\r\n<span style=\"color: #333333;\">  - NET_ADMIN<\/span>\r\n<span style=\"color: #333333;\">  - SYS_ADMIN<\/span><\/code><\/pre>\n<ol>\n<li>Cgroup_parent<\/li>\n<\/ol>\n<p>Specifies the parent cgroup of a container.<\/p>\n<p>Cgroup_parent: m-executor-abcd<\/p>\n<ol>\n<li>Devices<\/li>\n<\/ol>\n<p>List of device mappings.\u00a0Similar to the &#8211;device parameter of the Docker client.<\/p>\n<pre><code class=\"hljs dts\"><span class=\"hljs-symbol\"><span style=\"color: #333333;\">devices:<\/span><\/span>\r\n<span style=\"color: #333333;\">  - <span class=\"hljs-string\">\"\/dev\/ttyUSB0:\/dev\/ttyUSB0\"<\/span><\/span><\/code><\/pre>\n<ol>\n<li>Extends<\/li>\n<\/ol>\n<p>This tag can be used to extend another service. Extended content can be from the current file, or from other files, and the same service. Latecomers can choose to overwrite the original configuration.<\/p>\n<p>Extends\u00a0:\u00a0file: common.yml<br \/>\nservice: webapp<br \/>\nusers can use this tag anywhere, as long as the tag content contains both file and service values.\u00a0The value of file can be a relative or absolute path. If you do not specify the value of file, Compose will read the current YML file information.<br \/>\nMore details of the operation are described later in subsection 12.3.4.<\/p>\n<ol>\n<li>Network_mode<\/li>\n<\/ol>\n<p>The network mode is similar to the &#8211;net parameter of the Docker client, except that there is a relatively more service:[service name] format.<br \/>\nE.g:<\/p>\n<pre><code class=\"hljs dts\"><span style=\"color: #333333;\"><span class=\"hljs-symbol\">network_mode:<\/span> <span class=\"hljs-string\">\"bridge\"<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-symbol\">network_mode:<\/span> <span class=\"hljs-string\">\"host\"<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-symbol\">network_mode:<\/span> <span class=\"hljs-string\">\"none\"<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-symbol\">network_mode:<\/span> <span class=\"hljs-string\">\"service:[service name]\"<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-symbol\">network_mode:<\/span> <span class=\"hljs-string\">\"container:[container name\/id]\"<\/span><\/span><\/code><\/pre>\n<p>You can specify the network that uses the service or container.<\/p>\n<ol>\n<li>Networks<\/li>\n<\/ol>\n<p>Join the specified network in the following format:<\/p>\n<pre><code class=\"hljs yaml\"><span class=\"hljs-attr\"><span style=\"color: #333333;\">services:<\/span><\/span>\r\n<span class=\"hljs-attr\"><span style=\"color: #333333;\">  some-service:<\/span><\/span>\r\n<span class=\"hljs-attr\"><span style=\"color: #333333;\">    networks:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-bullet\">     -<\/span> some-network<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-bullet\">     -<\/span> other-network<\/span><\/code><\/pre>\n<p>There is also a special child tag aliases for this tag. This is a tag to set the service alias, for example:<\/p>\n<pre><code class=\"hljs yaml\"><span class=\"hljs-attr\"><span style=\"color: #333333;\">services:<\/span><\/span>\r\n<span class=\"hljs-attr\"><span style=\"color: #333333;\">  some-service:<\/span><\/span>\r\n<span class=\"hljs-attr\"><span style=\"color: #333333;\">    networks:<\/span><\/span>\r\n<span class=\"hljs-attr\"><span style=\"color: #333333;\">      some-network:<\/span><\/span>\r\n<span class=\"hljs-attr\"><span style=\"color: #333333;\">        aliases:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-bullet\">         -<\/span> alias1<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-bullet\">         -<\/span> alias3<\/span>\r\n<span class=\"hljs-attr\"><span style=\"color: #333333;\">      other-network:<\/span><\/span>\r\n<span class=\"hljs-attr\"><span style=\"color: #333333;\">        aliases:<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-bullet\">         -<\/span> alias2<\/span><\/code><\/pre>\n<p>The same service can have different aliases on different networks.<\/p>\n<ol>\n<li>other<\/li>\n<\/ol>\n<p>There are also these tags: cpu_shares, cpu_quota, cpuset, domainname, hostname, ipc, mac_address, mem_limit, memswap_limit, privileged, read_only, restart, shm_size, stdin_open, tty, user, working_dir<br \/>\nThese are all single-valued tags, similar to Use docker run effect.<\/p>\n<pre><code class=\"hljs http\"><span style=\"color: #333333;\"><span class=\"hljs-attribute\">cpu_shares<\/span>: 73<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attribute\">cpu_quota<\/span>: 50000<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attribute\">cpuset<\/span>: 0,1<\/span>\r\n\r\n<span class=\"http\"><span style=\"color: #333333;\"><span class=\"hljs-attribute\">user<\/span>: postgresql<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attribute\">working_dir<\/span>: \/code<\/span>\r\n\r\n<span style=\"color: #333333;\"><span class=\"hljs-attribute\">domainname<\/span>: foo.com<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attribute\">hostname<\/span>: foo<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attribute\">ipc<\/span>: host<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attribute\">mac_address<\/span>: 02:42:ac:11:65:43<\/span>\r\n\r\n<span style=\"color: #333333;\"><span class=\"hljs-attribute\">mem_limit<\/span>: 1000000000<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attribute\">memswap_limit<\/span>: 2000000000<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attribute\">privileged<\/span>: true<\/span>\r\n\r\n<span style=\"color: #333333;\"><span class=\"hljs-attribute\">restart<\/span>: always<\/span>\r\n\r\n<span class=\"yaml\"><span style=\"color: #333333;\"><span class=\"hljs-attr\">read_only:<\/span> <span class=\"hljs-literal\">true<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\">shm_size:<\/span> <span class=\"hljs-number\">64<\/span>M<\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\">stdin_open:<\/span> <span class=\"hljs-literal\">true<\/span><\/span>\r\n<span style=\"color: #333333;\"><span class=\"hljs-attr\">tty:<\/span> <span class=\"hljs-literal\">true<\/span><\/span><\/span><\/span><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Docker Engine Starting from version 1.12.0, Docker Swarm is integrated natively. The operation of the cluster can be directly controlled by the docker service command, which is very convenient and the operation process is greatly simplified. Docker Swarm For the average developer, the biggest advantage lies in the native support of the load balancing mechanism, [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7353"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7353"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7353\/revisions"}],"predecessor-version":[{"id":7354,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7353\/revisions\/7354"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}