{"id":442615,"date":"2026-05-04T19:50:28","date_gmt":"2026-05-04T11:50:28","guid":{"rendered":"https:\/\/idc.net\/help\/?p=442615"},"modified":"2026-04-20T19:52:36","modified_gmt":"2026-04-20T11:52:36","slug":"docker%e5%85%a5%e9%97%a8%e5%88%b0%e5%ae%9e%e6%88%98%ef%bc%9a%e5%9c%a8%e9%a6%99%e6%b8%afvps%e4%b8%8a%e5%ae%b9%e5%99%a8%e5%8c%96%e9%83%a8%e7%bd%b2%e4%bd%a0%e7%9a%84%e7%ac%ac%e4%b8%80%e4%b8%aaweb","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/442615\/","title":{"rendered":"Docker\u5165\u95e8\u5230\u5b9e\u6218\uff1a\u5728\u9999\u6e2fVPS\u4e0a\u5bb9\u5668\u5316\u90e8\u7f72\u4f60\u7684\u7b2c\u4e00\u4e2aWeb\u5e94\u7528"},"content":{"rendered":"<p>Docker \u662f\u8fd1\u5e74\u6765\u6539\u53d8\u8fd0\u7ef4\u884c\u4e1a\u7684\u6838\u5fc3\u6280\u672f\uff0c\u5b83\u8ba9\u5e94\u7528\u90e8\u7f72\u53d8\u5f97\u53ef\u91cd\u590d\u3001\u53ef\u79fb\u690d\u3001\u73af\u5883\u4e00\u81f4\u3002\u5bf9\u4e8e\u51fa\u6d77\u5efa\u7ad9\u8005\u548c\u72ec\u7acb\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u638c\u63e1 Docker \u610f\u5473\u7740\uff1a\u4e0d\u518d\u4e3a\"\u5728\u6211\u7535\u8111\u4e0a\u80fd\u8dd1\"\u70e6\u607c\u3001\u4e00\u6761\u547d\u4ee4\u90e8\u7f72\u4efb\u610f\u5e94\u7528\u3001\u8f7b\u677e\u8fc1\u79fb\u670d\u52a1\u5668\u3002\u672c\u6587\u4ece\u57fa\u7840\u6982\u5ff5\u5230\u5b9e\u6218\u90e8\u7f72\uff0c\u5e26\u4f60\u5b8c\u6210\u7b2c\u4e00\u4e2a\u5bb9\u5668\u5316 Web \u5e94\u7528\u3002<\/p>\n<hr \/>\n<h2>\u4e00\u3001\u4e3a\u4ec0\u4e48\u7528 Docker\uff1f\u548c\u4f20\u7edf\u90e8\u7f72\u65b9\u5f0f\u7684\u533a\u522b<\/h2>\n<table border=\"1\" cellpadding=\"8\" cellspacing=\"0\" style=\"border-collapse:collapse; width:100%;\">\n<thead>\n<tr style=\"background-color:#f5f5f5;\">\n<th>\u5bf9\u6bd4\u7ef4\u5ea6<\/th>\n<th>\u4f20\u7edf\u90e8\u7f72<\/th>\n<th>Docker \u90e8\u7f72<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u73af\u5883\u4f9d\u8d56<\/td>\n<td>\u9700\u8981\u5728\u6bcf\u53f0\u670d\u52a1\u5668\u624b\u52a8\u5b89\u88c5\u4f9d\u8d56<\/td>\n<td>\u4f9d\u8d56\u6253\u5305\u5728\u955c\u50cf\u4e2d\uff0c\u73af\u5883\u5b8c\u5168\u4e00\u81f4<\/td>\n<\/tr>\n<tr>\n<td>\u90e8\u7f72\u901f\u5ea6<\/td>\n<td>\u590d\u6742\uff0c\u8017\u65f6\u6570\u5c0f\u65f6<\/td>\n<td>\u4e00\u6761\u547d\u4ee4\uff0c\u79d2\u7ea7\u542f\u52a8<\/td>\n<\/tr>\n<tr>\n<td>\u8fc1\u79fb\u6210\u672c<\/td>\n<td>\u9ad8\uff0c\u9700\u8981\u91cd\u65b0\u914d\u7f6e\u73af\u5883<\/td>\n<td>\u4f4e\uff0c\u62f7\u8d1d\u955c\u50cf\u5373\u53ef\u5728\u4efb\u4f55\u673a\u5668\u8fd0\u884c<\/td>\n<\/tr>\n<tr>\n<td>\u8d44\u6e90\u9694\u79bb<\/td>\n<td>\u4e0d\u540c\u5e94\u7528\u53ef\u80fd\u51b2\u7a81<\/td>\n<td>\u6bcf\u4e2a\u5bb9\u5668\u5b8c\u5168\u9694\u79bb<\/td>\n<\/tr>\n<tr>\n<td>\u7248\u672c\u56de\u6eda<\/td>\n<td>\u7e41\u7410<\/td>\n<td>\u5207\u6362\u955c\u50cf tag \u5373\u53ef\u56de\u6eda<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h2>\u4e8c\u3001\u6838\u5fc3\u6982\u5ff5\uff1a\u955c\u50cf\u3001\u5bb9\u5668\u3001\u4ed3\u5e93<\/h2>\n<ul>\n<li><strong>\u955c\u50cf\uff08Image\uff09<\/strong>\uff1a\u5e94\u7528\u7684\"\u6a21\u677f\"\uff0c\u5305\u542b\u4ee3\u7801\u3001\u8fd0\u884c\u65f6\u3001\u4f9d\u8d56\u5e93\u3001\u914d\u7f6e\u3002\u7c7b\u6bd4\u4e3a\"\u5b89\u88c5\u5149\u76d8\"<\/li>\n<li><strong>\u5bb9\u5668\uff08Container\uff09<\/strong>\uff1a\u955c\u50cf\u8fd0\u884c\u8d77\u6765\u7684\u5b9e\u4f8b\uff0c\u662f\u771f\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\u3002\u7c7b\u6bd4\u4e3a\"\u4ece\u5149\u76d8\u5b89\u88c5\u597d\u7684\u7a0b\u5e8f\"<\/li>\n<li><strong>\u4ed3\u5e93\uff08Registry\uff09<\/strong>\uff1a\u5b58\u50a8\u548c\u5206\u53d1\u955c\u50cf\u7684\u5730\u65b9\u3002Docker Hub \u662f\u6700\u5927\u7684\u516c\u5171\u4ed3\u5e93\uff0c\u4f60\u4e5f\u53ef\u4ee5\u81ea\u5efa\u79c1\u6709\u4ed3\u5e93<\/li>\n<li><strong>Dockerfile<\/strong>\uff1a\u63cf\u8ff0\u5982\u4f55\u6784\u5efa\u955c\u50cf\u7684\u6587\u672c\u6587\u4ef6\uff0c\u7c7b\u4f3c\"\u5b89\u88c5\u8bf4\u660e\u4e66\"<\/li>\n<li><strong>Docker Compose<\/strong>\uff1a\u7528 YAML \u6587\u4ef6\u5b9a\u4e49\u548c\u8fd0\u884c\u591a\u5bb9\u5668\u5e94\u7528\uff08\u5982\u540c\u65f6\u542f\u52a8 Web + \u6570\u636e\u5e93 + Redis\uff09<\/li>\n<\/ul>\n<hr \/>\n<h2>\u4e09\u3001\u5728\u9999\u6e2f VPS \u4e0a\u5b89\u88c5 Docker<\/h2>\n<pre><code># \u66f4\u65b0\u7cfb\u7edf\r\nsudo apt update && sudo apt upgrade -y\r\n\r\n# \u5b89\u88c5 Docker \u5b98\u65b9\u4e00\u952e\u811a\u672c\r\ncurl -fsSL https:\/\/get.docker.com -o get-docker.sh\r\nsudo sh get-docker.sh\r\n\r\n# \u5c06\u5f53\u524d\u7528\u6237\u52a0\u5165 docker \u7ec4\uff08\u907f\u514d\u6bcf\u6b21\u90fd\u8981 sudo\uff09\r\nsudo usermod -aG docker $USER\r\nnewgrp docker\r\n\r\n# \u9a8c\u8bc1\u5b89\u88c5\r\ndocker --version\r\ndocker run hello-world<\/code><\/pre>\n<p>\u770b\u5230 \"Hello from Docker!\" \u8f93\u51fa\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<h3>\u5b89\u88c5 Docker Compose<\/h3>\n<pre><code>sudo apt install docker-compose-plugin -y\r\ndocker compose version<\/code><\/pre>\n<hr \/>\n<h2>\u56db\u3001\u5b9e\u6218\u4e00\uff1a\u8fd0\u884c\u4e00\u4e2a\u73b0\u6210\u7684 Nginx \u5bb9\u5668<\/h2>\n<pre><code># \u62c9\u53d6 Nginx \u5b98\u65b9\u955c\u50cf\u5e76\u8fd0\u884c\r\ndocker run -d \\\r\n  --name my-nginx \\\r\n  -p 8080:80 \\\r\n  --restart unless-stopped \\\r\n  nginx:latest<\/code><\/pre>\n<p>\u53c2\u6570\u8bf4\u660e\uff1a<\/p>\n<ul>\n<li><code>-d<\/code>\uff1a\u540e\u53f0\u8fd0\u884c<\/li>\n<li><code>--name my-nginx<\/code>\uff1a\u7ed9\u5bb9\u5668\u8d77\u4e2a\u540d\u5b57<\/li>\n<li><code>-p 8080:80<\/code>\uff1a\u5c06\u5bbf\u4e3b\u673a 8080 \u7aef\u53e3\u6620\u5c04\u5230\u5bb9\u5668 80 \u7aef\u53e3<\/li>\n<li><code>--restart unless-stopped<\/code>\uff1a\u670d\u52a1\u5668\u91cd\u542f\u540e\u81ea\u52a8\u542f\u52a8\u5bb9\u5668<\/li>\n<\/ul>\n<p>\u8fd0\u884c\u540e\uff0c\u6d4f\u89c8\u5668\u8bbf\u95ee <code>http:\/\/\u4f60\u7684VPS_IP:8080<\/code>\uff0c\u5e94\u8be5\u80fd\u770b\u5230 Nginx \u6b22\u8fce\u9875\u3002<\/p>\n<h3>\u5e38\u7528\u5bb9\u5668\u7ba1\u7406\u547d\u4ee4<\/h3>\n<pre><code>docker ps              # \u67e5\u770b\u8fd0\u884c\u4e2d\u7684\u5bb9\u5668\r\ndocker ps -a           # \u67e5\u770b\u6240\u6709\u5bb9\u5668\uff08\u5305\u62ec\u5df2\u505c\u6b62\u7684\uff09\r\ndocker logs my-nginx   # \u67e5\u770b\u5bb9\u5668\u65e5\u5fd7\r\ndocker stop my-nginx   # \u505c\u6b62\u5bb9\u5668\r\ndocker start my-nginx  # \u542f\u52a8\u5bb9\u5668\r\ndocker rm my-nginx     # \u5220\u9664\u5bb9\u5668\uff08\u9700\u5148\u505c\u6b62\uff09\r\ndocker images          # \u67e5\u770b\u672c\u5730\u955c\u50cf\u5217\u8868<\/code><\/pre>\n<hr \/>\n<h2>\u4e94\u3001\u5b9e\u6218\u4e8c\uff1a\u7528 Dockerfile \u6784\u5efa\u81ea\u5df1\u7684\u5e94\u7528\u955c\u50cf<\/h2>\n<p>\u4ee5\u4e00\u4e2a\u7b80\u5355\u7684 Node.js Express \u5e94\u7528\u4e3a\u4f8b\uff1a<\/p>\n<h3>\u9879\u76ee\u7ed3\u6784<\/h3>\n<pre><code>myapp\/\r\n\u251c\u2500\u2500 Dockerfile\r\n\u251c\u2500\u2500 package.json\r\n\u2514\u2500\u2500 app.js<\/code><\/pre>\n<h3>app.js<\/h3>\n<pre><code>const express = require('express');\r\nconst app = express();\r\n\r\napp.get('\/', (req, res) => {\r\n  res.send('Hello from Docker on HK VPS!');\r\n});\r\n\r\napp.listen(3000, () => {\r\n  console.log('Server running on port 3000');\r\n});<\/code><\/pre>\n<h3>Dockerfile<\/h3>\n<pre><code># \u4f7f\u7528\u5b98\u65b9 Node.js 18 \u7cbe\u7b80\u7248\u955c\u50cf\u4f5c\u4e3a\u57fa\u7840\r\nFROM node:18-alpine\r\n\r\n# \u8bbe\u7f6e\u5de5\u4f5c\u76ee\u5f55\r\nWORKDIR \/app\r\n\r\n# \u5148\u590d\u5236 package.json\uff0c\u5229\u7528 Docker \u5c42\u7f13\u5b58\r\nCOPY package*.json .\/\r\n\r\n# \u5b89\u88c5\u4f9d\u8d56\r\nRUN npm install --production\r\n\r\n# \u590d\u5236\u5e94\u7528\u4ee3\u7801\r\nCOPY . .\r\n\r\n# \u58f0\u660e\u5e94\u7528\u76d1\u542c\u7684\u7aef\u53e3\r\nEXPOSE 3000\r\n\r\n# \u5bb9\u5668\u542f\u52a8\u65f6\u6267\u884c\u7684\u547d\u4ee4\r\nCMD [\"node\", \"app.js\"]<\/code><\/pre>\n<h3>\u6784\u5efa\u5e76\u8fd0\u884c<\/h3>\n<pre><code># \u5728 myapp\/ \u76ee\u5f55\u4e0b\u6784\u5efa\u955c\u50cf\r\ndocker build -t myapp:v1 .\r\n\r\n# \u8fd0\u884c\u5bb9\u5668\r\ndocker run -d \\\r\n  --name myapp \\\r\n  -p 3000:3000 \\\r\n  --restart unless-stopped \\\r\n  myapp:v1\r\n\r\n# \u6d4b\u8bd5\r\ncurl http:\/\/localhost:3000<\/code><\/pre>\n<hr \/>\n<h2>\u516d\u3001\u5b9e\u6218\u4e09\uff1a\u7528 Docker Compose \u90e8\u7f72 WordPress + MySQL<\/h2>\n<p>\u521b\u5efa <code>docker-compose.yml<\/code>\uff1a<\/p>\n<pre><code>version: '3.8'\r\n\r\nservices:\r\n  db:\r\n    image: mysql:8.0\r\n    container_name: wp-mysql\r\n    restart: unless-stopped\r\n    environment:\r\n      MYSQL_ROOT_PASSWORD: your_root_password\r\n      MYSQL_DATABASE: wordpress\r\n      MYSQL_USER: wpuser\r\n      MYSQL_PASSWORD: your_wp_password\r\n    volumes:\r\n      - db_data:\/var\/lib\/mysql\r\n\r\n  wordpress:\r\n    image: wordpress:latest\r\n    container_name: wp-app\r\n    restart: unless-stopped\r\n    ports:\r\n      - \"8080:80\"\r\n    environment:\r\n      WORDPRESS_DB_HOST: db\r\n      WORDPRESS_DB_USER: wpuser\r\n      WORDPRESS_DB_PASSWORD: your_wp_password\r\n      WORDPRESS_DB_NAME: wordpress\r\n    volumes:\r\n      - wp_data:\/var\/www\/html\r\n    depends_on:\r\n      - db\r\n\r\nvolumes:\r\n  db_data:\r\n  wp_data:<\/code><\/pre>\n<pre><code># \u542f\u52a8\u6240\u6709\u670d\u52a1\r\ndocker compose up -d\r\n\r\n# \u67e5\u770b\u8fd0\u884c\u72b6\u6001\r\ndocker compose ps\r\n\r\n# \u67e5\u770b\u65e5\u5fd7\r\ndocker compose logs -f wordpress<\/code><\/pre>\n<p>\u8bbf\u95ee <code>http:\/\/\u4f60\u7684VPS_IP:8080<\/code>\uff0c\u5373\u53ef\u770b\u5230 WordPress \u5b89\u88c5\u5411\u5bfc\uff0c\u6574\u4e2a\u8fc7\u7a0b\u4e0d\u9700\u8981\u624b\u52a8\u5b89\u88c5 PHP\u3001MySQL\uff0cDocker \u81ea\u52a8\u5904\u7406\u6240\u6709\u4f9d\u8d56\u3002<\/p>\n<hr \/>\n<h2>\u4e03\u3001\u914d\u5408 Nginx \u53cd\u5411\u4ee3\u7406\u4f7f\u7528 HTTPS<\/h2>\n<p>\u901a\u5e38\u4e0d\u5efa\u8bae\u76f4\u63a5\u66b4\u9732\u5bb9\u5668\u7aef\u53e3\uff0c\u800c\u662f\u7528\u5bbf\u4e3b\u673a\u7684 Nginx \u505a\u53cd\u5411\u4ee3\u7406\uff0c\u63d0\u4f9b HTTPS \u652f\u6301\uff1a<\/p>\n<pre><code>server {\r\n    listen 80;\r\n    server_name yourdomain.com;\r\n    return 301 https:\/\/$host$request_uri;\r\n}\r\n\r\nserver {\r\n    listen 443 ssl;\r\n    server_name yourdomain.com;\r\n\r\n    ssl_certificate \/etc\/letsencrypt\/live\/yourdomain.com\/fullchain.pem;\r\n    ssl_certificate_key \/etc\/letsencrypt\/live\/yourdomain.com\/privkey.pem;\r\n\r\n    location \/ {\r\n        proxy_pass http:\/\/127.0.0.1:8080;   # \u4ee3\u7406\u5230 WordPress \u5bb9\u5668\r\n        proxy_set_header Host $host;\r\n        proxy_set_header X-Real-IP $remote_addr;\r\n        proxy_set_header X-Forwarded-Proto https;\r\n    }\r\n}<\/code><\/pre>\n<hr \/>\n<h2>\u603b\u7ed3<\/h2>\n<p>Docker \u8ba9\u670d\u52a1\u5668\u8fd0\u7ef4\u4ece\"\u624b\u5de5\u827a\"\u53d8\u6210\"\u5de5\u7a0b\u5316\"\u3002\u638c\u63e1\u672c\u6587\u7684\u57fa\u7840\u540e\uff0c\u4f60\u53ef\u4ee5\uff1a<\/p>\n<ul>\n<li>\ud83d\udc33 <strong>\u4e00\u6761\u547d\u4ee4<\/strong>\u90e8\u7f72\u4efb\u4f55\u5f00\u6e90\u5e94\u7528\uff08WordPress\u3001Ghost\u3001Nextcloud \u7b49\uff09<\/li>\n<li>\ud83d\udce6 <strong>\u6253\u5305\u81ea\u5df1\u7684\u5e94\u7528<\/strong>\uff0c\u5728\u4efb\u4f55\u670d\u52a1\u5668\u4e0a\u65e0\u7f1d\u8fd0\u884c<\/li>\n<li>\ud83d\udd04 <strong>\u8f7b\u677e\u8fc1\u79fb<\/strong>\uff1a\u6362\u670d\u52a1\u5668\u53ea\u9700\u5bfc\u51fa\u6570\u636e\u5377\uff0c\u65b0\u673a\u5668\u4e0a <code>docker compose up<\/code> \u5373\u53ef<\/li>\n<\/ul>\n<p><a href=\"https:\/\/idc.net\/cloud-hk\/\" title=\"\u9999\u6e2f\u4e91\u670d\u52a1\u5668\">\u540e\u6d6a\u4e91\u9999\u6e2f\u4e91\u670d\u52a1\u5668<\/a>\u9884\u88c5\u4e86 Ubuntu 22.04\uff0c\u5f00\u7bb1\u5373\u53ef\u5b89\u88c5 Docker\uff0c\u662f\u5b66\u4e60\u548c\u751f\u4ea7\u90e8\u7f72 Docker \u5e94\u7528\u7684\u7406\u60f3\u73af\u5883\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Docker \u662f\u8fd1\u5e74\u6765\u6539\u53d8\u8fd0\u7ef4\u884c\u4e1a\u7684\u6838\u5fc3\u6280\u672f\uff0c\u5b83\u8ba9\u5e94\u7528\u90e8\u7f72\u53d8\u5f97\u53ef\u91cd\u590d\u3001\u53ef\u79fb\u690d\u3001\u73af\u5883\u4e00\u81f4\u3002\u5bf9\u4e8e\u51fa\u6d77\u5efa\u7ad9\u8005\u548c\u72ec\u7acb\u5f00 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[202648,202757],"tags":[],"class_list":["post-442615","post","type-post","status-publish","format-standard","hentry","category-hkvps","category-docker"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/442615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=442615"}],"version-history":[{"count":1,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/442615\/revisions"}],"predecessor-version":[{"id":442616,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/442615\/revisions\/442616"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=442615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=442615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=442615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}