I'm new to Docker.
Can you please have a look at my scheme attached below?
What I want is to be able to have an amount of isolated docker containers with the current software onboard:
Every isolated container is linked to the same volume with the application code but is started with different ENV vars: expressJS port, db name and etc. You got me, right?
For example we have 2 isolated containers:stack1
and stack2
.
Both of them use the same volume with app code located at /home/user/app_code/ (volume mount) at the host machine.
NodeJS inside stack1
is started on 3001 port and is connected to its mongoDB server that uses DB at /home/user/db1 (volume mount) and has its dedicated storage for multimedia located at /home/user/storage1
NodeJS inside stack2
is started on 3002 port and is connected to its mongoDB server that uses DB at /home/user/db2 (volume mount) and has its dedicated storage for multimedia located at /home/user/storage2
And of course stack1
and stack2
are placed behind the Nginx single container reverse proxy.
What's the best way to implement my plan?
As I understand it docker-compose
is not the right tool in my case. In the end I can build only stack that consists if nodeJs image and Mongo image. But how to deal with ffmpeg and cron? How to multiply stacks? Is it possible to put them behind sinle Nginx container?
The second way is to take "phusion/baseimage-docker", manually install NodeJs, Mongodb, ffmpeg, multiply this container and hide each behind the Nginx revese proxy. But this approach violates a bit Best practices for writing Dockerfiles (Run only one process per container)
Or is there another proper way? How would you implement this architecture?
Thank you in advance!
It's certainly not elegant but you can do that using docker-compose. You'll just have to create copies of each service. eg:
version: "2"
services:
stack1_node:
...
stack1_mongo:
...
stack1_software:
...
stack2_node:
...
stack2_mongo:
...
stack2_software:
...
That's the short answer. The longer answer is that what you're describing is called a pod
in Kubernetes or a task
in AWS ECS. They are grouping of containers which form a unit as a whole. The new docker "swarm mode" also has the notion of task but it currently only handles one container. I have no doubt they'll extend it in the next few months to handle what you're describing. They're stealing ideas from everywhere, as they should.