4
votes

I felt into issues configuring environment, containing postgres, pgadmin and nginx. All this services are in docker containers and here is my docker-compose file:

version: '3'

services:
  postgres:
    image: postgres
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres

  pgadmin:
    links:
      - postgres:postgres
    image: dpage/pgadmin4:3.0
    environment:
      PGADMIN_DEFAULT_EMAIL: '[email protected]'
      PGADMIN_DEFAULT_PASSWORD: 'postgres'
    ports:
      - "5050:80"
    restart: unless-stopped

  nginx:
    links:
      - pgadmin:pgadmin
    image: "nginx:1.13.12"
    ports:
      - "80:80"
    volumes:
      - ./nginxServers/server:/etc/nginx/conf.d/default.conf

And here is my nginx.conf, placed in ./nginxServers/server:

server {
    listen       80;
    server_name  _;

    location  /pgadmin/ {                                                                    
            proxy_pass http://pgadmin/;
    }
}

As you can see, it's a very simple setup, allowing me to use pgadmin via http://localhost/pgadmin.

Unfortunately, this doesn't work. I can see pgadmin web interface via http://127.0.0.1:5050, but when i navigate to http://127.0.0.1/pgadmin, all the styles and scripts are not loaded.

I also tried another location in nginx configuration:

location  /pgadmin {                                                                    
            proxy_pass http://pgadmin;
}

But this also didn't help.

Thus, i'm stucked with correct configuration of nginx as a reverse proxy for pgadmin.

P.S. As i've googled, this problem can be with serving django static content, but since i'm not familiar with django, i can't get any workaround.

I'll be gratefull for any help with this strange problem.

1
Have you defined any docker network? - Alejandro Galera
@AlexGalera No i didn't, as you can see, i simply use container name as host name and it works. Is this a reason of my problem? - Alex Voskresenskiy
Please, try with network: host for docker-compose, or if you launch it with docker, docker run --net=host... - Alejandro Galera
@AlexGalera So i deleted links and added network_mode: "host" and now it doesn't work at all, because nginx can't find hostname pgadmin. What did you want me to do with net=host? I'm not very good with docker-compose yet - Alex Voskresenskiy
If you launch a container with docker run --net=host option, container inherits all network configuration of the host. So, is possible to share eth interfaces, including localhost. In docker-compose, section is called: network-mode: "host". Let me post in an answer, so you can see better structured the code. - Alejandro Galera

1 Answers

2
votes

Probably you already solved it. But the problem is the way nginx resolves the hostname. It does that only once for performance reasons. To force nginx to search for the ip dynamically, just add the Docker resolver in the nginx configuration

http {
  resolver 127.0.0.11 ipv6=off;
}

see here at the bottom: docker dns server