My Dockerfile executes RUN npm run build
command. When I execute docker build
command on t2.micro EC2 instance, instance freezes and does not respond (I cannot even connect with ssh). When I monitor the CPU usage, I can see that CPU usage reached to maximum level. Therefore, I have tried to limit memory usage with --max_semi_space_size=1
and --max_old_space_size=198
arguments but it did not work.
If I can set the CPU usage limit for the docker build command I think it might work. Can someone help me?
I'm aware that if I increase vCPU amount of the EC2 instance then I can build my application without any trouble but since it is a demo project I'm trying to deploy it on free tier.
Dockerfile:
FROM node:16-alpine
COPY . .
# Install dependencies
RUN node \
--max_semi_space_size=1 \
--max_old_space_size=198 \
$(which npm) ci
# Build the app
RUN node \
--max_semi_space_size=1 \
--max_old_space_size=198 \
$(which npm) run build
EXPOSE 3000
# Start the app
CMD [ "npx", "serve", "build" ]