Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am building a Python app and I am trying to run it inside Docker. (My works completely in virtualenv with no Docker.)

So, my app consists of config.py file and other files which make everything work, but are in this case unimportant.

My config file looks like this:

SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://gimtest:gimtest@localhost:5432/gimtest-users"

App requires postgresql to be run before the app starts, so I tried using Docker-Compose. My docker-compose.yml looks like this:

version: '2'
services:
   web:
      build: ./web
      ports:
         - "5000:5000"
      depends_on:
         - postgres
      links:
         - postgres
         - elastic
      expose:
         - 5000
      command:
         "python run.py"
   postgres:
      image: postgres:9.5
      expose:
         - 5432
      environment:
         POSTGRES_USER: "gimtest"
         POSTGRES_PASSWORD: "gimtest"
         POSTGRES_DB: "gimtest-users"

   elastic:
      image: elasticsearch:2.3

Now the problem is that I can't connect to postgresql database. (At least that's what compile says because it throws an error from python app that no postgresql is running on specified url (up in config.py).

How can I fix the url so that it will work?

share|improve this question
    
If you can manually connect to the postges db, then try add a delay to your app. – warmoverflow yesterday
    
I can't connect to docker postgres. What I can is connecting to separate psql program. The delay should be fixed with depends_on definition. Thanks for thought though. – maticzav yesterday
    
depends_on will not wait until the db is ready. See docs.docker.com/compose/startup-order You'll need to add a manual delay if db takes time to be ready. Also you db connection should be to postgres, not localhost – warmoverflow yesterday
    
Ok, I see now. I don't get the part about connecting to postgres instead of localhost... How should the URL look like then? – maticzav yesterday
1  
Just change localhost to postgres. postgres is the service name or host name for the db container. – warmoverflow yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.