Hi. I am new to Docker and came across Docker compose today.
Was just wondering how can I create app instance on server1 and database instance on server2 using docker compose ?
All the examples, i have seen till now have created the app and database on the same node. They just use different ports. I would like to know if there is any way to separate these instances.
Can anyone help me in understanding how docker is implemented in real life scenario or atleast share few resources which could help me understand the real life examples of docker ?
Pure Docker can’t do this on its own. @terpz’s suggestion of using Swarm is probably the easiest way.
Back when dinosaurs roamed the earth, Google had just announced Kubernetes 0.1, and there wasn’t docker exec yet, I did this sort of thing more manually:
ssh to the machine that will run the database server. docker run -p5432:5432 postgres (or whatever the actual database is).
ssh to the machine that will run the application. From its point of view, the first machine that you ssh’d to is running a database server; it doesn’t know or care that it’s in Docker. So now you can docker run -p 80:8080 -e PGHOST=dbhost.example.com myimage.
There are various ways to automate and script this, like using Ansible to do the “ssh to the machine and launch a Docker container” step.