【问题标题】:Building docker image of Nuxt app with https使用 https 构建 Nuxt 应用程序的 docker 镜像
【发布时间】:2021-06-05 15:51:54
【问题描述】:

最近,我刚刚更改了我的 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)

如何在不包含密钥文件的情况下对我的 Nuxt 应用程序进行 dockerize?我想在运行时使用 docker volume。

【问题讨论】:

    标签: node.js docker https nuxt.js


    【解决方案1】:

    您可以创建秘密并在图像上使用它们。这是您可以做到的方法; https://docs.docker.com/engine/reference/commandline/secret_create/

    【讨论】:

    • 我想要做的是在运行时传递密钥而不是构建时间。 docker secret 能解决这个问题吗?
    猜你喜欢
    • 2019-07-13
    • 1970-01-01
    • 1970-01-01
    • 2014-09-16
    • 1970-01-01
    • 2018-06-19
    • 2021-05-23
    • 1970-01-01
    • 2019-12-21
    相关资源
    最近更新 更多