I’m having weird issues with my Docker builds in a monorepo setup. Sometimes the build works fine, but other times it fails randomly with COPY errors for different services.
The error I keep getting looks like this:
=> ERROR [user-service builder 3/6] COPY requirements.txt package.json* ./ 0.0s
=> CANCELED [order-service internal] load build definition from Dockerfile 0.1s
=> CANCELED [payment-service internal] load build definition from Dockerfile 0.1s
=> ERROR [notification-service internal] load build context
This happens randomly - first build might work, second fails, then third works again. I have all the config files in the right place but Docker can’t seem to find them consistently.
Here’s my docker-compose service config:
notification-service:
<<: *node-service
build:
context: .
dockerfile: ./services/notification_app/Dockerfile
ports: ["3001:3001"]
depends_on: [redis, mongodb, rabbitmq]
And my Dockerfile:
FROM node:18-alpine AS deps
WORKDIR /app
RUN npm install -g yarn
COPY requirements.txt package.json ./
RUN yarn config set network-timeout 600000 && yarn install --frozen-lockfile --production=false
FROM node:18-alpine AS runner
WORKDIR /app
RUN addgroup -g 1001 -S nodegroup && adduser -S nodeuser -u 1001
COPY --from=deps /app/node_modules ./node_modules
COPY app/ .
RUN chown -R nodeuser:nodegroup /app
USER nodeuser
EXPOSE 3001
CMD ["node", "notification_app/server.js"]
Why does this keep happening? The files are definitely there in my project structure. Any ideas how to fix this inconsistent behavior?