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!
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.
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".
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With