Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yarn workspaces and docker

I am trying to use yarn workspaces and then put my application into a Docker image.

The folder structure looks like this:

  • root
    • Dockerfile
    • node_modules/
      • libA --> ../libA
    • libA/
      • ...
    • app/
      • ...

Unfortunately Docker doesn't support symbolic links - therefore it is not possible to copy the node_modules-folder in the root directory into a Docker image, even if the Dockerfile is in the root as in my case.

One thing I could do would be to exclude the symlinks with .dockerignore and then copy the real directory to the image.

Another idea - which I would prefer - would be to have a tool that replaces the symlinks with the actual contents of the symlink. Do you know if there is such a tool (preferably a Javascript package)?

Thanks

like image 914
Steven Avatar asked Oct 29 '22 11:10

Steven


1 Answers

Yarn is used for dependency management, and should be configured to run within the Docker container to install the necessary dependencies, rather than copying them from your local machine.

The major benefit of Docker is that it allows you to recreate your development environment without worrying about the machine that it is running on - the same thing applies to Yarn, by running yarn install it installs the right versions for the relevant architecture of the machine your Docker image is built upon.

In your Dockerfile include the following after configuring your work directory:

RUN yarn install

Then you should be all sorted!

Another thing you should do is include the node_modules directory in your .gitignore and .dockerignore files so it is never include when distributing your code.

TL;DR: Don't copy node_modules directory from local machine, include RUN yarn install in Dockerfile

like image 149
Benjamin Scholtz Avatar answered Dec 28 '22 08:12

Benjamin Scholtz