4

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" ]
Hüseyin Aydın
  • 486
  • 5
  • 9

1 Answers1

0

in your system, run sudo docker info. if you get WARNING: no swap limit support, you need to manually edit grub configuration first by running sudo nano /etc/default/grub and adding the following line: GRUB_CMDLINE_LINUX="cdgroup_enable=memory swapaccount=1" and saving .

limiting cpu can then be done. for commands on limiting memory and cpu you can check this article. limit cpu and memory usage in container

Edtimer
  • 244
  • 3
  • 9
  • Does limiting cpu usage in containers also limit cpu usage of the docker build process? (I mean without docker in docker) – Matteo T. Aug 30 '23 at 07:55