Replies: 4 comments 2 replies
-
It might help to describe specific issues that a monorepo presents for docker. Compose is still the right tool I think, if you want to dev in Docker. I would use the watch feature for sure, and maybe the new includes feature. Tilt (acquired by Docker) would be an option if wanting to dev in k8s. You may use Turborepo or Nx for package management. This could be a good thread to document common monorepo issues and docker-ish solutions. |
Beta Was this translation helpful? Give feedback.
-
This repo seems to get you part of the way there: https://github.com/moofoo/turbo-docker-monorepo. There is an associated blog post by the author: https://dev.to/moofoo/creating-a-development-dockerfile-and-docker-composeyml-for-yarn-122-monorepos-using-turborepo-896 But unfortunatley, there is still no way to see the changes in the shared library without rebuilding. |
Beta Was this translation helpful? Give feedback.
-
Okay I got something that is close to what I was envisioning. I'm still trying to improve it. My hope is that there are some existing tools (like turborepo) that can simplify some of it. I wanted a monorepo while still maintaining individual services. This bends the rules of what a monorepo is in a way. Because when you develop a monorepo locally, it just expects all the code to be accessible. When you have individual services, you want to isolate the code to only whats needed. Now, from a build perspective that makes sense. But I was after a "as-close-to-prod-as-possible" setup. So here is my compose file: services:
monorepo:
build:
context: .
volumes:
- monorepo:/monorepo
command: []
server:
build:
context: .
dockerfile: apps/server/Dockerfile
depends_on:
- monorepo
init: true
ports:
- "3000:3000"
command: /monorepo/node_modules/.bin/nodemon -w /monorepo/packages -w /monorepo/apps/server /monorepo/apps/server/index.js
develop:
watch:
- action: sync
path: ./apps/server
target: /monorepo/apps/server
volumes:
- monorepo:/monorepo
greet-service:
depends_on:
- monorepo
build:
context: .
dockerfile: apps/greet-service/Dockerfile
init: true
ports:
- "3001:3000"
command: /monorepo/node_modules/.bin/nodemon -w /monorepo/packages -w /monorepo/apps/greet-service /monorepo/apps/greet-service/index.js
develop:
watch:
- action: sync
path: ./apps/server
target: /monorepo/apps/server
volumes:
- monorepo:/monorepo
volumes:
monorepo: The Anyway, here is the entire project. The README is just my "steps" along the way. I did manage to put the entire monorepo into a single service (as can be seen on the https://github.com/adam-beck/my-monorepo-attempt/tree/can-i-have-individual-services-for-servers |
Beta Was this translation helpful? Give feedback.
-
Pinned. Good walkthrough of your thought process and trials! |
Beta Was this translation helpful? Give feedback.
-
One thing I haven't quite figured out how to do properly is running a development environment -- with Docker Compose -- for a monorepo that is using workspaces. It would be awesome if anybody had advice (or if this sort of setup is possible). There seems to be very little literature online about this topic. In Bret's Udemy course, there was mention of monorepos in the Q/A, but it's 3 years old and doesn't seem to solve the problem the "docker way". I would love to provide an example in this repo as well but, again, I'm not sure where to even begin.
I've been oblivious to some of the more recent changes to Docker in the last couple of years. So part of it may just be my ignorance. Lately, I've just been developing outside of containers, which never sat well with me. I'm hoping there has been some new feature that I'm missing to make this easier than it sounds like it would be.
Monorepos seem to diverge from the purpose of what a container is/does. That is, each project should be isolated. But also, for development, there needs to be a way to house the "root" workspace and inject the "packages" as well. Almost seems like it wouldn't work.
Beta Was this translation helpful? Give feedback.
All reactions