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?
2
Answers
Most likely because localhost is container-based. Have you tried putting in your host’s ip address, eg:
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:
and in nginx conf file:
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.
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
worksI am assuming you will place your default.conf file inside conf.d folder
Second :-
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 phpmatestFollowing works :-
docker-compose file
default.conf