Limit it to use only 2 CPUs and use only half of each one.
docker run -it --c 512 --cpus 2
Limit container memory
Limit the container memory to 1GB
docker run IMAGE_NAME -m 1073741824
Use another image as cache
Sometimes you are on a new machine and you don’t want your image to build from scratch. You can pull a previous image from your registry and use its cache. This will accelerate your build time and allow you to hit production as soon as possible.