From 1dc324c35c1c9cf9b533a9e75eff8a25fda59f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E5=BA=86=E6=89=8D=E4=B8=A8=E9=9D=99=E8=A7=85?= Date: Sun, 21 Jan 2024 11:36:23 +0800 Subject: [PATCH] Add docs for docker deployment (#47) --- ...-2f6bca4c-90bc-499c-b8bc-2b9a34160987.json | 7 ++ docs/deploy/Docker.md | 109 ++++++++++++++++++ yarn.lock | 63 +--------- 3 files changed, 117 insertions(+), 62 deletions(-) create mode 100644 change/@zhishuyun-hub-2f6bca4c-90bc-499c-b8bc-2b9a34160987.json create mode 100644 docs/deploy/Docker.md diff --git a/change/@zhishuyun-hub-2f6bca4c-90bc-499c-b8bc-2b9a34160987.json b/change/@zhishuyun-hub-2f6bca4c-90bc-499c-b8bc-2b9a34160987.json new file mode 100644 index 0000000..2c41f77 --- /dev/null +++ b/change/@zhishuyun-hub-2f6bca4c-90bc-499c-b8bc-2b9a34160987.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "add docs for docker deploy", + "packageName": "@zhishuyun/hub", + "email": "cqc@cuiqingcai.com", + "dependentChangeType": "patch" +} diff --git a/docs/deploy/Docker.md b/docs/deploy/Docker.md new file mode 100644 index 0000000..93ce71e --- /dev/null +++ b/docs/deploy/Docker.md @@ -0,0 +1,109 @@ +# Docker Deployment + +## Requirements + +Install [Docker](https://www.docker.com/), to ensure you can execute `docker` command: + +``` +$ docker +Usage: docker [OPTIONS] COMMAND + +A self-sufficient runtime for containers + +Common Commands: + run Create and run a new container from an image + exec Execute a command in a running container + ps List containers + build Build an image from a Dockerfile + pull Download an image from a registry + push Upload an image to a registry +... +``` + +## Login to Docker + +Register an account in [Docker Hub](https://hub.docker.com/), then use command to login: + +``` +docker login +``` + +Then enter your username and password to login, then you will see like: + +``` +Login Succeeded +``` + +## Build with Docker + +``` +docker build -t / . +``` + +Replace `` to your username in Docker Hub, and replace `` with any name you want as the image name, like: + +``` +docker build -t foobar/hub . +``` + +Then you will see like this: + +``` +[+] Building 5.9s (8/16) docker:desktop-linux + => [build-stage 1/6] FROM docker.io/library/node:18@sha256:995a5f4314885452a4a785abc25a0fec40e26c346559e11e709d58bb7a927c 2.0s + => => resolve docker.io/library/node:18@sha256:995a5f4314885452a4a785abc25a0fec40e26c346559e11e709d58bb7a927cf4 0.0s + => => sha256:30d85599795460b2d9d24c6b87c53ec60555b601705cc83bea31632240500980 0B / 64.14MB 2.0s + => => sha256:995a5f4314885452a4a785abc25a0fec40e26c346559e11e709d58bb7a927cf4 1.21kB / 1.21kB 0.0s + => => sha256:084b3c822003a20d41f793237286e112d1b5a1c0c7b8b04cb53a17a963a76ed7 2.00kB / 2.00kB 0.0s + => => sha256:ef847f8b5ae3554df13851034f22683a8b9aef31b3659033211775d8d6cb6b79 7.34kB / 7.34kB + ... +=> [build-stage 4/6] RUN yarn 83.5s + => [build-stage 5/6] COPY . . 0.3s + => [build-stage 6/6] RUN yarn build 16.3s + => [production-stage 2/3] COPY --from=build-stage /app/dist /usr/share/nginx/html 0.0s + => [production-stage 3/3] COPY nginx.conf /etc/nginx/conf.d/default.conf 0.0s + => exporting to image 0.0s + => => exporting layers 0.0s + => => writing image sha256:f4e06895b43560b3cd43970c8942f35d56643959de5272eebee1a887a1b7798a 0.0s + => => naming to docker.io/germey/hub +``` + +## Push Docker + +``` +docker push / +``` + +Now you have pushed your image to Docker Hub, then you can deploy this image to any server. + +## Deploy Docker + +In your server machine, you can then pull this image and then run it + +``` +docker run -d -p 8000:80 / +``` + +Then visit [http://localhost:8000](http://localhost:8000) you will see it. + +## Configure HTTPS + +If you want to configure HTTPS and domain, like example.abc.com, you can install Nginx to forward the traffic from Docker: + +Apply the HTTPS cert for your domain, you will have 2 files, one is cert, the other is private key, like `example.abc.com.pem` and `example.abc.com.key`, change the nginx conf file as below: + +``` +server { + listen 443; + server_name example.abc.com; + + ssl_certificate /path/to/your/example.abc.com.pem; + ssl_certificate_key /path/to/your/example.abc.com.key; + + location / { + proxy_pass http://127.0.0.1:8000; + } +} +``` + +Also please set the Domain to server's ip address, then restart nginx, it will work. diff --git a/yarn.lock b/yarn.lock index 25c0205..2f97b5d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -390,7 +390,7 @@ resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.1.2.tgz#7c6cf998d6d20b914c0a55a91ae928ff25965e72" integrity sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw== -"@jridgewell/sourcemap-codec@^1.4.10", "@jridgewell/sourcemap-codec@^1.4.14", "@jridgewell/sourcemap-codec@^1.4.15": +"@jridgewell/sourcemap-codec@^1.4.10", "@jridgewell/sourcemap-codec@^1.4.14": version "1.4.15" resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz#d7c6e6755c78567a951e04ab52ef0fd26de59f32" integrity sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg== @@ -527,15 +527,6 @@ estree-walker "^1.0.1" picomatch "^2.2.2" -"@rollup/pluginutils@^5.0.2": - version "5.1.0" - resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-5.1.0.tgz#7e53eddc8c7f483a4ad0b94afb1f7f5fd3c771e0" - integrity sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g== - dependencies: - "@types/estree" "^1.0.0" - estree-walker "^2.0.2" - picomatch "^2.3.1" - "@trysound/sax@0.2.0": version "0.2.0" resolved "https://registry.yarnpkg.com/@trysound/sax/-/sax-0.2.0.tgz#cccaab758af56761eb7bf37af6f03f326dd798ad" @@ -546,11 +537,6 @@ resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== -"@types/estree@^1.0.0": - version "1.0.5" - resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.5.tgz#a6ce3e556e00fd9895dd872dd172ad0d4bd687f4" - integrity sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw== - "@types/json-schema@^7.0.9": version "7.0.15" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841" @@ -951,11 +937,6 @@ acorn@^7.4.0: resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa" integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A== -acorn@^8.11.2: - version "8.11.3" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.11.3.tgz#71e0b14e13a4ec160724b38fb7b0f233b1b81d7a" - integrity sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg== - acorn@^8.7.0: version "8.7.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.0.tgz#90951fde0f8f09df93549481e5fc141445b791cf" @@ -1746,11 +1727,6 @@ es-abstract@^1.19.0, es-abstract@^1.19.1: string.prototype.trimstart "^1.0.4" unbox-primitive "^1.0.1" -es-module-lexer@^1.3.0: - version "1.4.1" - resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-1.4.1.tgz#41ea21b43908fe6a287ffcbe4300f790555331f5" - integrity sha512-cXLGjP0c4T3flZJKQSuziYoq7MlT+rnvfZjfp7h+I7K9BNX54kP9nyWvdbwjQ4u1iWbOL4u96fgeZLToQlZC7w== - es-to-primitive@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/es-to-primitive/-/es-to-primitive-1.2.1.tgz#e55cd4c9cdc188bcefb03b366c736323fc5c898a" @@ -2925,13 +2901,6 @@ magic-string@^0.25.7: dependencies: sourcemap-codec "^1.4.4" -magic-string@^0.30.1: - version "0.30.5" - resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.30.5.tgz#1994d980bd1c8835dc6e78db7cbd4ae4f24746f9" - integrity sha512-7xlpfBaQaP/T6Vh8MO/EqXSW5En6INHEvEXQiuff7Gku0PWjU3uf6w/j9o7O+SpB5fOAkrI5HeoNgwjEO0pFsA== - dependencies: - "@jridgewell/sourcemap-codec" "^1.4.15" - markdown-it@^13.0.1: version "13.0.1" resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-13.0.1.tgz#c6ecc431cacf1a5da531423fc6a42807814af430" @@ -4131,26 +4100,6 @@ universalify@^2.0.0: resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717" integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ== -unplugin-element-plus@^0.8.0: - version "0.8.0" - resolved "https://registry.yarnpkg.com/unplugin-element-plus/-/unplugin-element-plus-0.8.0.tgz#320c8b43a87fe6d680b9117656476f597bccf700" - integrity sha512-jByUGY3FG2B8RJKFryqxx4eNtSTj+Hjlo8edcOdJymewndDQjThZ1pRUQHRjQsbKhTV2jEctJV7t7RJ405UL4g== - dependencies: - "@rollup/pluginutils" "^5.0.2" - es-module-lexer "^1.3.0" - magic-string "^0.30.1" - unplugin "^1.3.2" - -unplugin@^1.3.2: - version "1.6.0" - resolved "https://registry.yarnpkg.com/unplugin/-/unplugin-1.6.0.tgz#0bd7c344182c73e685c864f4f7161531f024b942" - integrity sha512-BfJEpWBu3aE/AyHx8VaNE/WgouoQxgH9baAiH82JjX8cqVyi3uJQstqwD5J+SZxIK326SZIhsSZlALXVBCknTQ== - dependencies: - acorn "^8.11.2" - chokidar "^3.5.3" - webpack-sources "^3.2.3" - webpack-virtual-modules "^0.6.1" - update-browserslist-db@^1.0.13: version "1.0.13" resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz#3c5e4f5c083661bd38ef64b6328c26ed6c8248c4" @@ -4312,16 +4261,6 @@ w3c-keyname@^2.2.4: resolved "https://registry.yarnpkg.com/w3c-keyname/-/w3c-keyname-2.2.6.tgz#8412046116bc16c5d73d4e612053ea10a189c85f" integrity sha512-f+fciywl1SJEniZHD6H+kUO8gOnwIr7f4ijKA6+ZvJFjeGi1r4PDLl53Ayud9O/rk64RqgoQine0feoeOU0kXg== -webpack-sources@^3.2.3: - version "3.2.3" - resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde" - integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w== - -webpack-virtual-modules@^0.6.1: - version "0.6.1" - resolved "https://registry.yarnpkg.com/webpack-virtual-modules/-/webpack-virtual-modules-0.6.1.tgz#ac6fdb9c5adb8caecd82ec241c9631b7a3681b6f" - integrity sha512-poXpCylU7ExuvZK8z+On3kX+S8o/2dQ/SVYueKA0D4WEMXROXgY8Ez50/bQEUmvoSMMrWcrJqCHuhAbsiwg7Dg== - which-boxed-primitive@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz#13757bc89b209b049fe5d86430e21cf40a89a8e6"