Thoughts about Docker Compose environments
Docker Compose is a useful tool to decouple images and split them into components, to make them easier to read and to maintain.
However, Docker Compose environments are best used when the images coupled together don’t need to interact together at a system layer, but only at a network layer.
I’ve had the recent experience of a Node.js project that needed to interact with a Redis database, adding large amounts of data as a single action (between 300 000 and a million inserts). My instinctive thought was to decompose this project into a Node.js project image, and a Redis image, linked together through Compose. Redis has a mass insert protocol, but it is only available as a command-line tool (
cat data.txt | redis-cli --pipe) - there’s no network protocol to use it. I’ve thought of a few options, but nothing ideal:
- Make my own Redis image with an interface (poorly efficient, especially dealing with large file transfers)
- Add a
redis-cliclient to the original Node.js image (adds complexity to the image)
- Create a new interface image containing
redis-cli, serving as an interface between the Node.js image and the Redis image
- Use the
redis-streamnpm package instead of the Redis Mass Insert tool (less complex to design, but also less efficient).