Flink / dokku-psql-single-container

Plugin for dokku that provides a Postgresql server in a single container
MIT License
51 stars 9 forks source link

DATABASE_URL should use symbolic hostname #4

Closed sglebs closed 9 years ago

sglebs commented 9 years ago

I have noticed that this plugin injects DATABASE_URL (nice) but with a hardcoded IP (not nice):

DATABASE_URL: postgresql://core_server:7484fa2a31bb01b29d5f274f4a559d27081d8db0f24372ddb88acb098f1a9b91@172.17.0.1:5432/co

According to "The Docker Book":

"Tip Remember how we mentioned that container IP addresses change when a container is restarted? Well since Docker version 1.3 if the linked container is restarted then the IP address in the /etc/hosts file will be updated with the new IP address."

Can't we use links and the symbolic name and therefore avoid IPs in DATABASE_URL, which would make us survive a reboot? There is a redis plugin that seems to follow this approach:

https://github.com/sekjun9878/dokku-redis-plugin/blob/master/libconfig

Search for REDIS_URL. It always injects the hostname "redis" in /etc/hosts, thanks to the way the linked container is hooked in.

According to the docker book, the hostname used is the alias for the link. Example:

sudo docker run -p 4567 --name webapp2 --link redis:db ...

So, here the "db" hostname will be injected into /etc/hosts of the container where we are hooking the link.

I will experiment with a patch for this in my PostGIS fork, ok?

Flink commented 9 years ago

Yep no problem this is also something I wanted to do, use the new docker-options plugin from dokku 0.3.17 to use real docker links between containers. But it might requires a little bit of work to do things properly (use links when running some commands for example instead of docker exec, I don’t know exactly yet).

And yes I’m aware for the redis plugin since the REDIS_URL originated from one of my PR: https://github.com/sekjun9878/dokku-redis-plugin/pull/8 :grin: :wink:

So yes very good idea :+1:

Flink commented 9 years ago

But FYI, the plugin handles restart of the PG container by exporting the new DATABASE_URL and restarting all apps using a PG database. So it’s not perfect but works. Still the link option is a better one :)

sglebs commented 9 years ago

I think the last time I restarted the VM in VirtualBox, it did not do so. I will try again sometime.

Flink commented 9 years ago

Ok then --link is now used :) I will make a 0.3.17 release!