Option 1: Never install dependencies on host OS
If you’re developing in Docker, you will need to bind-mount your code from the host file system into the container so you can edit code with your host editor, but having it run on the Linux VM provided by Docker Desktop.
The big deal here is if your dependencies have compiled binaries in them, and you installed them on the host first, they’ll fail to run in Docker’s Linux if your host OS is macOS or Windows. To get around that, use docker-compose to install your dependencies before up by using:
docker-compose run <app-name> <dep install command>
Option 2: Move dependencies in image build, and hide any mounted in from host.
The other option separates your dependencies on the host from those in the image and container. It requires a little planning up front.
First, configure your image to install dependencies outside your apps working directory. Most package management systems support this option, but each one needs a different configuration to ensure it works (usually involving environment variables and updating $PATH). I often move it up a directory so it looks something like: