当前位置:   article > 正文

【Nuxt3学习】7. Docker部署_docker 部署nuxt3

docker 部署nuxt3

源码地址: https://github.com/xbmlz/nuxt-starter.git

修改package.json,增加start命令

{
  "private": true,
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "preview": "nuxt preview",
    "start": "node .output/server/index.mjs",
    "generate": "nuxi generate"
  },
  "dependencies": {
    "@element-plus/icons-vue": "^1.1.4",
    "@nuxtjs/axios": "^5.13.6",
    "element-plus": "^2.2.0",
    "pinia": "^2.0.14",
    "vue": "^3.2.33"
  },
  "devDependencies": {
    "@iconify/vue": "^3.2.1",
    "@pinia/nuxt": "^0.1.9",
    "@vueuse/nuxt": "^8.4.2",
    "@windicss/plugin-animations": "^1.0.9",
    "nuxt": "3.0.0-rc.3",
    "nuxt-windicss": "^2.3.1",
    "sass": "^1.51.0"
  }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

编写Docker部署脚本

新增Dockerfile文件如下

FROM node:14-alpine

RUN mkdir -p /app

WORKDIR /app

COPY package.json /app/

RUN RUN npm i --registry=https://registry.npm.taobao.org

RUN npm run build

COPY ./.output /app/.output

EXPOSE 9000

ENTRYPOINT ["npm", "run", "start"]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

新增docker-compose.yml文件如下

version: "3"
services:
  service_nuxt:
    image: nuxtapp:0.0.0 
    container_name: nuxtapp
    build:
      context: ./
    ports:
      - "3000:3000"
    environment:
      - TZ: Asia/Shanghai
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

启动容器

docker-compose up -d --build
  • 1

停止容器

docker-compose stop
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/186690
推荐阅读
相关标签
  

闽ICP备14008679号