{"id":455,"date":"2023-06-26T15:57:17","date_gmt":"2023-06-26T07:57:17","guid":{"rendered":"https:\/\/chih-hao.synology.me\/wordpress\/?p=455"},"modified":"2024-04-25T14:06:10","modified_gmt":"2024-04-25T06:06:10","slug":"ubuntu%e4%b8%ad%e5%ae%89%e8%a3%9ddocker-docker-compose","status":"publish","type":"post","link":"https:\/\/wp.chih-hao.synology.me\/?p=455","title":{"rendered":"Ubuntu\u4e2d\u5b89\u88dddocker &amp; docker-compose"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u5b89\u88dd docker &amp; docker-compose<\/h2>\n\n\n\n<p>\u4e5f\u53ef\u4ee5\u76f4\u63a5\u7528\u81ea\u52d5\u8173\u672c\u5b89\u88dd\u5982\u4e0b:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -sSL https:\/\/get.docker.com | sh\n<\/code><\/pre>\n\n\n\n<p>1.\u66f4\u65b0 Ubuntu \u5957\u4ef6\u5eab<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>sudo apt-get update<\/code><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"373\" src=\"https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-1024x373.png\" alt=\"\" class=\"wp-image-456\" srcset=\"https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-1024x373.png 1024w, https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-300x109.png 300w, https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-768x280.png 768w, https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-900x328.png 900w, https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-1280x467.png 1280w, https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image.png 1330w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>2.\u5b89\u88dd\u6240\u9700\u5957\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>sudo apt-get install apt-transport-https ca-certificates curl software-properties-common<\/code><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"594\" src=\"https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-1-1024x594.png\" alt=\"\" class=\"wp-image-457\" srcset=\"https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-1-1024x594.png 1024w, https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-1-300x174.png 300w, https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-1-768x445.png 768w, https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-1-1536x891.png 1536w, https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-1-900x522.png 900w, https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-1-1280x742.png 1280w, https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-1.png 1612w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>3.\u900f\u904e curl \u4e0b\u8f09\u5916\u90e8 docker \u4f86\u6e90\u7684\u91d1\u9470<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>wget https:\/\/download.docker.com\/linux\/ubuntu\/gpg<\/code><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"195\" src=\"https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-2-1024x195.png\" alt=\"\" class=\"wp-image-458\" srcset=\"https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-2-1024x195.png 1024w, https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-2-300x57.png 300w, https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-2-768x146.png 768w, https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-2-1536x292.png 1536w, https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-2-900x171.png 900w, https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-2-1280x243.png 1280w, https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-2.png 1815w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>4.\u4e26\u532f\u5165\u8a72\u91d1\u9470<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>sudo apt-key add gpg<\/code><\/code><\/pre>\n\n\n\n<p>5.\u5c07\u5916\u90e8\u7684&nbsp;<code>repository<\/code>&nbsp;\u4f86\u6e90\u532f\u5165<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo add-apt-repository \"deb &#91;arch=amd64] https:\/\/download.docker.com\/linux\/ubuntu bionic stable\"<\/code><\/pre>\n\n\n\n<p>6.\u63a5\u8457\u958b\u59cb\u5b89\u88ddDocker\u5957\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>sudo apt-get install docker-ce<\/code><\/code><\/pre>\n\n\n\n<p>7.\u6700\u5f8c\u52a0\u5165\u4f7f\u7528\u8005\u7684\u5e33\u865f\u9032\u5165 docker \u7fa4\u7d44<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>sudo gpasswd -a ${USER} docker<\/code><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"555\" height=\"48\" src=\"https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-3.png\" alt=\"\" class=\"wp-image-459\" srcset=\"https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-3.png 555w, https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-3-300x26.png 300w\" sizes=\"auto, (max-width: 555px) 100vw, 555px\" \/><\/figure>\n\n\n\n<p>8.\u78ba\u8a8d\u5b89\u88dd\u5f8c\u7684 Docekr \u670d\u52d9\u662f\u5426\u57f7\u884c (\u5169\u8005\u64c7\u4e00\u5373\u53ef)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>sudo service docker status<\/code><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><code>sudo systemctl status docker<\/code><\/code><\/pre>\n\n\n\n<p>9.\u6700\u5f8c\u6211\u5011\u8981\u91cd\u555f\u6211\u5011\u7684 terminal<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>bash<\/code><\/code><\/pre>\n\n\n\n<p>10.\u6e2c\u8a66docker \u5f9e docker \u7684 compose \u5c08\u6848\u62c9\u6a94\u6848\u4e0b\u4f86<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>sudo curl -L \"https:\/\/github.com\/docker\/compose\/releases\/download\/1.25.4\/docker-compose-$(uname&nbsp;-s)-$(uname -m)\" -o \/usr\/local\/bin\/docker-compose<\/code>\n\u65b0\u7248\u7684\n\nsudo curl -L \"https:\/\/github.com\/docker\/compose\/releases\/download\/v2.25.0\/docker-compose-$(uname -s)-$(uname -m)\" -o \/usr\/local\/bin\/docker-compose\n<\/code><\/pre>\n\n\n\n<p>11.\u589e\u52a0\u57f7\u884c\u6b0a\u9650<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>sudo chmod +x \/usr\/local\/bin\/docker-compose<\/code><\/code><\/pre>\n\n\n\n<p>\u5efa\u7acb PHP \u74b0\u5883<\/p>\n\n\n\n<p>1.\u958b\u65b0\u8cc7\u6599\u593e\u4e26\u65b0\u589e\u6a94\u6848\uff0c\u6a94\u6848\u540d\u7a31\u70ba&nbsp;<code>docker-compose.yml<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>nano docker-compose.yml<\/code><\/code><\/pre>\n\n\n\n<p>2.\u5728&nbsp;<code>docker-compose.yml<\/code>&nbsp;\u52a0\u5165\u4ee5\u4e0b\u8a2d\u5b9a\u6a94<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>version: \"2\"\nservices:\n    web:\n        image: php:7-apache\n        ports:\n            - \"8080:80\"\n        volumes:\n            - .\/server:\/var\/www\/html\/\nvolumes:\n    persistent:\nnetworks:\n    default:\n        driver: bridge<\/code><\/code><\/pre>\n\n\n\n<p>3.\u5728\u8cc7\u6599\u593e\u88e1\u9762\u5728\u65b0\u589e\u4e00\u500b&nbsp;<code>server<\/code>&nbsp;\u7684\u8cc7\u6599\u593e<\/p>\n\n\n\n<p>\u7db2\u7ad9\u67b6\u69cb\u76ee\u524d\u5982\u5716\u6240\u793a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"286\" height=\"123\" src=\"https:\/\/wp.chih-hao.synology.me\/wp-content\/uploads\/2023\/06\/image-4.png\" alt=\"\" class=\"wp-image-460\"\/><\/figure>\n\n\n\n<p>4.server \u8cc7\u6599\u593e\u70ba\u6211\u5011\u653e php code \u7684\u5730\u65b9<\/p>\n\n\n\n<p>\u9032\u5165&nbsp;<code>server<\/code><\/p>\n\n\n\n<p>\u65b0\u589e&nbsp;<code>phpinfo.php<\/code>&nbsp;\u7684\u6a94\u6848<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nphpinfo();\n?&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>PHP \u4e2d phpinfo() \u9019\u500b\u51fd\u5f0f\u662f PHP \u5167\u5efa\u51fd\u5f0f\uff0c\u7528\u4f86\u63d0\u4f9b\u7cfb\u7d71\u4e0a\u8207 PHP \u6709\u95dc\u7684\u8cc7\u8a0a\n<ul class=\"wp-block-list\">\n<li>PHP \u7248\u672c\uff08PHP version )<\/li>\n\n\n\n<li>\u64f4\u5c55\uff08extensions\uff09<\/li>\n\n\n\n<li>\u4f3a\u670d\u5668\u8a0a\u606f\uff08server information\uff09<\/li>\n\n\n\n<li>\u4f3a\u670d\u5668\u74b0\u5883\uff08environment\uff09<\/li>\n\n\n\n<li>\u4f5c\u696d\u7cfb\u7d71\u7248\u672c\u8cc7\u8a0a\uff08OS version information\uff09<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>7.\u56de\u5230\u4e0a\u4e00\u5c64\uff0c\u8ddf&nbsp;<code>docker-compose.yml<\/code>&nbsp;\u540c\u4e00\u5c64<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u57f7\u884c&nbsp;<code>docker-compose up -d<\/code><\/code><\/pre>\n\n\n\n<p>\u6253\u958b\u700f\u89bd\u5668 IP:8080\/phpinfo.php \u5c31\u6703\u770b\u5230 PHP \u8cc7\u8a0a<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b89\u88dd docker &amp; docker-compose&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-455","post","type-post","status-publish","format-standard","hentry","category-ubuntudocker-ubuntu"],"_links":{"self":[{"href":"https:\/\/wp.chih-hao.synology.me\/index.php?rest_route=\/wp\/v2\/posts\/455","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.chih-hao.synology.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.chih-hao.synology.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.chih-hao.synology.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.chih-hao.synology.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=455"}],"version-history":[{"count":4,"href":"https:\/\/wp.chih-hao.synology.me\/index.php?rest_route=\/wp\/v2\/posts\/455\/revisions"}],"predecessor-version":[{"id":559,"href":"https:\/\/wp.chih-hao.synology.me\/index.php?rest_route=\/wp\/v2\/posts\/455\/revisions\/559"}],"wp:attachment":[{"href":"https:\/\/wp.chih-hao.synology.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.chih-hao.synology.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.chih-hao.synology.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}