View profile

DevOps and Docker Updates - Code Dependencies in Dev

My Node.js post is up on Docker's blog, but much of it is applicable to other languages too, so here'
DevOps and Docker Updates - Code Dependencies in Dev
By Bret Fisher • Issue #8 • View online
My Node.js post is up on Docker’s blog, but much of it is applicable to other languages too, so here’s one topic that I’ve made “language independent” for you: app dependency management in subdirectories

Foxy is my new mascot for my courses, because everything needs a mascot!
Foxy is my new mascot for my courses, because everything needs a mascot!
Where To Put Your Dependencies for Cross-OS Development
It might be npm, yarn, composer, bundler, pip, bower, webpack, or others… but the same issue usually exists:
How do you configure Docker when your binary dependencies are a sub directory of your code, and your host OS and Docker OS are different?
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:
source code is copied into ./app/src but dependencies go in dep
source code is copied into ./app/src but dependencies go in dep
Then in your docker-compose, you need to ensure any dependencies that are bind-mounted in with your source code are hidden inside the container. This can be done by adding a volume that mounts the dep directory to an empty tmp volume, like:
I hope that helps you rethink your dev setup to be optimum for Docker, and be sure to skim the Docker blog post for other topics from my Node.js course that are likely applicable to your apps, even if not using node.
See ya next week,
Bret
Did you enjoy this issue?
Bret Fisher

Frequent updates on my projects, videos, and opinions focused on the container ecosystem, including Docker, Kubernetes, Docker Swarm, CI/CD, and container DevOps.

If you don't want these updates anymore, please unsubscribe here
If you were forwarded this newsletter and you like it, you can subscribe here
Powered by Revue
Bret Fisher, Virginia Beach, Virginia, USA