The context is as follows: create an image of Strapi
on GitLab
.
Please forgive me, this is one of my first approaches to Docker.
I get this error in Docker after using the following command:
docker compose build
(I did not use docker-compose build
because it is not recognised)
I attach the dockerfile:
# syntax=docker/dockerfile:1
FROM strapi/base
ARG NODE_VERSION=18.20.3
# Use node image for base image for all stages.
FROM node:${NODE_VERSION}-alpine as base
# Set working directory for all build stages.
WORKDIR /usr/src/app
FROM base as deps
RUN --mount=type=bind,source=package.json,target=package.json
--mount=type=bind,source=yarn.lock,target=yarn.lock
--mount=type=cache,target=/root/.yarn
yarn install --production --frozen-lockfile
RUN --mount=type=bind,source=package.json,target=package.json
--mount=type=bind,source=yarn.lock,target=yarn.lock
--mount=type=cache,target=/root/.yarn
yarn install --frozen-lockfile
COPY . .
RUN yarn run build
FROM base as final
ENV NODE_ENV production
USER node
COPY package.json .
# Copy the production dependencies from the deps stage and also
# the built application from the build stage into the image.
COPY --from=deps /usr/src/app/node_modules ./node_modules
COPY --from=build /usr/src/app/.strapi ./.strapi
# Expose the port that the application listens on.
EXPOSE 1337
# Run the application.
CMD yarn start
Thank you for your help.
2
Answers
OK the problem was trivial, just remove:
I don't know why I had added it.
A Dockerfile
ARG
is specific to the build stage where it’s used. Like other settings, anyARG
s get lost at the nextFROM
line.You can use
ARG
values in aFROM
line but the important trick is that you need to declare theARG
before the very firstFROM
line.(You note in your answer that the first build stage isn’t used, and deleting its
FROM
line helps. This again makes theARG
be first, so it’s visible in laterFROM
lines.)