Windows Docker === headache
To start off this adventure I reiterate that making your applications run in docker everywhere is a good thing. So the process of getting applications in docker is called dockerisation or to dockerise your apps. Or for you other English speakers dockerization and to dockerize. The reason for this is that in principle if you can run docker you can run the application. Now this is where Windows comes in.
This is where Windows comes in. Windows being the host and it being so different from OSX and GNU/Linux systems it brings it's own quirks with it when running docker on Windows. One of the things I explored in a previous post where you copy in files from Windows into the docker container and the line endings being different resulting in not working scripts. Now I will explore a small problem running a front-end application in docker and Windows.
Mounting
The concept of mounting means you have a device or folder and you want to make it available at a specific location. In most cases you would mount a hard disk or maybe a USB stick to a location you can access the folder and inspect the contents. Well you can also mount files onto a location or a whole filesystem even. When using docker you can also mount directories or files on your host system into the docker application. This creates a nice two way street of manipulating files and directories. Whatever you change on the host system will be reflected inside the docker container and vice versa.
Dependencies
In the front-end world of development dependencies are generally managed through a package.json
and a package-lock.json
, for you Yarn fanboys a yarn.lock
file. Meaning when you run your installer of choice command to install
the packages it will use these files as input and put everything in directory node_modules
. This is all fine and dandy but what I discovered is that if you mount your application's source code in the docker and therefore have docker create the node_modules
directory synced with Windows host it will go awry.
Solution
What seems to be the problem is that Windows cannot handle the vast amount of writes and operations inside the node_modules
directory. Solution is to create a volume using docker volume create
and then using that named volume as the mount for your node_modules
. Actual example for those who are using docker-compose :
volumes:
node_modules:
services:
volumes:
- node_modules:/var/www/html/node_modules
Also place this solution in a file called docker-compose.windows.yaml
. Then you only have the override for Windows and not for all other users.