• Vue 安装与创建第一Docker的项目


     1. 下载nodejs 并且安装

    Node.js

    2. 打开命令窗口,验证是否安装成功

    1. C:\Users\Harry>node -v
    2. v18.16.0
    3. C:\Users\Harry>npm -v
    4. 9.5.1

    3. 安装Vue CLI

    C:\Users\Harry>npm install -g @vue/cli

    经过不算漫长的等待,你的Vue CLI就装好了。确认一下:

    1. C:\Users\Harry>vue -V
    2. @vue/cli 5.0.8

    4. 新建Vue项目

    1. C:\Users\Harry>vue create hello-world-vue
    2. added 865 packages in 22s
    3. ....
    4. 🚀 Invoking generators...
    5. 📦 Installing additional dependencies...
    6. added 103 packages in 5s
    7. ....
    8. ⚓ Running completion hooks...
    9. 📄 Generating README.md...
    10. 🎉 Successfully created project hello-world-vue.
    11. 👉 Get started with the following commands:
    12. $ cd hello-world-vue
    13. $ npm run serve

    5. Build Vue项目

    1. C:\Users\Harry>cd hello-world-vue
    2. C:\Users\Harry\hello-world-vue>npm run build
    3. > hello-world-vue@0.1.0 build
    4. > vue-cli-service build
    5. All browser targets in the browserslist configuration have supported ES module.
    6. Therefore we don't build two separate bundles for differential loading.
    7. ⠏ Building for production...
    8. DONE Compiled successfully in 6786ms 10:56:49 AM
    9. File Size Gzipped
    10. dist/js/chunk-vendors.3199f451.js 74.86 KiB 28.06 KiB
    11. dist/js/app.acd4efbf.js 13.08 KiB 8.42 KiB
    12. dist/css/app.2cf79ad6.css 0.33 KiB 0.23 KiB
    13. Images and other types of assets omitted.
    14. Build at: 2023-09-16T02:56:49.159Z - Hash: ae38191f07779925 - Time: 6786ms
    15. DONE Build complete. The dist directory is ready to be deployed.
    16. INFO Check out deployment instructions at https://cli.vuejs.org/guide/deployment.html
    17. npm notice
    18. npm notice New major version of npm available! 9.5.1 -> 10.1.0
    19. npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.1.0
    20. npm notice Run npm install -g npm@10.1.0 to update!
    21. npm notice

    运行npm run build 命令后,你会看到创建的dist目录,里面包含了所有编译好的js文件。

    6. 启动Vue项目

    执行npm run serve启动项目

    1. C:\Users\Harry\hello-world-vue>npm run serve
    2. > hello-world-vue@0.1.0 serve
    3. > vue-cli-service serve
    4. INFO Starting development server...
    5. DONE Compiled successfully in 3502ms 10:59:29 AM
    6. App running at:
    7. - Local: http://localhost:8080/
    8. - Network: http://172.20.10.2:8080/
    9. Note that the development build is not optimized.
    10. To create a production build, run npm run build.

    7. 访问页面 http://localhost:8080

    8. 创建Dockerfile文件

    在项目的根目录下创建一个Dockerfile文件。

    C:\Users\Harry\hello-world-vue>touch Dockerfile

    copy 下面内容到Dockerfile文件里

    1. # Use an official Node.js runtime as a parent image
    2. FROM node:14
    3. # Set the working directory in the container
    4. WORKDIR /app
    5. # Copy package.json and package-lock.json to the working directory
    6. COPY package*.json ./
    7. # Install app dependencies
    8. RUN npm install
    9. # Copy the rest of the application code to the working directory
    10. COPY . .
    11. # Build the Vue.js app for production
    12. RUN npm run build
    13. # Expose port 80
    14. EXPOSE 80
    15. # Define the command to run the application
    16. CMD [ "npm", "run", "serve" ]

    9. 创建 Docker Image:

    用Dockerfile文件创建Docker image。

    docker build -t hello-world-vue .

    1. C:\Users\Harry\hello-world-vue>docker build -t hello-world-vue .
    2. [+] Building 94.5s (11/11) FINISHED
    3. => [internal] load build definition from Dockerfile 0.0s
    4. => => transferring dockerfile: 538B 0.0s
    5. => [internal] load .dockerignore 0.0s
    6. => => transferring context: 2B 0.0s
    7. => [internal] load metadata for docker.io/library/node:18
    8. .......
    9. => [internal] load build context 7.7s
    10. => => transferring context: 114.72MB 7.7s
    11. => [2/6] WORKDIR /app 0.4s
    12. => [3/6] COPY package*.json ./ 0.1s
    13. => [4/6] RUN npm install 11.4s
    14. => [5/6] COPY . . 1.7s
    15. => [6/6] RUN npm run build 4.2s
    16. => exporting to image 1.4s
    17. => => exporting layers 1.4s
    18. => => writing image sha256:2268a502dde3c98a590e316f25ec43f796ab5e9ac1c3af627d68bd64f19cd63a 0.0s
    19. => => naming to docker.io/library/hello-world-vue 0.0s
    20. Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them

    10. 在本地运行的docker容器

    Finally, run the Docker container based on the image you just built:

    docker run -p 8081:8080 hello-world-vue

    1. C:\Users\Harry\hello-world-vue>docker run -p 8081:8080 hello-world-vue
    2. > hello-world-vue@0.1.0 serve /app
    3. > vue-cli-service serve
    4. INFO Starting development server...
    5. DONE Compiled successfully in 1776ms3:40:01 AM
    6. App running at:
    7. - Local: http://localhost:8080/
    8. - Network: http://172.17.0.2:8080/
    9. Note that the development build is not optimized.
    10. To create a production build, run npm run build.
    11. WAIT Compiling...3:40:02 AM
    12. Compiling...
    13. DONE Compiled successfully in 54ms3:40:02 AM
    14. App running at:
    15. - Local: http://localhost:8080/
    16. - Network: http://172.17.0.2:8080/

    遇到的问题

    1. digital envelope routines::initialization error'

      opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],

      library: 'digital envelope routines',

      reason: 'unsupported',

      code: 'ERR_OSSL_EVP_UNSUPPORTED'

    解决方法:

    由于本地的node.js版本比较高,所以你要降低你的node.js版本,或者安装nvm,切换node.js版本。

    还有个方法就是设置一下环境变量。

    Linux and macOS (Windows Git Bash)-

    export NODE_OPTIONS=--openssl-legacy-provider
    

    Windows command prompt-

    set NODE_OPTIONS=--openssl-legacy-provider
    

    Windows PowerShell-

    $env:NODE_OPTIONS = "--openssl-legacy-provider"
  • 相关阅读:
    如何避免缓存穿透、缓存击穿、缓存雪崩?
    elasticsearch-5.6.15集群部署,如何部署x-pack并添加安全认证
    Presto 中orderby 算子的实现过程
    你们的优雅停机真的优雅吗?
    Kafka Stream 学习笔记-2 使用Avro 协议
    C++程序启动时报“0xC000007B”无法启动的问题排查
    【tomcat】tomcat系统架构以及核心启动流程
    微信小程序获取用户头像调整
    【论文笔记】基于生成对抗网络的强化学习算法的研究
    bat脚本学习(一)
  • 原文地址:https://blog.csdn.net/keeppractice/article/details/132915630