usgo / online-ratings

AGA Online Ratings protocol and implementation
MIT License
23 stars 12 forks source link

docker-compose not linking containers properly on Docker for Mac/VirtualBox #48

Closed brilee closed 8 years ago

brilee commented 8 years ago

Versions: docker-compose version 1.8.0, build f3628c7 docker-machine version 0.7.0, build a650a40 Docker version 1.12.0, build 8eab29e online-ratings git commit ID 60ea273 Add utility function to dump flask env

I executed:

$ docker-machine create -d virtualbox dev
$ docker-compose build && docker-compose up -d
$ docker-machine env dev
# switch docker env
$ curl -v 192.168.99.100
500 Internal Service Error...
$ docker-compose logs web
(see attached web_logs)
FATAL:  no pg_hba.conf entry for host "172.17.0.4", user "postgres", database "postgres", SSL off

The above error is rather confusing because postgres is not 172.17.0.4. 172.17.0.4 is actually the web container, and the postgres box should be at 172.17.0.3

$ docker exec -it onlineratings_web_1 bash
root@060177ce38c6:/usr/src/app# cat /etc/hosts                                                                                                                                 
127.0.0.1   localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.3  postgres_1 f851624c05f9 onlineratings_postgres_1
172.17.0.3  onlineratings_postgres_1 f851624c05f9
172.17.0.3  postgres f851624c05f9 onlineratings_postgres_1
172.17.0.4  060177ce38c6

So somehow the flask app container is not attempting to connect to the postgres container, and is falling back to trying to connect to a postgres instance within the flask container. There is no such postgres instance, and thus the stack trace in the logs.

I dumped the values in the Config object from the flask app to see what it was connecting to, and I got this: SQLALCHEMY_DATABASE_URI=postgresql://postgres:lol-change-me-plz@postgres:5432/postgres

At this point, I was stumped - the sqlalchemy database URI would seem to be pointed at postgres, but nothing is happening.

web_logs.txt

@amj @Kashomon any thoughts?

artasparks commented 8 years ago

I think perhaps this is a result of us using an old docker compose version.

From the docker docs:

Note: There are two versions of the Compose file format – version 1 (the legacy format, which does not support volumes or networks) and version 2 (the most up-to-date). For more information, see the Versioning section.

We're currently using V1. I'm a little surprised it worked previously. I'll look at updating it to V2 syntax.

artasparks commented 8 years ago

I see the volumes concept is a top-level concept. I'm less convinced this will fix it, but I'll try it anyway.

brilee commented 8 years ago

Yeah, I had noticed that the compose syntax had been updated, and thought I might try to fix it while I was undoing the .dev.yaml / .prod.yaml madness.

I first tried to update it in one go, and ran into the above issues. I figured I had made a mistake during the translation, especially because the web container had been used both as a normal container for flask, and as a volume container for nginx's static file delivery. So I made the changes to separate the volumes, while keeping the syntax in version 1, hoping that I could verify correctness and then make a straightforward literal translation to version 2. Those changes are in 6c775a4f and 3079832.

artasparks commented 8 years ago

oops. misclick