Docker compose, heroku, hostmane links and product

2020-03-03 05:09发布

问题:

I currently have a simple app consisting of a few micro services (database, front-end node app, user services, etc.) each with its own Dockerfile, and a docker-compose.yml file to get them all up on a local deployment environment. So everything works fine doing docker-compose up.

For production, I was looking for a Heroku (open to other PaaS), which do not support Docker Compose. Not specially nice, but could live with it for now.

The thing is that with Docker Compose on local deployment, the different services are linked via its hostname automatically (if the mongo database service is called "mydatabase", I can do mongodb://mydatabase/whatever within my other services).

So, the question is, what happens with those links on Heroku? What are the best practices to have the different services linked consistently between development and production in this case?

Thanks!

回答1:

Docker compose creates a docker virtual network which allows you to connect the containers using the container name as a hostname. Heroku doesn't directly support docker-compose, as Docker compose is really intended for local development on your own machine and not for production.

For production Docker has Docker swarm, which is very similar to Docker compose, however is intended for production environments. You can use the same docker-compose file (called stackfile in swarm) to deploy on swarm. In docker swarm, you can connect the containers that you have using the same service name just like you would do in docker-compose.

Heroku supports Docker swarm via the DockerHero add-on which you can use to to have your Docker container connected and running on Heroku.