2

I have a few Django that I want to host on a single docker host running CentOS. I want to have 3 layers

  • network
  • application
  • database

network: I want to have an nginx container in the network layer routing requests to different containers in the application layer. I play to use 1:1 port mappings in this docker container to expose port 80 on the host to the container. Nginx will use direct request to appropriate app in the application layer running on port 8001-8010

application: Ill have several containers each running a seperate django app using Gunicorn running on port 8001-8010

database: one container running MySQL with a different database for each app. The MYSQL container will have a data volume linked to it for persistence.

I understand you can link containers. But as I understand it, I think it relies on the order in which the containers are started ie: how can you link nginx to several containers when they havent been started yet.

So my question is

  1. How do I connect the network layer to the application layer when the number/names of containers in the application is always changing. ie: I might bring a new applcation online/offline. How would I update nginx config and what would the addressing look like?

  2. How do I connect the application layer to the database layer? do I have to use Docker Linking? In my Django application code I need to use the hostname of the database to connect to. What would I put for my hostname of my docker container? Would it be able to resolve?

  3. Is there a reference architecture I could leverage?

CraigH
  • 2,041
  • 3
  • 30
  • 48

2 Answers2

0

Docker does not support dynamic linking but there are some tools that can do this for you, see this SO question.

2.) You could start you database container at first and then link all application containers to the database container. Docker will create the host file at the boot up (statically, if your database container reboots and gets another IP you need dynamlically links, see above). When you link a container like this:

-link db:db

you can access the container with the hostname db.

Community
  • 1
  • 1
joh.scheuer
  • 566
  • 3
  • 11
  • thanks, the link you provided talks about using consul or etcd. Those dont work at a OS DNS name resolution level though do they? ie: how can my nginx config file or my django connect to an etc endpoint without rewriting my code? – CraigH Dec 05 '14 at 02:21
  • Consul works with etcd https://consul.io/intro/vs/index.html . [Etcd](https://github.com/coreos/etcd) is a distributed key value store and Consule, SkyDNS etc. building a DNS on top of etcd. AkyDNS should be available for all Docker contaienr according to these statement: "We setup skydns to bind it's nameserver to the docker0 bridge so that it is available to containers." I don't know i nginx can handle this maybe you end up with these [hipache](https://github.com/hipache/hipache) or [vulcand](https://github.com/mailgun/vulcand). – joh.scheuer Dec 05 '14 at 07:53
0

I ended up using this solution:

https://github.com/blalor/docker-hosts

It allows you to have to refer to other containers on the same host by hostname. It is also dynamic as the /etc/host file on the containers gets updated dynamically as containers go up and down.

CraigH
  • 2,041
  • 3
  • 30
  • 48