3

I am trying to install Mezzanine on Docker to test out Docker

I've used this Container with this postgres db, with a few customizations (namely commenting out) on the Mezzanine container and using the start.sh script to include DB info.

When I run these 2 Docker commands:

docker run -P --name some_web -p 80:80 --link some_db:db myapp/mezzanine-docker
    db: docker run -d --name="some_db" -e 'PSQL_TRUST_LOCALNET=true' myapp/docker-postgresql:latest

It throws this error: Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?

Why? Just need a pointer in the right direction.

user3125823
  • 1,846
  • 2
  • 18
  • 46
  • Is the order of commands correct in your question? You should create the database container *before* the application container when you intent to link `some_db` into `some_web`. – helmbert May 04 '15 at 18:32
  • No, I didn't notice that they got flipped. I run the db command first. – user3125823 May 04 '15 at 20:20

1 Answers1

1

I agree with @helmbert because sometimes I encounter weird behavior of docker-compose. For me it seems like docker-compose can't guarantee the containers run order. So if mezzanine starts before the database initialization, it will obviously fail.

But the nature of the error that you describe suggests that your django-based application is improperly configured. Check the value of DATABASES['default']['HOST'] in settings.py, it must be equal to db.

Vitaly Isaev
  • 5,392
  • 6
  • 45
  • 64
  • "HOST" is set to 127.0.0.1, everything I've read recommend that setting. Any suggestions? – user3125823 May 04 '15 at 20:24
  • It's OK only in case if you do it on your development workstation: when both webserver and database are working on the same host - your machine. But you're trying to create a distributed web application. So you have two different virtual machines - docker containers. They should interact as a real hosts and call each other by hostname. So you have two options here: either overwrite `DATABASES['default']['HOST']` (and make it equal to `db`), either expose PostgreSQL port on host (`docker run -d -p 5432:5432 (...)`). – Vitaly Isaev May 04 '15 at 20:37
  • Ah ok, I think the light bulb went on in my head :). So then this command, docker run -P --name some_web -p 80:80 --link some_db:db myapp/mezzanine-docker, should really .... -p 5432:5432 .... ? – user3125823 May 05 '15 at 13:35
  • Did you try to fix `DATABASES['default']['HOST']` field? `127.0.0.1` value is an obvious mistake. In case if you for a some reason don't want to fix this error, you can map `postgres` container port to your host port (it should be considered as a bad design if `postgres` client are working only on the same host): 1. `docker run -d --name="some_db" -p 5432:5432 -e 'PSQL_TRUST_LOCALNET=true' myapp/docker-postgresql:latest` 2. `docker run --name some_web -p 80:80 --link some_db:db myapp/mezzanine-docker` – Vitaly Isaev May 05 '15 at 13:52
  • Yes, I fixed the HOST setting, just need to test it. I'll post the result here – user3125823 May 05 '15 at 15:11
  • I re-ran the commands with the new port and still get the same error. Should I also state 5432 in the PORT in settings.py? – user3125823 May 05 '15 at 15:39
  • I think I may have found the issue, in the postgresql.conf file - #listen_addresses = 'localhost' - that needs to get changed to #listen_addresses = '*' doesn't it? – user3125823 May 05 '15 at 15:46