skip to Main Content

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?

2

Answers


  1. Chosen as BEST ANSWER

    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
    

  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search