sosedoff / pgweb

Cross-platform client for PostgreSQL databases
https://sosedoff.github.io/pgweb
MIT License
8.63k stars 732 forks source link

deploy pgweb as a container alongside postgres in a docker-compose setup? #216

Closed alexlenail closed 7 years ago

alexlenail commented 7 years ago

Hello! This looks terrific. For my use case, I'd love to run this container alongside my postgres container, link them together, and have pgweb available at some port on my URL. Is that an idea that's been had before?

alexlenail commented 7 years ago

My mistake, I didn't look closely at the wiki! https://github.com/sosedoff/pgweb/wiki/Docker This mostly answers my question. I'll try to figure the rest out on my own.

alexlenail commented 7 years ago

Okay, so I added to my docker-compose file the following:

pgweb:
  container_name: pgweb
  restart: always
  image: sosedoff/pgweb
  ports: 
    - "8081:8081" 
  links: 
    - postgres:postgres
  environment:
    - DATABASE_URL=postgres://postgres:postgres@db:5432/postgres

I have my functional postgres db in the same file

With the above, I get:

Connecting to server...
Error: dial tcp: lookup db on 192.168.65.1:53: no such host

If I change the environment line to

    - DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres

I get

Connecting to server...
Error: dial tcp 172.17.0.2:5432: getsockopt: connection refused

I changed the name just in case since my image is called postgres not db, the way you name it on the wiki https://github.com/sosedoff/pgweb/wiki/Docker

Any ideas? What's the correct DATABASE_URL? (I'm assuming that's the issue) @sosedoff

sosedoff commented 7 years ago

As far as connecting to the postgres (from pgweb) it should just work as long as the postgres server is reachable and credentials are correct (host/port/user/db). From your example its not clear how you start postgres container. Could you provide more details from your compose file?

alexlenail commented 7 years ago

Hi @sosedoff Here's the postgres piece of the compose file:

postgres:
  container_name: postgres
  restart: always
  image: postgres:latest
  volumes:
    - ./postgres-data:/var/lib/postgresql/data
  ports:
    - "5432:5432"
sosedoff commented 7 years ago

Postgres does not start right away, it takes a few seconds after start to become fully available. Since pgweb depends on the postgres container, you have to specify that in your compose file:

pgweb:
  container_name: pgweb
  restart: always
  image: sosedoff/pgweb
  ports: 
    - "8081:8081" 
  links: 
    - postgres:postgres
  environment:
    - DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres
  depends_on:
    - postgres

Also, default postgres container does not have SSL enabled, so just disable that. New variables:

DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres?sslmode=disable
alexlenail commented 7 years ago

@sosedoff that worked! Thanks so much!! Would you like to update the wiki or can I?

sosedoff commented 7 years ago

What would you like to modify in wiki?

alexlenail commented 7 years ago

Hi @sosedoff I would just add the correct docker-compose config from your last comment to the bottom of that page, just in case there's anyone out there like me who'd like to add this to their docker-compose setup. I personally think that for folks running postgres in a compose setup, plopping in pgweb if they don't already have a tool for looking through their database would be a godsend.

sosedoff commented 7 years ago

Sure, go ahead.

alexlenail commented 7 years ago

@sosedoff would you anticipate pgweb to fail if the db were too large? On a small DB, this works fine, but on my production DB I can't get pgweb to load. The log has no errors in it, the page just won't load...

sosedoff commented 7 years ago

Its hard to just guess, but you can check the request status in the chrome debug tools. Pgweb makes AJAX call for each query so you'll be able to see if anything is being returned at all.

alexlenail commented 7 years ago

nevermind I'm a moron. =)

sosedoff commented 7 years ago

Care to share a bit more info on the problem? Its always good to know what kind of stuff people do so i can work out a better ux

alexlenail commented 7 years ago

The port was closed. "Huh, that's funny, it won't load..." =)

alexlenail commented 5 years ago

Did the flag (which I have in my docker compose)

    environment:
      - DATABASE_URL=

stop working or move in a recent version of pgweb?