Reputation: 438
I have a frontend-container, which builds the react-app as static files in global volume. I don't need this container after building anymore. How to delete it after docker-compose build?
Dockerfile:
FROM node:16-alpine3.12
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
COPY . .
RUN yarn build
RUN rm -rf node_modules
Upvotes: 0
Views: 1844
Reputation: 326
I would recommend that you use a multi-stage build. It works like this:
Stages 1 and 2 take place in different containers.
You should have it like this:
# Stage 1
FROM node:16-alpine3.12 as build
WORKDIR /build
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
COPY . .
RUN yarn build
RUN rm -rf node_modules
# Stage 2
FROM alpine:latest as run
WORKDIR /app
COPY --from=build /build/* .
Read more in the official documentation: https://docs.docker.com/develop/develop-images/multistage-build/
Upvotes: 1