Windows + Docker + Magento 2 + Grunt = Wasting my life

I have this very annoying habit of denying new technology. Not because I’m not a tech-savy person, not because I don’t like new stuff … it is just me. I just don’t see the benefits. Until I have to start working with it and then Hallelujah “Why didn’t I start to work with this ages ago?”. This was the issue with me and SCSS (any form of preprocessing languages), with Sublime, with Foundation (Grids and frameworks in general).

And because I acknowledge my problem I decided to stay ahead of it this time and I got me some pretty good understanding of the Docker. In fact I thought I was pretty good at it as when I spoke with some of my colleagues that I knew they were using it for quite some time, they didn’t suspect I was a newbie. So I started using it everywhere!

I’ve been also working with Magento 2 recently. So in my mind everything was clicking “I will spin off a new container, I will mount my Magento 2 installation to and I will have a Mary X-mass”. Boy, was I wrong!

Magento 2 is using symbolic links (symlinks) like a lot! A lot a lot! And Docker for Windows does not like it. It could be because I’m using 64 bit Windows 10 pro, it could be because I’m using a SSD or Hyper-V or I don’t know why .. but the fact is when I run “grunt less:<theme>” the container complains that the files inside pub/static/frontend/<Vendor>/<theme>/<locale> were ENOTEMPTY and it could not continue the process. My God … Didn’t I spend the entire day yesterday of trying to bypass/fix it.

Until I found out this gem of a comment. What I did is the following:

  • Deleted everything inside my Windows host pub/static/ folder content.
  • Attached to my container and created a new folder away from the mounted one. I mounted my code folder into /code volume so I created a new folder in /var/www/pub/static/. I don’t use apache, nor I use /var/www/ in any other way. So it is pretty safe to be there.
  • Then created a symlink for pub/static/ to poitn to /var/www/pub/static/

As far as the container is concerned the “pub/static” folder is a local for the container and not mounted one. At this point when I run grunt less:<theme> it all works as expected.

Can I have my beer now?