Tech notes/yarn run in docker

First published:

Last Edited:

Number of edits:

I wanted to build the assets for a website as part of the startup process of a django container. To speed it up, I wanted to install the dependencies during the image creation in the same way I was already doing it for the Python dependencies.

The first think I did was moving the files into the container while building the image:

COPY ./yarn.lock /yarn.lock
COPY ./package.json /package.json
RUN yarn install

And I created a start script that would run:

yarn webpack

The problem is that the node_modules folder ended up being a folder above where the project's package.json file was (in the /app directory in the container). I couldn't find a way of telling yarn where to look for the modules, so I had to force the proper webpack to run, by updated the start script to:

/node_modules/.bin/webpack --mode=production

The full example code is in this pull request.

Tags: #docker #yarn #building-assets #build-automation


These are the other notes that link to this one.

Nothing links here, how did you reach this page then?


Share your thoughts on this note
Aquiles Carattino
Aquiles Carattino
This note you are reading is part of my digital garden. Follow the links to learn more, and remember that these notes evolve over time. After all, this website is not a blog.
© 2021 Aquiles Carattino
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License
Privacy Policy