{"id":181,"date":"2025-06-08T22:25:38","date_gmt":"2025-06-08T14:25:38","guid":{"rendered":"https:\/\/note.yuncrown.com\/?p=181"},"modified":"2025-06-13T14:18:22","modified_gmt":"2025-06-13T06:18:22","slug":"ubuntu2404-docker%e5%92%8c%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/note.yuncrown.com\/index.php\/2025\/06\/08\/ubuntu2404-docker%e5%92%8c%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e9%85%8d%e7%bd%ae\/","title":{"rendered":"ubuntu2404 docker\u5b89\u88c5\u548c\u5f00\u53d1\u73af\u5883\u914d\u7f6e"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>\u5728~\/\u76ee\u5f55\u65b0\u5efaubuntu2404 \u76ee\u5f55\u5e76\u8fdb\u5165\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir ubuntu2404 &amp;&amp; cd ubuntu2404<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7f16\u8f91dockerfile\u6587\u4ef6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>FROM ubuntu:24.04\n\nENV DEBIAN_FRONTEND=noninteractive\n\nRUN apt update &amp;&amp; apt install -y \\\n    curl wget git vim nano unzip gnupg2 ca-certificates \\\n    lsb-release software-properties-common\n\n# \u6dfb\u52a0 PHP PPA \u5e76\u5b89\u88c5 PHP 8.2 \u6838\u5fc3\nRUN add-apt-repository ppa:ondrej\/php -y &amp;&amp; \\\n    apt update &amp;&amp; apt install -y php8.2 php8.2-fpm php8.2-cli\n\n# \u5b89\u88c5 nginx\nRUN apt install -y nginx\n\nRUN apt clean &amp;&amp; rm -rf \/var\/lib\/apt\/lists\/*\n\nRUN mkdir -p \/workspace\nWORKDIR \/workspace\n\nCMD &#91;\"\/bin\/bash\"]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7f16\u8f91docker-compose.yml\u6587\u4ef6\uff08\u65b9\u4fbf\u5bb9\u5668\u6302\u8f7d\u5bbf\u4e3b\u673a\u76ee\u5f55\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>services:\n  ubuntu2404:                                  # \u5b9a\u4e49\u670d\u52a1\u540d\u4e3a ubuntu2404\n    build: .                                   # \u4f7f\u7528\u5f53\u524d\u76ee\u5f55\u7684 Dockerfile \u6784\u5efa\u955c\u50cf\n    image: ubuntu2404                          # \u8bbe\u7f6e\u955c\u50cf\u540d\n    container_name: ubuntu2404                 # \u5bb9\u5668\u540d\u79f0\u4e3a ubuntu2404\uff0c\u65b9\u4fbf\u7ba1\u7406\n    user: \"1000:1000\"                          # \u5bb9\u5668\u5185\u8fd0\u884c\u7528\u6237\u7684uid\u548cgid\n    volumes:\n      - .\/code:\/workspace                                 # \u5bbf\u4e3b\u673a .\/code \u76ee\u5f55\u6302\u8f7d\u5230\u5bb9\u5668 \/workspace\n      - .\/code\/nginx\/conf.d:\/etc\/nginx\/conf.d             # \u6302\u8f7dnginx\u7ad9\u70b9\u914d\u7f6e\u6587\u4ef6\n      - .\/code\/php\/php82\/php.ini:\/etc\/php\/8.2\/cli\/php.ini # \u6302\u8f7dphp\u7ad9\u70b9\u914d\u7f6e\u6587\u4ef6\n    ports:\n      - \"80:80\"                                # \u5bbf\u4e3b\u673a80\u7aef\u53e3\u6620\u5c04\u5230\u5bb9\u566880\u7aef\u53e3\uff08nginx\u9ed8\u8ba4\u7aef\u53e3\uff09\n      - \"9000:9000\"                            # \u5bbf\u4e3b\u673a9000\u7aef\u53e3\u6620\u5c04\u5230\u5bb9\u56689000\u7aef\u53e3\uff08php-fpm\u9ed8\u8ba4\u7aef\u53e3\uff09\n    stdin_open: true                           # \u4fdd\u6301STDIN\u6253\u5f00\uff0c\u65b9\u4fbf\u4ea4\u4e92\u64cd\u4f5c\n    tty: true                                  # \u5206\u914d\u4f2a\u7ec8\u7aef\uff0c\u652f\u6301\u7ec8\u7aef\u989c\u8272\u548c\u4ea4\u4e92<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4fee\u6539docker-compose.yml\u6587\u4ef6\u540e\u91cd\u6784\u5bb9\u5668<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u505c\u6b62\u5e76\u5220\u9664 \u5f53\u524d\u76ee\u5f55\u4e0b\u7531\u8be5 docker-compose.yml \u7ba1\u7406\u7684\u6240\u6709\u5bb9\u5668\u3001\u7f51\u7edc\u548c\u9ed8\u8ba4\u5377\ndocker compose down\n# \u91cd\u65b0\u542f\u52a8\u5bb9\u5668\u5e76\u751f\u6548\u6302\u8f7d\u76ee\u5f55\ndocker compose up -d<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6784\u5efa\u955c\u50cf\u5e76\u542f\u52a8\u5bb9\u5668\uff08\u57fa\u4e8edocker-compose.yml<\/strong>\u6587\u4ef6<strong>\uff09<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u52a0\u4e0a -d \u53c2\u6570\uff0c\u8ba9\u5bb9\u5668\u5728\u540e\u53f0\u8fd0\u884c\uff08detached mode\uff09\ndocker compose up -d --build\n\ndocker compose up\t    # \u542f\u52a8\u5bb9\u5668\uff0c\u4e0d\u91cd\u5efa\u955c\u50cf\uff08\u9664\u975e\u955c\u50cf\u4e0d\u5b58\u5728\uff09\ndocker compose build\t    # \u5355\u72ec\u6784\u5efa\u955c\u50cf\uff0c\u4e0d\u542f\u52a8\u5bb9\u5668\ndocker compose up --build   # \u6784\u5efa\u955c\u50cf \u5e76 \u542f\u52a8\u5bb9\u5668\uff08\u63a8\u8350\u7528\u4e8e\u5f00\u53d1\uff09<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6784\u5efa\u955c\u50cf\uff08build\uff09\uff08\u57fa\u4e8edockerfile\u6587\u4ef6\uff09<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker build -t ubuntu2404 .<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u542f\u52a8\u5bb9\u5668<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u5bb9\u5668\u542f\u52a8\u540e\uff0c\u4f1a\u8fdb\u5165\u4ea4\u4e92\u5f0f\u7ec8\u7aef\uff08bash\uff09\ndocker run -it --name ubuntu2404 -p 80:80 ubuntu2404<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8fdb\u5165\u548c\u9000\u51fa\u5bb9\u5668<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u8fdb\u5165\ndocker exec -it ubuntu2404 bash\n# \u4f7f\u7528root\u7528\u6237\u8fdb\u5165\ndocker exec -it -u root ubuntu2404 bash\n# \u9000\u51fa\nctrl + P + Q\n# \u6216\uff08\u8fd0\u884c\u65f6\u52a0-d\u53c2\u6570\u7684\u60c5\u51b5\u4e0b\uff0cdocker\u4f1a\u5728\u540e\u53f0\u8fd0\u884c\uff0c ctrl + D\u4e0d\u4f1a\u4f7f\u5bb9\u5668\u505c\u6b62\uff09\nctrl + D<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5220\u9664\u5bb9\u5668\u548c\u955c\u50cf<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u67e5\u770b\u5bb9\u5668\u540d\u6216ID\ndocker ps -a\n# \u505c\u6b62\u5bb9\u5668\ndocker stop \u5bb9\u5668\u540d\u6216ID\n# \u5220\u9664\u5bb9\u5668\ndocker rm \u5bb9\u5668\u540d\u6216ID\n# \u67e5\u770b\u955c\u50cf\ndocker images\n# \u5220\u9664\u955c\u50cf\ndocker rmi \u955c\u50cfID\n# \u5220\u9664\u6240\u6709\u6ca1\u6709\u88ab\u5bb9\u5668\u4f7f\u7528\u7684\u955c\u50cf\ndocker image prune -a<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5220\u9664\u672a\u4f7f\u7528\u7684\u955c\u50cf\u3001\u5bb9\u5668\u3001\u7f51\u7edc\u3001\u7f13\u5b58<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u4f1a\u6e05\u7406\uff1a\u505c\u6b62\u7684\u5bb9\u5668\uff0c\u672a\u6253 tag \u7684\u955c\u50cf\uff0c\u672a\u4f7f\u7528\u7684\u7f51\u7edc\uff0c\u6784\u5efa\u7f13\u5b58\ndocker system prune\n# \u52a0 -a \u4f1a\u5220\u9664\u6240\u6709\u672a\u4f7f\u7528\u7684\u955c\u50cf\uff08\u614e\u7528\uff09\ndocker system prune -a\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b89\u88c5php\u5e38\u7528\u6269\u5c55<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u5b89\u88c5pdo_mysql\napt update &amp;&amp; apt install -y php8.2-mysql\n# \u5b89\u88c5\u5b8c\u4e86\u91cd\u542fphp\nservice php8.2-fpm restart<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5176\u4ed6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u542f\u52a8nginx\nnginx\n# \u542f\u52a8php\nphp-fpm8.2\n# \u91cd\u542fnginx\nnginx -s reload<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728~\/\u76ee\u5f55\u65b0\u5efaubuntu2404 \u76ee\u5f55\u5e76\u8fdb\u5165\uff1a \u7f16\u8f91dockerfile\u6587\u4ef6\uff1a \u7f16\u8f91docker-compo [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-181","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/posts\/181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/comments?post=181"}],"version-history":[{"count":34,"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/posts\/181\/revisions"}],"predecessor-version":[{"id":245,"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/posts\/181\/revisions\/245"}],"wp:attachment":[{"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/media?parent=181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/categories?post=181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/note.yuncrown.com\/index.php\/wp-json\/wp\/v2\/tags?post=181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}