{"id":388,"date":"2023-09-16T10:57:09","date_gmt":"2023-09-16T02:57:09","guid":{"rendered":""},"modified":"2023-09-16T10:57:09","modified_gmt":"2023-09-16T02:57:09","slug":"docker\u5206\u5e03\u5f0f\u5e94\u7528\u90e8\u7f72\u65b9\u6848","status":"publish","type":"post","link":"https:\/\/mushiming.com\/388.html","title":{"rendered":"docker\u5206\u5e03\u5f0f\u5e94\u7528\u90e8\u7f72\u65b9\u6848"},"content":{"rendered":"

\u76ee\u5f55<\/strong><\/p>\n

\u4e00. \u7b80\u5355\u7684IDEA\u6253\u5305\u90e8\u7f72docker<\/p>\n

\u4e8c. docker Compose<\/p>\n

1. \u5b98\u7f51\u4ecb\u7ecd<\/p>\n

2. compose\u7684\u5b89\u88c5\u4ee5\u53ca\u6d4b\u8bd5<\/p>\n

3. compose\u914d\u7f6e\u6587\u4ef6yml\u7f16\u5199<\/p>\n

4. \u7f16\u5199\u670d\u52a1\uff0c\u6d4b\u8bd5compose<\/p>\n

\u4e09. docker Swarm<\/p>\n

1. \u8fd0\u884cswarm\u96c6\u7fa4<\/p>\n

1.1 \u521d\u59cb\u5316init<\/p>\n

1.2 \u52a0\u5165\u8282\u70b9join<\/p>\n

1.3 \u67e5\u770b\u6d4b\u8bd5\u4ee5\u53caraft\u4e00\u81f4\u6027\u7b97\u6cd5<\/p>\n

2. swarm\u90e8\u7f72\u5e94\u7528<\/p>\n

2.1 \u521b\u5efa\u4e00\u4e2aswarm\u96c6\u7fa4\u670d\u52a1<\/p>\n


\n

\u4e00. \u7b80\u5355\u7684IDEA\u6253\u5305\u90e8\u7f72docker<\/h1>\n
\n

\u5c06\u6211\u4eec\u5199\u597d\u7684java\u9879\u76ee\uff0c\u901a\u8fc7dockerfile\u6253\u5305\u90e8\u7f72\u5728docker\u4e2d\u8fd0\u884c<\/p>\n<\/blockquote>\n

\u2460\u5728IDEA\u4e2d\u7f16\u5199dockerFile\u6587\u4ef6\uff08\u6700\u597d\u4e0b\u8f7ddocker\u7684IDEA\u63d2\u4ef6\uff09<\/p>\n

FROM java:8\n#\u628a\u5f53\u524d\u8def\u5f84\u4e0b\u7684jar\u6587\u4ef6\uff0ccopy\u5230\u6307\u5b9a\u76ee\u5f55\u4e2d\nCOPY *.jar \/opt\/jar\/app.jar\nCMD [\"--server.port=8090\"]\nEXPOSE 8090\n#docker run \u540e\u6307\u5b9a\u547d\u4ee4: java -jar \/opt\/jar\/app.jar\nENTRYPOINT [\"java\", \"-jar\", \"\/opt\/jar\/app.jar\"]\n\n#docker run \u6700\u7ec8\u6307\u5b9a\u547d\u4ee4: java -jar \/opt\/jar\/app.jar --server.port=8090<\/code><\/pre>\n

\u2461\u5c06jar\u5305\u548cDockerfile\u6587\u4ef6\u4e0a\u4f20\u81f3\u670d\u52a1\u5668\uff0c\u7136\u540e\u901a\u8fc7docker build\u547d\u4ee4\u6253\u5305\u6210\u955c\u50cf\uff0c\u7136\u540e\u76f4\u63a5run\u8fd0\u884c\u5373\u53ef\u5b8c\u6210\u53d1\u5e03\u90e8\u7f72<\/p>\n

\u4e8c. docker Compose<\/h1>\n
\n

\u901a\u8fc7docker\u8fdb\u884c\u90e8\u7f72\uff0c\u53ef\u4ee5\u901a\u901a\u8fc7dockerFile\u6587\u4ef6---build---run\u624b\u52a8\u5b8c\u6210\u5355\u4e2a\u5bb9\u5668\u7684\u90e8\u7f72\u8fd0\u884c<\/p>\n

\u5982\u679c\u901a\u8fc7compose\u6765\u90e8\u7f72\u7684\u8bdd\uff0c\u53ef\u4ee5\u505a\u5230\u591a\u4e2a\u5e94\u7528\u6dfb\u52a0\u4f9d\u8d56\u5173\u7cfb\uff0c\u9ad8\u6548\u7684\u5b9e\u73b0\u7ba1\u7406\u5bb9\u5668<\/p>\n<\/blockquote>\n

1. \u5b98\u7f51\u4ecb\u7ecd<\/h2>\n
\n
    \n
  • compose\u662f\u4e00\u4e2a\u7528\u6765\u5b9a\u4e49\u548c\u8fd0\u884c\u5bb9\u5668<\/span>\u7684\u5e94\u7528\uff08docker\u7684\u5f00\u6e90\u9879\u76ee\uff09<\/li>\n
  • \u901a\u8fc7yam<\/span>l\u6587\u4ef6\u914d\u7f6e\u5e94\u7528\u670d\u52a1<\/li>\n
  • \u901a\u8fc7\u547d\u4ee4<\/span>\uff0cdocker-compose-up\uff0c\u521b\u5efa\u5e76\u542f\u52a8\u4e00\u4e2acompose<\/li>\n
  • \u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\uff0c\u81ea\u52a8\u542f\u52a8\u670d\u52a1\uff0c\u5e76\u8bbe\u7f6e\u4f9d\u8d56\u5173\u7cfb\u3002\u5b9e\u73b0\u5bb9\u5668\u7684\u6279\u91cf\u7f16\u6392\u3002\u4e00\u952e\u7edf\u4e00\u90e8\u7f72<\/li>\n<\/ul>\n<\/blockquote>\n

     \"docker\u5206\u5e03\u5f0f\u5e94\u7528\u90e8\u7f72\u65b9\u6848<\/p>\n

    2. compose\u7684\u5b89\u88c5\u4ee5\u53ca\u6d4b\u8bd5<\/h2>\n

    \u2460\u4e0b\u8f7dcompose\uff1a<\/strong><\/p>\n

    \u5b98\u65b9\u4e0b\u8f7d\uff08\u901f\u5ea6\u8f83\u6162\uff09\uff1a<\/p>\n

    sudo curl -L \"https:\/\/github.com\/docker\/compose\/releases\/download\/1.27.4\/docker-compose-$(uname -s)-$(uname -m)\" -o \/usr\/local\/bin\/docker-compose<\/p>\n

    \u56fd\u5185\u955c\u50cf\u4e0b\u8f7d\uff1a<\/p>\n

    curl -L https:\/\/get.daocloud.io\/docker\/compose\/releases\/download\/1.25.5\/docker-compose-`uname -s`-`uname -m` > \/usr\/local\/bin\/docker-compose<\/p>\n

    \u2461\u8bbe\u7f6e\u6743\u9650<\/strong><\/p>\n

    sudo chmod +x \/usr\/local\/bin\/docker-compose<\/code><\/pre>\n

    \u2462\u6d4b\u8bd5<\/strong><\/p>\n

    #\u67e5\u770b\u7248\u672c\ndocker-compose version<\/code><\/pre>\n

     <\/p>\n

     <\/p>\n

    3. compose\u914d\u7f6e\u6587\u4ef6yml\u7f16\u5199<\/h2>\n
    \n

    docker compose\u7684\u914d\u7f6e\u6587\u4ef6\u4e3b\u8981\u7528\u6765\u914d\u7f6e\u5bb9\u5668\u4ee5\u53ca\u5bb9\u5668\u7684\u89c4\u5219\u3002\u53ef\u4ee5\u7406\u89e3\u4e3a\u4e00\u5171\u6709\u4e09\u5c42<\/p>\n

    \u53c2\u8003\u5b98\u65b9\u6587\u6863\uff1ahttps:\/\/docs.docker.com\/compose\/compose-file\/<\/p>\n<\/blockquote>\n

    #\u2460compose\u7684\u7248\u672c\uff0c\u9700\u8981\u4e0edocker\u7684\u5f15\u64ce\u517c\u5bb9\nversion: 3.8 \n\n#\u2461\u914d\u7f6e\u7684\u670d\u52a1\uff0c\u5c31\u76f8\u5f53\u4e8e\u914d\u7f6e\u4e86\u54ea\u4e9b\u5bb9\u5668\nservice\uff1a\n    \u670d\u52a11\uff1a\n        #\u53ef\u4ee5\u914d\u7f6e\u8be5\u5bb9\u5668\u7684\u5185\u5bb9\uff0c\u4f8b\u5982images\/build\/network\/ports\u7b49\n    \u670d\u52a12:\n        ...\n\n#\u2462\u5176\u4ed6\u914d\u7f6e\uff0c\u4f8b\u5982\u53ef\u4ee5\u6dfb\u52a0\u4e00\u4e2a\u7f51\u7edc\u3001\u6dfb\u52a0\u6302\u8f7d\u8bbe\u7f6e\u7b49\u7b49\nnetworks:\n    ....\nvolumes:\n    ....<\/code><\/pre>\n

    \u547d\u4ee4\uff1a\u5b98\u65b9\u6587\u6863\u7ed9\u51fa\u4e86\u6240\u6709\u547d\u4ee4\u7684\u4f7f\u7528\u89c4\u5219\uff0c\u4e0b\u9762\u5217\u4e3e\u5e38\u7528\u7684\u547d\u4ee4\u793a\u4f8b<\/p>\n

      \n
    • build\uff1a\u6784\u5efa\uff0c\u53ef\u4ee5\u7528\u6765\u6307\u5b9a\u6784\u5efa\u8def\u5f84  .\u8868\u793a\u5f53\u524d\u8def\u5f84\uff0c\u4e0b\u9762\u8868\u793a\u5728\u5f53\u524d\u8def\u5f84\u7684dir\u6587\u4ef6\u4e2d\u901a\u8fc7Dockerfile-alternate\u6587\u4ef6\u4e3a\u8fdb\u884c\u8fdb\u884c\u6784\u5efa\u955c\u50cf\uff0cdockerfile\u5982\u679c\u4e0d\u5199\uff0c\u9ed8\u8ba4\u5c31\u662f\u627e\u8def\u5f84\u4e0bDockerfile\u6587\u4ef6<\/li>\n<\/ul>\n

      \"docker\u5206\u5e03\u5f0f\u5e94\u7528\u90e8\u7f72\u65b9\u6848<\/p>\n

        \n
      • network\uff1a\u6307\u5b9a\u4f7f\u7528\u7684\u7f51\u7edc<\/li>\n<\/ul>\n

        \"docker\u5206\u5e03\u5f0f\u5e94\u7528\u90e8\u7f72\u65b9\u6848<\/p>\n

          \n
        • command\uff1a\u7f16\u5199\u547d\u4ee4<\/li>\n<\/ul>\n

          \"docker\u5206\u5e03\u5f0f\u5e94\u7528\u90e8\u7f72\u65b9\u6848<\/p>\n

            \n
          • \n

            container_name\uff1a\u6307\u5b9a\u5bb9\u5668\u7684\u540d\u5b57<\/p>\n<\/li>\n<\/ul>\n

            \"docker\u5206\u5e03\u5f0f\u5e94\u7528\u90e8\u7f72\u65b9\u6848<\/p>\n

              \n
            • \n

              depends_on\uff1a\u6307\u5b9a\u542f\u52a8\u4f9d\u8d56\u5173\u7cfb<\/p>\n<\/li>\n<\/ul>\n

              \"docker\u5206\u5e03\u5f0f\u5e94\u7528\u90e8\u7f72\u65b9\u6848<\/p>\n

                \n
              • \n

                deploy\uff1a\u96c6\u7fa4\u76f8\u5173<\/p>\n<\/li>\n

              • \n

                environment\uff1a\u73af\u5883\u53d8\u91cf\uff0c\u4f8b\u5982\u8bbe\u7f6emysql\u7684\u5bc6\u7801<\/p>\n<\/li>\n<\/ul>\n

                \"docker\u5206\u5e03\u5f0f\u5e94\u7528\u90e8\u7f72\u65b9\u6848<\/p>\n

                4. \u7f16\u5199\u670d\u52a1\uff0c\u6d4b\u8bd5compose<\/h2>\n

                \u6d4b\u8bd5\u4e00\u4e2aspringboot\u548cRedis\u96c6\u5408\u4f7f\u7528\u7684web\u5e94\u7528<\/p>\n

                  \n
                • \u521b\u5efa\u4e00\u4e2a\u65b0\u7684springboot\u9879\u76ee\uff0c\u8bbe\u7f6eRedis\u914d\u7f6e\uff0c\u521b\u5efa\u4e00\u4e2acontroller\u6d4b\u8bd5\u63a5\u53e3\uff1a<\/li>\n<\/ul>\n

                  \"docker\u5206\u5e03\u5f0f\u5e94\u7528\u90e8\u7f72\u65b9\u6848<\/p>\n

                  \"docker\u5206\u5e03\u5f0f\u5e94\u7528\u90e8\u7f72\u65b9\u6848<\/p>\n

                    \n
                  • \u5c06\u8be5springboot\u9879\u76ee\u6253\u5305\uff0c\u5e76\u7f16\u5199Dockerfile\u6587\u4ef6\uff1a<\/li>\n<\/ul>\n

                    \"docker\u5206\u5e03\u5f0f\u5e94\u7528\u90e8\u7f72\u65b9\u6848<\/p>\n

                      \n
                    • \u5c06jar\u5305\u548cdockerfile\u4e0a\u4f20\u81f3\u670d\u52a1\u5668\uff0c\u7f16\u5199docker-compose.yml\u6587\u4ef6\uff0c<\/li>\n<\/ul>\n

                      \u5c06springboot\u5e94\u7528\u6309\u7167\u6211\u4eec\u7f16\u5199\u7684dockerfile\u6784\u5efa\uff0c\u5c06Redis\u6309\u7167\u955c\u50cf\u6784\u5efa\uff0c\u5e76\u901a\u8fc7\u8be5\u914d\u7f6e\u6587\u4ef6\u7f16\u6392\u540e\u4e00\u8d77\u542f\u52a8\u3002<\/p>\n

                      version: \"3.8\"\nservices:\n  web:\n    #\u5bfb\u627e\u5f53\u524d\u8def\u5f84\u4e0b\u7684\u9ed8\u8ba4Dockerfile\u6587\u4ef6\u6784\u5efa\u955c\u50cf\n    build: .\n    ports:\n      - \"8090:8090\"\n    #\u542f\u52a8\u4f9d\u8d56Redis\n    depends_on:\n      - redis\n  redis:\n    #\u901a\u8fc7\u8be5\u955c\u50cf\u6784\u5efa\u5bb9\u5668\n    image: \"redis:alpine\"\n<\/code><\/pre>\n
                        \n
                      • \u542f\u52a8\uff1a docker-compse up \u8bbf\u95ee8090\u7aef\u53e3\u8fdb\u884c\u6d4b\u8bd5\u5b8c\u6210\u3002redis \u4e5f\u53ef\u4ee5\u6210\u529f\u8fde\u63a5<\/li>\n
                      • docker-compose down\u53ef\u4ee5\u505c\u6389compose\u670d\u52a1<\/li>\n<\/ul>\n

                        \u5b98\u65b9\u63d0\u4f9b\u7684\u4e00\u952e\u5b89\u88c5wordpress\u535a\u5ba2\u6848\u4f8b\uff1a<\/strong><\/span><\/p>\n

                        https:\/\/docs.docker.com\/compose\/wordpress\/<\/p>\n

                        \u4e09. docker Swarm<\/h1>\n
                        \n

                        swarm\u662f\u4e00\u4e2a\u96c6\u7fa4\u90e8\u7f72\u6a21\u5f0f\uff0c\u5206\u4e3amanager\u4e3b\u8282\u70b9\u548cwork\u5de5\u4f5c\u8282\u70b9\u3002<\/p>\n

                        \u64cd\u4f5c\u90fd\u662fmanager\u4e0a\u8fdb\u884c\u3002\u65e0\u9700\u5b89\u88c5\uff0cdocker\u5f15\u64ce\u81ea\u5e26swarm\u3002\u5177\u6709\u4e00\u81f4\u6027\u7684\u7279\u6027<\/p>\n

                          \n
                        • \u81f3\u5c11\u9700\u8981\u4fdd\u8bc1\u4e09\u4e2amanager\u8282\u70b9\uff0c\u5f53swarm\u53ea\u6709\u4e00\u4e2a\u4e3b\u8282\u70b9\u65f6\uff0c\u662f\u4e0d\u4f1a\u5de5\u4f5c\u7684<\/li>\n
                        • swarm\u642d\u5efa\u6210\u529f\u540e\uff0c\u4f1a\u521b\u5efa\u4e00\u4e2a\u9ed8\u8ba4\u7684\u7f51\u7edc\u3002\u96c6\u7fa4\u90fd\u5728\u8be5\u7f51\u7edc\u5de5\u4f5c\u3002docker swarm --help\u67e5\u770b\u5e2e\u52a9\u547d\u4ee4<\/li>\n<\/ul>\n

                          swarm\u662f\u96c6\u7fa4\u90e8\u7f72\uff0c\u5e94\u7528\u901a\u8fc7swarm\u8fdb\u884c\u90e8\u7f72\u540e\uff0c\u53ef\u4ee5\u65b9\u4fbf\u7684\u8fdb\u884c\u7ba1\u7406\u3001\u8d1f\u8f7d\u5747\u8861\u3001\u6269\u5bb9\u7f29\u5bb9\u7b49<\/p>\n

                          \u5229\u7528swarm\uff0c\u53ef\u4ee5\u5c06\u5e94\u7528\u90e8\u7f72\u5728\u4e00\u53f0\u670d\u52a1\u5668\uff0c\u7136\u540e\u901a\u8fc7swarm\u4e00\u952e\u6a2a\u5411\u6269\u5c55<\/span><\/p>\n

                          \u4f8b\uff1a<\/span><\/p>\n

                          \u90e8\u7f72\u4e00\u4e2aPMS-web\u5e94\u7528\uff0c\u90e8\u7f72\u5728\u67d0\u53f0\u670d\u52a1\u5668\u4e0a\u4f5c\u4e3aservice\uff0c\u7136\u540e\u6a2a\u5411\u6269\u5c55\u5206\u522b\u90e8\u7f72\u57284\u53f0\u673a\u5668\u4e0a\u3002\u901a\u8fc7nginx\u8d1f\u8f7d\u5747\u8861\u5b8c\u6210\u8bbf\u95ee\u3002\u5b9e\u73b0\u670d\u52a1\u7684\u9ad8\u53ef\u7528\u3002<\/span><\/p>\n<\/blockquote>\n

                           \u63d0\u4f9b\u4e86\u96c6\u7fa4\u7684\u52a0\u5165\u3001\u79bb\u5f00\u547d\u4ee4<\/p>\n

                          \"docker\u5206\u5e03\u5f0f\u5e94\u7528\u90e8\u7f72\u65b9\u6848<\/p>\n

                          1. \u8fd0\u884cswarm\u96c6\u7fa4<\/h2>\n

                          1.1 \u521d\u59cb\u5316init<\/h3>\n

                          \u9996\u5148\u5728\u67d0\u53f0\u670d\u52a1\u5668\u521d\u59cb\u5316swarm\uff0c\u901a\u8fc7init\u547d\u4ee4<\/p>\n

                          docker swarm init --advertise-addr 47.111.111.11<\/code><\/pre>\n

                          \u7136\u540e\u4f1a\u8fd4\u56de\u4e00\u4e2a\u5e26\u6709token\u7684join\u8fde\u63a5\uff1a\u5e76\u663e\u793a\u4e86\u5f53\u524dnode\u7684\u4fe1\u606f\uff0c\u662f\u4f5c\u4e3a\u4e00\u4e2amanager\u3002<\/p>\n

                          \"docker\u5206\u5e03\u5f0f\u5e94\u7528\u90e8\u7f72\u65b9\u6848<\/p>\n

                          1.2 \u52a0\u5165\u8282\u70b9join<\/h3>\n

                          \u751f\u6210\u52a0\u5165\u547d\u4ee4<\/strong>\u7684\u547d\u4ee4\uff1a<\/p>\n

                            \n
                          • docker swarm join-token worker  \uff1a \u52a0\u5165\u4e00\u4e2aworker\u8282\u70b9<\/li>\n
                          • docker swarm join-token manager  \uff1a \u52a0\u5165\u4e00\u4e2amanager\u8282\u70b9<\/li>\n<\/ul>\n

                            \u521d\u59cb\u5316\u4e00\u53f0manager\u670d\u52a1\u5668\u540e\uff0c\u5728\u53e6\u5916\u4e00\u53f0\u670d\u52a1\u5668\u4e2d\u4f5c\u4e3awork\/manager\u8282\u70b9\uff0c\u52a0\u5165\u8be5swarm\u4e2d\uff08\u7528init\u540e\u7684\u63d0\u793a\u8bed\u3001\u6216\u8005\u901a\u8fc7\u58f0\u660e\u547d\u4ee4\uff09<\/p>\n

                            \u6ce8<\/span>\uff1ainit\u7684manger\u8282\u70b9IP\u7684\u7aef\u53e3\uff0c\u9700\u8981\u5f00\u653e<\/strong><\/em><\/u><\/p>\n

                            docker swarm join --token SWMTKN-1-1fpo5ovbg8imf3vkaedqswlku3andjqf2ekps224r0hlvq8uvx-2ouvlo5e42hux9v48py56b0im 124.70.111.112:2377<\/code><\/pre>\n

                            1.3 \u67e5\u770b\u6d4b\u8bd5\u4ee5\u53caraft\u4e00\u81f4\u6027\u7b97\u6cd5<\/h3>\n

                            \u901a\u8fc7docker node ls  \u67e5\u770b\u6240\u6709\u7684\u8282\u70b9\u4fe1\u606f(\u53ea\u80fd\u5728manager\u8282\u70b9\u64cd\u4f5c)<\/p>\n

                            \u901a\u8fc7docker swarm leave \u79bb\u5f00\u5f53\u524d\u96c6\u7fa4<\/p>\n

                            raft\u4e00\u81f4\u6027\u7b97\u6cd5\uff1a<\/p>\n

                            \n

                            \u5982\u679cswarm\u4e2d\u53ea\u5269\u4e86\u4e00\u4e2amanager\u8282\u70b9\uff0c\u5219swarm\u4e0d\u53ef\u7528\u3002\u6240\u4ee5\uff0c\u6211\u4eec\u5728\u90e8\u7f72swarm\u7684\u65f6\u5019\uff0c\u81f3\u5c11\u9700\u8981\u90e8\u7f72\u4e09\u4e2amanager\u8282\u70b9\uff0c\u624d\u80fd\u4fdd\u8bc1\u9ad8\u53ef\u7528\u3002\u5047\u8bbe\u4e09\u53f0\u4e2d\u6709\u4e00\u53f0\u5b95\u673a\uff0c\u90a3\u8fd8\u6709\u4e24\u53f0\u53ef\u4ee5\u4f7f\u7528\uff0c\u5982\u679c\u4e24\u53f0\u4e2d\u518d\u6709\u4e00\u53f0\u5b95\u673a\uff0c\u5219\u6574\u4e2aswarm\u4e0d\u53ef\u7528\u3002<\/p>\n<\/blockquote>\n

                            2. swarm\u90e8\u7f72\u5e94\u7528<\/h2>\n
                            \n

                            \u5bf9\u4e8edocker\u6765\u8bf4\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7docker run\u8fd0\u884c\u4e00\u4e2a\u5bb9\u5668\u3001\u53ef\u4ee5\u901a\u8fc7docker-compose \u4e00\u952e\u542f\u52a8\u5bb9\u5668<\/p>\n

                            \u4f46\u662f\u8fd9\u90fd\u662f\u76f8\u5bf9\u4e8e\u5355\u673a\u670d\u52a1\u6765\u8bf4\u7684\uff0c\u5982\u679c\u9488\u5bf9\u4e8e\u96c6\u7fa4\u670d\u52a1\uff0c\u5c31\u9700\u8981\u4e00\u53f0\u670d\u52a1\u5668\u4e00\u53f0\u670d\u52a1\u5668\u7684\u8fd0\u884c\u547d\u4ee4\uff0c\u5e76\u4e14\u4e5f\u4e0d\u597d\u7ba1\u7406<\/p>\n

                            \u6240\u4ee5\uff0c\u5bf9\u4e8e\u96c6\u7fa4docker\u5bb9\u5668\u670d\u52a1\u7684\u4f7f\u7528\uff0cswarm\u63d0\u4f9b\u4e86\u65b9\u4fbf\u7684\u7ba1\u7406\u529f\u80fd<\/p>\n

                            swarm\u662f\u5e94\u7528\u96c6\u7fa4\u90e8\u7f72\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u4e5f\u5c31\u610f\u5473\u7740\u901a\u8fc7swarm\u90e8\u7f72\u7684\u5e94\u7528\uff0c\u662f\u4e00\u4e2a\u96c6\u7fa4\u73af\u5883\u3002\u901a\u8fc7swarm\u90e8\u7f72\u5e94\u7528\u53ef\u4ee5\u5b9e\u73b0\uff1a<\/p>\n

                              \n
                            • \u642d\u5efa\u5e94\u7528\u7684\u96c6\u7fa4\u73af\u5883<\/li>\n
                            • \u52a8\u6001\u7684\u6269\u7f29\u5bb9\u670d\u52a1<\/li>\n
                            • \u5b9e\u73b0\u7070\u8272(\u91d1\u4e1d\u96c0)\u66f4\u65b0(\u4e0d\u505c\u673a\u66f4\u65b0)<\/li>\n
                            • ......<\/li>\n<\/ul>\n<\/blockquote>\n

                              2.1 \u521b\u5efa\u4e00\u4e2aswarm\u96c6\u7fa4\u670d\u52a1<\/h3>\n
                              \n

                              docker service --help \u67e5\u770b\u5e2e\u52a9\u6587\u6863<\/p>\n

                              \u9996\u5148\u5728\u67d0\u53f0\u670d\u52a1\u5668\u4e0a\u521d\u59cb\u5316swarm \uff1a  docker swarm init<\/p>\n

                              docker service create<\/strong><\/span> -p 8090:80 --name my_service nginx   #\u901a\u8fc7swarm\u521b\u5efa\u4e00\u4e2anginx\u7684docker\u670d\u52a1\uff08\u4e8c\u4e3b\u4e8c\u4ece\u7684docker swarm\uff09<\/p>\n

                              \u521b\u5efa\u5b8c\u6210\u540e\uff0c\u4f1a\u5728\u8fd9\u56db\u53f0docker\u670d\u52a1\u5668\u4e2d\u968f\u673a\u4e00\u53f0\u4e0a\uff0c\u8fd0\u884c\u4e00\u4e2anginx\u7684docker\u5bb9\u5668\uff0c\u53ef\u901a\u8fc7docker ps\u67e5\u770b<\/p>\n<\/blockquote>\n

                              \n

                              \u6269\u5bb9\uff1aupdate\u3001scale<\/span><\/strong><\/p>\n

                              \u201cdocker swarm\u96c6\u7fa4\u4e2d\u7684service\u542f\u52a8\u540e\uff0c\u5728\u8be5\u96c6\u7fa4\u4e2d\u7684\u4efb\u610f\u8282\u70b9ip\u90fd\u53ef\u4ee5\u8bbf\u95ee\u8be5\u670d\u52a1\uff08\u4f1a\u81ea\u52a8\u8fdb\u884c\u8d1f\u8f7d\u5747\u8861\uff0c\u968f\u673a\u8bbf\u95ee\u4efb\u610f\u4e00\u4e2a\u5bb9\u5668\uff09\uff0c\u524d\u63d0\u662fdocker swarm\u7684\u670d\u52a1\u7aef\u53e3(2377)\u3001\u5e94\u7528\u7aef\u53e3(8090\u81ea\u5b9a\u4e49)\u3001\u901a\u8baf\u7aef\u53e3(7946)\u3001\u7f51\u7edc\u7aef\u53e3(4789)\u90fd\u5f00\u542f\u201d<\/strong><\/span><\/p>\n

                              \u6b64\u65f6nginx\u53ea\u5728\u4e00\u53f0\u670d\u52a1\u5668\u4e0a\u8fd0\u884c\u5417\uff0c\u5982\u679c\u9700\u8981\u6269\u5bb9\uff0c\u76f4\u63a5\u8fd0\u884cupdate\u6307\u4ee4\u5373\u53ef\uff1a<\/p>\n

                              eg\uff1a\u521b\u5efa10\u4e2anginx\u670d\u52a1\uff08\u968f\u673a\u5206\u914d\u5728\u4e0d\u540c\u7684\u670d\u52a1\u5668\u4e0a\uff09\uff1a<\/p>\n

                              docker service update --replicas 10 my-nginx   \u6216\u8005<\/p>\n

                              docker service scale my-nginx=10<\/p>\n

                              eg\uff1a\u7f29\u5bb9\u4e3a2\u4e2a\uff1a<\/p>\n

                              docker service update --replicas 2 my-nginx  \u6216\u8005<\/p>\n

                              docker service scale my-nginx=2<\/p>\n

                              \u901a\u8fc7docker service ls \u67e5\u770b\u6240\u6709\u7684\u670d\u52a1<\/p>\n

                              \"docker\u5206\u5e03\u5f0f\u5e94\u7528\u90e8\u7f72\u65b9\u6848<\/p>\n<\/blockquote>\n

                              \n

                              service\u7684\u64cd\u4f5c\uff1a<\/p>\n

                              \u53ef\u4ee5\u901a\u8fc7rm\u79fb\u9664\u3001rollback\u56de\u6eda\u3001logs\u67e5\u770b\u65e5\u5fd7\u3001inspect\u67e5\u770b\u5143\u6570\u636e<\/p>\n<\/blockquote>\n

                               <\/p>\n

                               <\/p>\n

                               <\/p>\n

                              +<\/p>\n

                               <\/p>\n

                               <\/p>\n

                               <\/p>\n

                               <\/p>\n

                               <\/p>\n","protected":false},"excerpt":{"rendered":"docker\u5206\u5e03\u5f0f\u5e94\u7528\u90e8\u7f72\u65b9\u6848\u4e00.\u7b80\u5355\u7684IDEA\u6253\u5305\u90e8\u7f72docker\u5c06\u6211\u4eec\u5199\u597d\u7684java\u9879\u76ee\uff0c\u901a\u8fc7dockerfile\u6253\u5305\u90e8\u7f72\u5728docker\u4e2d\u8fd0\u884c\u2460\u5728IDEA...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[83],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/388"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=388"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/388\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}