如何在Docker中使用distroless镜像托管Strapi而不使用npm命令?

huangapple go评论59阅读模式
英文:

How to host Strapi using distroless image in Docker without using npm command?

问题

以下是已翻译的内容:

我正在尝试在 Docker 容器中使用 distroless 镜像托管 Strapi 实例。由于我正在使用 distroless 镜像,无法使用 npm 命令来运行 Strapi。是否有一个等效的 strapi start 命令,可以纯粹使用 Node 来运行?

这是我简化后的 Dockerfile:

FROM node:16-alpine as build
# 构建步骤
# ...

FROM gcr.io/distroless/nodejs:16 as host
WORKDIR /opt/app
COPY --from=build /opt/app ./
EXPOSE 1337
CMD ["yarn", "start"]

正如我之前提到的,由于在 CMD 行中使用了 npm 命令,这个 Dockerfile 无法与 distroless 镜像一起使用。要在 distroless 镜像中使用 Strapi 而不使用 npm 命令,您需要进行以下更改。

英文:

I am trying to host a Strapi instance in a Docker container using a distroless image. As I am using a distroless image, I cannot use the npm command to run Strapi. Is there an equivalent of the strapi start command that can be run purely using Node?

Here is my summarised Dockerfile:

FROM node:16-alpine as build
# Build steps
# ...

FROM gcr.io/distroless/nodejs:16 as host
WORKDIR /opt/app
COPY --from=build /opt/app ./
EXPOSE 1337
CMD ["yarn", "start"]

As I mentioned, this Dockerfile cannot be used with a distroless image since it uses npm command in the CMD line. What changes should I make to my Dockerfile to use Strapi with a distroless image without using the npm command?

答案1

得分: 0

只替换CMD命令为您在package.json中的命令。

我会假设应该是: yarn start

CMD ["yarn", "start"]

有关CMD的参考:https://docs.docker.com/engine/reference/builder/#cmd

英文:

Just replace the CMD command with the one that you have in your package.json.

I would assume that would be: yarn start

CMD ["yarn", "start"]

For references about CMD: https://docs.docker.com/engine/reference/builder/#cmd

答案2

得分: 0

所以正确的路径是 ./node_modules/@strapi/strapi/bin/strapi.js

以下是已更新的 Dockerfile

FROM gcr.io/distroless/nodejs:16 as host
WORKDIR /opt/app
COPY --from=build /opt/app ./
EXPOSE 1337
CMD ["./node_modules/@strapi/strapi/bin/strapi.js", "start"]

请注意,在使用 distroless 时,不应该使用 alpine 构建应用程序。请使用 node 基础镜像。

FROM node:16.20 as build
英文:

So the right path is ./node_modules/@strapi/strapi/bin/strapi.js

Here's the updated Dockerfile

FROM gcr.io/distroless/nodejs:16 as host
WORKDIR /opt/app
COPY --from=build /opt/app ./
EXPOSE 1337
CMD ["./node_modules/@strapi/strapi/bin/strapi.js", "start"]

Take note that you should not use alpine to build the application when you are using distroless. Use the node base image.

FROM node:16.20 as build

huangapple
  • 本文由 发表于 2023年4月1日 00:11:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75900652.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定