当前位置: 首页 > news >正文

next项目部署到云服务器上(手动)

准备环境:

云服务器 ECS,服务器安装好了docker

自己的next项目

开始:

1.在next项目根目录下创建Dockerfile文件

FROM node:18-alpine AS base# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \if [ -f yarn.lock ]; then yarn --frozen-lockfile; \elif [ -f package-lock.json ]; then npm ci; \elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \else echo "Lockfile not found." && exit 1; \fi# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1RUN yarn build# If using npm comment out above and use below instead
# RUN npm run build# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /appENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjsCOPY --from=builder /app/public ./public# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/staticUSER nextjsEXPOSE 3000ENV PORT 3000
# set hostname to localhost
ENV HOSTNAME "0.0.0.0"CMD ["node", "server.js"]

2.更改项目中next.config.js文件(主要是增加ouput这个)

// next.config.js
module.exports = {// ... rest of the configuration.output: 'standalone',
}

3.把项目放到云服务器上

方法多样

我是通过写完把代码push到远端gitlab后,下载了tar文件,在通过finalShell把文件手动上传到目录下的

4.解压上传的文件

切到对应的目录下(项目文件名改成自己的)

 tar -xvf international_station-master.tar

5.创建docker镜像(换成自己的项目名称,别怀疑是有. 的)

 docker build -t international_station-master .

这样就打包好了

6.docker images一下看看是否创建镜像成功

7.通过镜像创建容器,并启动

docker run -d -p 3000:3000 --name webserver international_station-master:latest 

8.如果是阿里云的话,记得把3000端口号加上安全组,然后就能通过ip:3000访问啦

http://www.lryc.cn/news/208142.html

相关文章:

  • CG Magic分享3dmax软件安装与打开文件转圈圈怎么办?
  • 京东(天猫)数据分析:2023下半年茶饮料市场高速增长,东方树叶一骑绝尘
  • 软件测试之【单元测试、系统测试、集成测试】
  • 安装 tensorflow==1.15.2 遇见的问题
  • OJ刷题 第十八篇(递归篇)
  • 互联网产品说明书指南,附撰写流程与方法
  • 从JVM方面解释java传递问题
  • Oracle查询用户所有表的语句
  • Python轮廓追踪【OpenCV形态学操作】
  • 安全狗安装
  • HTTP发起请求与收到响应的大致过程
  • c++继承的小细节
  • 【分享】7-Zip压缩包的密码可以取消吗?
  • learning rate
  • 小型气象站数据采集网关准确监测雨量和风速
  • C++常见容器实现原理
  • Mysql数据库 5.SQL语言聚合函数 语言日期-字符串函数
  • 使用Linux JumpServer 堡垒机进行远程访问
  • postgresql14管理(五)-tablespace
  • Echarts-3D柱状图
  • vue中组件传值 引用页面与组件页面绑定参数 vue省市地区街道级联选择组件
  • componentDidMount只执行一次的解决方法
  • React之diff原理
  • ElasticSearch中关于Nasted嵌套查询的介绍:生动案例,通俗易懂,彻底吸收
  • 系列二、Spring的优缺点是什么
  • ESP32网络开发实例-HTTP-GET请求
  • PHP:json_encode和json_decode用法
  • Kafka-Java二:Spring配置kafka消息发送端的缓冲区
  • 【ArcGIS模型构建器】05:批量为多个矢量数据添加相同的字段
  • 坤坤的悲伤生活