Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1K
Vistas
Docker-compose for mysql, phpmyadmin and nginx

I want to use a dockerized SQL database server, an additional client (here: phpmyadmin) and a reverse proxy to make the client interface reachable from outside servers.

So far I used this docker-compose file:

version: '3'

services:
        mariatest:
                image: mysql
                restart: always
                networks:
                       - dbnet
                environment:
                        MYSQL_ROOT_PASSWORD: password
                        MYSQL_DATABASE: test
                        MYSQL_USER: test
                        MYSQL_PASSWORD: test

        phpmatest:
                depends_on:
                        - mariatest
                image: phpmyadmin/phpmyadmin
                restart: always
                networks:
                        - dbnet
                ports:
                        - "9080:80"
                environment:
                        MYSQL_ROOT_PASSWORD: password
                        PMA_HOST: mariatest

        reverse:
                image: nginx
                networks:
                        - dbnet
                ports:
                        - "8000:80"
                volumes:
                        - /var/dockervolumes/nginx:/etc/nginx

networks:
     dbnet:

The taken from the volume I get the nginx default.conf file as

server {
    listen       80;
    server_name  localhost;

    location / {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://localhost:9080/;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

When using the local machine with http://localhost:9080 I can use the PMA without any problems. When trying to use the reverse proxy address (http://localhost:8000) I only get an nginx error the page I am looking for is unavailable. Inside the logs I see that the reverse proxy fails on the connect() with connection refused.

What am I missing for such setups?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Most likely because localhost is container-based. Have you tried putting in your host's ip address, eg:

proxy_pass http://[HOSTIP]:9080/;

You may need to either static your container IPs or request them by their hostname. To use DNS, set the container host name (one way is to set container_name), eg:

services:
    phpmatest:
        container_name: phpmatest

and in nginx conf file:

proxy_pass http://phpmatest:80/;

should work because they are on the same container network.

You will need to also set up nginx to receive DNS from docker, in case a container needs to restart or change. There are tutorials on how to do this elsewhere.

over 4 years ago · Santiago Trujillo Denunciar

0

Two issues with your code :

First :-

/var/dockervolumes/nginx:/etc/nginx This doesn't let nginx start inside container because nginx configuration doesn't get auto-created due to volume binding.

Try using docker ps command to verify.

Using /var/dockervolumes/nginx:/etc/nginx/conf.d works

I am assuming you will place your default.conf file inside conf.d folder

Note: If you bind any directory inside container to host system, that directory is not initialised by container.

Second :-

proxy_pass http://localhost:9080/;

You assuming that localhost inside your container and you real host is same.

Use proxy_pass http://phpmatest; that will work because your service name is phpmatest

Note: If you create a customer docker network i.e dbtest in your case. All services using same network are directly accessible by their name i.e phpmatest in your case.

Following works :-

docker-compose file

version: '3'

services:
        mariatest:
                image: mysql
                restart: always
                networks:
                       - dbnet
                environment:
                        MYSQL_ROOT_PASSWORD: password
                        MYSQL_DATABASE: test
                        MYSQL_USER: test
                        MYSQL_PASSWORD: test

        phpmatest:
                depends_on:
                        - mariatest
                image: phpmyadmin/phpmyadmin
                restart: always
                networks:
                        - dbnet
                ports:
                        - "9080:80"
                environment:
                        MYSQL_ROOT_PASSWORD: password
                        PMA_HOST: mariatest

        reverse:
                image: nginx
                networks:
                        - dbnet
                ports:
                        - "8000:80"
                volumes:
                        - /var/dockervolumes/nginx:/etc/nginx/conf.d

networks:
     dbnet:

default.conf

server {
    listen       80;
    server_name  localhost;

    location / {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://phpmatest;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda