最近,我刚刚更改了我的 Nuxt 应用程序,以使用如下所示的简单代码行来支持 https。
nuxt.config.js
server: {
https: {
key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
cert: fs.readFileSync(path.resolve(__dirname, 'server.cert'))
}
}
我尝试为这个应用构建 docker 镜像,当然,我已经排除了 server.key 和 server.cert。
Dockerfile
FROM node:12
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build
ENV HOST 0.0.0.0
EXPOSE 3000
CMD ["npm", "run", "start"]
出乎意料的是,构建 Nuxt 应用程序需要运行 nuxt.config.js 文件,因此它输出跟随错误。
FATAL ENOENT: no such file or directory, open '/app/server.key'
at Object.openSync (fs.js:462:3)
at Object.readFileSync (fs.js:364:35)
at nuxt.config.js:80:24
at p (node_modules/jiti/dist/jiti.js:1:9442)
at Object.loadNuxtConfig (node_modules/@nuxt/config/dist/config.js:1054:15)
at loadNuxtConfig (node_modules/@nuxt/cli/dist/cli-index.js:338:32)
at NuxtCommand.getNuxtConfig (node_modules/@nuxt/cli/dist/cli-index.js:463:26)
at Object.run (node_modules/@nuxt/cli/dist/cli-build.js:90:30)
at NuxtCommand.run (node_modules/@nuxt/cli/dist/cli-index.js:413:22)
如何在不包含密钥文件的情况下 dockerize 我的 Nuxt 应用程序?我想在运行时使用 docker volume。
您可以创建秘密并在图像上使用它们。这是您的方法; https://docs.docker.com/engine/reference/commandline/secret_create/