1

Whenever I run,

docker-compose run --rm npm run production

Laravel mix takes around 15 minutes to complete the build. I suspect this is due to inherent slowness of Docker Desktop for Windows - I say this because even my Laravel site is loading slowly in my browser when accessed over localhost.

In order to attempt to speed up my Docker Desktop, I have created the following .wslconfig file in C:\Users<my_username>,

[wsl2] 
memory=8GB
processors=2

I am definitely using WSL version 2. Please refer: enter image description here

The following https://github.com/docker/for-win/issues/1936#issuecomment-380257581 was promising: I excluded my project files from my Norton Antivirus' "scannable" files, temporarily disabled my Antivirus. After doing all of the above, I shutdown my WSL on my Windows by using wsl --shutdown which automatically shutdown Docker Desktop. I then restarted Docker Desktop. But after all this, npm run production is still frustratingly slow in my Docker Container.

I would be grateful to understand if I am missing something.

Here is my PC config:

enter image description here

I am using Windows 10 Home.

Here is the npm snippet from my docker-compose.yml file:

npm:
    build:
      context: ./dockerfiles
      dockerfile: node.dockerfile
    container_name: npm
    volumes:
      - ./src:/var/www/html
    ports:
      - 3008:3000
      - 3009:3001
    working_dir: /var/www/html
    entrypoint: ['npm']
    networks:
      - laravel

And the contents of node.dockerfile:

FROM node:14.5.0-alpine

The site ( configured using a separate NGINX DOCKER container ) itself is slow to load, this is why I suspect that this is related to Memory size issue of Docker Desktop. But I am happy to accept counter arguments to my theory, probably this might be the result of a misconfigured npm Docker container on my local. But whatever it is, npm is taking hell lot of time to build my project (no matter what I do)!

4
  • If your Dockerfile just contains the FROM line and you're bind-mounting everything that would run inside the container, would it be easier to just run Node directly on your host? Are you hitting the problems described in docker on wsl2 very slow?
    – David Maze
    Commented May 13, 2023 at 14:36
  • This may be a personal bias, but I think the reason for the slowness is ultimately Hyper-V.
    – Charlie
    Commented May 15, 2023 at 9:13
  • In the past, when I completely disabled Hyper-V and created a virtual machine through Virtualbox to run Docker, the same specifications were several times faster than the underlying Hyper-V.
    – Charlie
    Commented May 15, 2023 at 9:13
  • But I've moved to MAC for development now so not sure if this is still the case.
    – Charlie
    Commented May 15, 2023 at 9:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.