Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Webpack-dev-server in docker is significantly slower than on local machine

I'm moving most of my development processes into docker to ensure a parallel development environment between computers so there are no odd bugs or issues due to version mis-match, etc.

All of this is going great, except that when running webpack-dev-server inside of docker, the build process is substantially slower than when I run it just locally on my computer. (Like 3-5 minutes in docker vs 30 seconds to 1 min locally). Is there any way to speed this up? Is it just an issue with docker/webpack interacting with a lot of files on my hard drive through a mounted volume?

If it matters, my host system is a Mac running High Sierra on an i7 with 16bg of ram.

I'm running docker for mac, docker -v returns: Docker version 17.12.0-ce, build c97c6d6

I hope all of this is clear enough, let me know if I can add any information!

like image 746
Griffin Meyer Avatar asked Mar 01 '18 22:03

Griffin Meyer


People also ask

Why is my webpack build so slow?

js ecosystem. Over the past eight years, webpack has become increasingly powerful. However, due to the additional packaging process, the building speed is getting slower as the project grows. As a result, each startup takes dozens of seconds (or minutes), followed by a round of build optimization.

Is Docker similar to webpack?

Docker belongs to "Virtual Machine Platforms & Containers" category of the tech stack, while Webpack can be primarily classified under "JS Build Tools / JS Task Runners".

How long should webpack take?

Depending on the machine on which the build was launched, it tooks between 5 and 12 minutes. It is not possible to have a build that takes so long. webpack is not a slow bundler.


2 Answers

For those in a similar spot, as Matt suggested, the issues were coming from having a mounted volume. I sped the build up significantly by using docker's volume cache mode. The docs on it are here.

The command looks something like this:

docker run -v \local\director:docker\directory:cached dockerImage

like image 66
Griffin Meyer Avatar answered Oct 26 '22 05:10

Griffin Meyer


I would recommend using delegated instead of cached as per the documentation:

Cached: The host is authoritative in this case. There may be delays before writes on a host are available to the container.

Delegated: The container is authoritative. There may be delays until updates within the container appear on the host.

So the docker-compose file would be as following:

version: '3'
services:
  front:
    container_name: my-front-dev
    image: my-front-dev-image
    build:
      context: .
      dockerfile: front/Dockerfile.dev
    ports:
      - 5002:80
    volumes:
      - ./front/:/app/:rw:delegated
like image 21
Nicolas Avatar answered Oct 26 '22 05:10

Nicolas