diff --git a/Dockerfile b/Dockerfile index 95170c0..3f34d53 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,23 +4,30 @@ FROM node:16.17.0-alpine RUN mkdir -p /opt/app # 设置工作目录 WORKDIR /opt/app + # 将代码复制到容器中 -COPY . /opt/app +COPY package.json /opt/app +COPY yarn.lock /opt/app +COPY pm2.sh /opt/app RUN cd /opt/app # 添加权限,防止依赖无法安装 RUN chmod -R 777 * # 添加执行shell文件权限 RUN chmod u+x pm2.sh - RUN yarn --registry=https://registry.npm.taobao.org RUN npm i pm2 -g --registry=https://registry.npm.taobao.org +# 将代码复制到容器中 +COPY . . RUN npm run build RUN ls -l -a # 容器对外暴露的端口号,要和node项目配置的端口号一致 EXPOSE 3000 +# 修复容器外无法访问问题 +ENV NUXT_HOST=0.0.0.0 +ENV NUXT_PORT=3000 # 通过shell文件来执行多条命令 CMD ["./pm2.sh"] diff --git a/pm2.json b/pm2.json index 00a4eca..6b857ba 100644 --- a/pm2.json +++ b/pm2.json @@ -5,15 +5,15 @@ "script": "./node_modules/nuxt/bin/nuxt.js", "args": "start", "env": { - "NODE_ENV": "production", - "VUE_APP_TITLE": "production" + "NODE_ENV": "production" + }, + "env_test": { + "NODE_ENV": "test" }, "env_dev": { - "NODE_ENV": "development", - "VUE_APP_TITLE": "development" + "NODE_ENV": "development" }, "env_prod": { - "NODE_ENV": "production", - "VUE_APP_TITLE": "production" + "NODE_ENV": "production" } } diff --git a/pm2.sh b/pm2.sh index 04efa83..d27a3ca 100644 --- a/pm2.sh +++ b/pm2.sh @@ -1,3 +1,3 @@ #!/bin/sh -pm2 start pm2.json +pm2 start pm2.json --env $APP_ENV #启动pm2,$APP_ENV:docker运行时候传入的参数 pm2 logs