{"id":79271,"date":"2023-10-18T13:42:52","date_gmt":"2023-10-18T05:42:52","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=79271"},"modified":"2023-10-18T13:42:52","modified_gmt":"2023-10-18T05:42:52","slug":"ubuntu-use-docker-compose","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/ubuntu-use-docker-compose.html","title":{"rendered":"Ubuntu \u4e2dDocker Compose\u7684\u5947\u6deb\u5f02\u5de7"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nDocker Compose \u662f\u4e00\u4e2a\u8fd0\u884c\u591a\u5bb9\u5668 Docker \u5e94\u7528\u7684\u5de5\u5177\u3002Compose \u901a\u8fc7\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\u6765\u914d\u7f6e\u4e00\u4e2a\u5e94\u7528\u7684\u670d\u52a1\uff0c\u7136\u540e\u901a\u8fc7\u4e00\u4e2a\u547d\u4ee4\u521b\u5efa\u5e76\u542f\u52a8\u6240\u6709\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u6307\u5b9a\u7684\u670d\u52a1\u3002
\n\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u770b\u5230\u5982\u4f55\u5728 Ubuntn 16.04 \u4e0a\u5b89\u88c5 Docker Compose\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u5b89\u88c5 Docker<\/strong><\/div>\n

\u6211\u4eec\u9700\u8981\u5b89\u88c5 Docker \u6765\u5b89\u88c5 Docker Compose\u3002\u9996\u5148\u4e3a\u5b98\u65b9 Docker \u4ed3\u5e93\u6dfb\u52a0\u516c\u94a5\u3002<\/p>\n

$ curl -fsSL https:\/\/download.docker.com\/linux\/ubuntu\/gpg | sudo apt-key add -<\/pre>\n

\u63a5\u4e0b\u6765\uff0c\u6dfb\u52a0 Docker \u4ed3\u5e93\u5230 apt \u6e90\u5217\u8868\uff1a<\/p>\n

$ sudo add-apt-repository \"deb [arch=amd64] https:\/\/download.docker.com\/linux\/ubuntu $(lsb_release -cs) stable\"<\/pre>\n

\u66f4\u65b0\u5305\u6570\u636e\u5e93\uff0c\u5e76\u4f7f\u7528 apt \u5b89\u88c5 Docker<\/p>\n

$ sudo apt-get update\r\n$ sudo apt install docker-ce<\/pre>\n

\u5728\u5b89\u88c5\u8fdb\u7a0b\u7ed3\u675f\u540e\uff0cDocker \u5b88\u62a4\u7a0b\u5e8f\u5e94\u8be5\u5df2\u7ecf\u542f\u52a8\u5e76\u8bbe\u4e3a\u5f00\u673a\u81ea\u52a8\u542f\u52a8\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762\u7684\u547d\u4ee4\u6765\u67e5\u770b\u5b83\u7684\u72b6\u6001\uff1a<\/p>\n

$ sudo systemctl status docker\r\n---------------------------------\r\n\r\n\u25cf docker.service - Docker Application Container Engine\r\nLoaded: loaded (\/lib\/systemd\/system\/docker.service; enabled; vendor preset: enabled)\r\nActive: active (running)\r\n<\/pre>\n
\u5b89\u88c5 Docker Compose<\/strong><\/div>\n

\u73b0\u5728\u53ef\u4ee5\u5b89\u88c5 Docker Compose \u4e86\u3002\u901a\u8fc7\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u4e0b\u8f7d\u5f53\u524d\u7248\u672c\u3002<\/p>\n

# curl -L https:\/\/github.com\/docker\/compose\/releases\/download\/1.14.0\/docker-compose-\r\n`uname -s`-`uname -m` > \/usr\/local\/bin\/docker-compose\r\n<\/pre>\n

\u4e3a\u4e8c\u8fdb\u5236\u6587\u4ef6\u6dfb\u52a0\u6267\u884c\u6743\u9650\uff1a<\/p>\n

# chmod +x \/usr\/local\/bin\/docker-compose\r\n<\/pre>\n

\u68c0\u67e5 Docker Compose \u7248\u672c\uff1a<\/p>\n

$ docker-compose -v\r\n<\/pre>\n

\u8f93\u51fa\u5e94\u8be5\u5982\u4e0b\uff1a<\/p>\n

docker-compose version 1.14.0, build c7bdf9e\r\n<\/pre>\n
\u6d4b\u8bd5 Docker Compose<\/strong><\/div>\n

Docker Hub \u5305\u542b\u4e86\u4e00\u4e2a\u7528\u4e8e\u6f14\u793a\u7684 Hello World \u955c\u50cf\uff0c\u53ef\u4ee5\u7528\u6765\u8bf4\u660e\u4f7f\u7528 Docker Compose \u6765\u8fd0\u884c\u4e00\u4e2a\u5bb9\u5668\u6240\u9700\u7684\u914d\u7f6e\u3002<\/p>\n

\u521b\u5efa\u5e76\u6253\u5f00\u4e00\u4e2a\u76ee\u5f55\uff1a<\/p>\n

$ mkdir hello-world $ cd hello-world\r\n<\/pre>\n

\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 YAML \u6587\u4ef6\uff1a<\/p>\n

$ $EDITOR docker-compose.yml\r\n<\/pre>\n

\u5728\u6587\u4ef6\u4e2d\u7c98\u8d34\u5982\u4e0b\u5185\u5bb9\uff1a<\/p>\n

unixmen-compose-test:\r\nimage: hello-world\r\n<\/pre>\n

\u6ce8\u610f: \u7b2c\u4e00\u884c\u662f\u5bb9\u5668\u540d\u79f0\u7684\u4e00\u90e8\u5206\u3002
\n\u4fdd\u5b58\u5e76\u9000\u51fa\u3002<\/p>\n

\u8fd0\u884c\u5bb9\u5668<\/strong><\/div>\n

\u63a5\u4e0b\u6765\uff0c\u5728 hello-world \u76ee\u5f55\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

$ sudo docker-compose up\r\n<\/pre>\n

\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0cCompose \u8f93\u51fa\u5e94\u8be5\u5982\u4e0b\uff1a<\/p>\n

Pulling unixmen-compose-test (hello-world:latest)...\r\nlatest: Pulling from library\/hello-world\r\nb04784fba78d: Pull complete\r\nDigest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f\r\nStatus: Downloaded newer image for hello-world:latest\r\nCreating helloworld_unixmen-compose-test_1 ...\r\nCreating helloworld_unixmen-compose-test_1 ... done\r\nAttaching to helloworld_unixmen-compose-test_1\r\nunixmen-compose-test_1 |\r\nunixmen-compose-test_1 | Hello from Docker!\r\nunixmen-compose-test_1 | This message shows that your installation appears to be working correctly.\r\nunixmen-compose-test_1 |\r\nunixmen-compose-test_1 | To generate this message, Docker took the following steps:\r\nunixmen-compose-test_1 | 1\\. The Docker client contacted the Docker daemon.\r\nunixmen-compose-test_1 | 2\\. The Docker daemon pulled the \"hello-world\" image from the Docker Hub.\r\nunixmen-compose-test_1 | 3\\. The Docker daemon created a new container from that image which runs the\r\nunixmen-compose-test_1 | executable that produces the output you are currently reading.\r\nunixmen-compose-test_1 | 4\\. The Docker daemon streamed that output to the Docker client, which sent it\r\nunixmen-compose-test_1 | to your terminal.\r\nunixmen-compose-test_1 |\r\nunixmen-compose-test_1 | To try something more ambitious, you can run an Ubuntu container with:\r\nunixmen-compose-test_1 | $ docker run -it ubuntu bash\r\nunixmen-compose-test_1 |\r\nunixmen-compose-test_1 | Share images, automate workflows, and more with a free Docker ID:\r\nunixmen-compose-test_1 | https:\/\/cloud.docker.com\/\r\nunixmen-compose-test_1 |\r\nunixmen-compose-test_1 | For more examples and ideas, visit:\r\nunixmen-compose-test_1 | https:\/\/docs.docker.com\/engine\/userguide\/\r\nunixmen-compose-test_1 |\r\nhelloworld_unixmen-compose-test_1 exited with code 0 Docker\r\n<\/pre>\n

\u5bb9\u5668\u53ea\u80fd\u5728\u547d\u4ee4\uff08LCTT \u8bd1\u6ce8\uff1a\u6b64\u5904\u5e94\u4e3a\u5bb9\u5668\u4e2d\u7684\u547d\u4ee4\uff09\u8fd8\u5904\u4e8e\u6d3b\u52a8\u72b6\u6001\u65f6\u8fd0\u884c\uff0c\u56e0\u6b64\u5f53\u6d4b\u8bd5\u5b8c\u6210\u8fd0\u884c\u65f6\uff0c\u5bb9\u5668\u5c06\u505c\u6b62\u8fd0\u884c\u3002<\/p>\n

\u7ed3\u8bba<\/strong><\/div>\n

\u672c\u6587\u662f\u5173\u4e8e\u5728 Ubuntu 16.04 \u4e2d\u5b89\u88c5 Docker Compose \u7684\u6559\u7a0b\u3002\u6211\u4eec\u8fd8\u770b\u5230\u4e86\u5982\u4f55\u901a\u8fc7\u4e00\u4e2a YAML \u683c\u5f0f\u7684 Compose \u6587\u4ef6\u6784\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u9879\u76ee\u3002<\/p>\n


\n

via: https:\/\/www.unixmen.com\/container-docker-compose-ubuntu-16-04\/<\/a><\/p>\n

\u4f5c\u8005\uff1aGiuseppe Molica<\/a> \u8bd1\u8005\uff1aLocez<\/a> \u6821\u5bf9\uff1awxy<\/a><\/p>\n

\u672c\u6587\u7531 LCTT<\/a> \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd<\/a> \u8363\u8a89\u63a8\u51fa<\/p>\n

\n

\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/linux.cn\/article-8746-1.html<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1a http:\/\/lrxjmw.cn\/ubuntu-use-docker-compose.html<\/a>\u7f16\u8f91\uff1a\u90d1\u5e05\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u5bfc\u8bfb Docker Compose \u662f\u4e00\u4e2a\u8fd0\u884c\u591a\u5bb9\u5668 Docker \u5e94\u7528\u7684\u5de5\u5177\u3002Compose \u901a\u8fc7\u4e00\u4e2a\u914d\u7f6e\u6587 […]<\/p>\n","protected":false},"author":63,"featured_media":79282,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-79271","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/79271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=79271"}],"version-history":[{"count":7,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/79271\/revisions"}],"predecessor-version":[{"id":285348,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/79271\/revisions\/285348"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/79282"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=79271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=79271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=79271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}