skip to Main Content

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


  1. Chosen as BEST ANSWER

    OK the problem was trivial, just remove:

    FROM strapi/base
    

    I don't know why I had added it.


  2. A Dockerfile ARG is specific to the build stage where it’s used. Like other settings, any ARGs get lost at the next FROM line.

    You can use ARG values in a FROM line but the important trick is that you need to declare the ARG before the very first FROM line.

    # syntax=docker/dockerfile:1
    
    # Must be before any FROMs
    ARG NODE_VERSION=18.20.3
    
    FROM strapi/base
    ...
    
    FROM node:${NODE_VERSION}-alpine as base
    ...
    

    (You note in your answer that the first build stage isn’t used, and deleting its FROM line helps. This again makes the ARG be first, so it’s visible in later FROM lines.)

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