I'm trying to set up a nginx proxy inside docker that will listen for web traffic and then based on virtualhosts forward traffic to differerat jenkins instances also running inside docker containers. To orchestrate this I use docker-compose.
I have managed to:
- Start up jenkins instances and talk to them directly
- Start nginx and configure it to act as a proxy for a webserver running on another host
But when I try to let the nginx server route the traffic inside docker I cant get it to work, just getting 502-Bag Gateway errors and the folowing in the nginx logs:
[error] 6#6: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "localhost:8080"
Relevant parts of my docker-compose.yml:
httpd:
build: httpd
ports:
- "8080:8080"
links:
- "server_jenkins"
- "clients_jenkins"
restart: always
server_jenkins:
image: jenkins
ports:
- "8081:8080"
restart: always
clients_jenkins:
image: jenkins
ports:
- "8082:8080"
restart: always
The httpd/Dockerfile looks like this:
FROM nginx
RUN rm -rf /etc/nginx
COPY config /etc/nginx/
And relevant parts of nginx.conf looks like this (only proxying one jenkins instance):
http {
server {
listen 8080;
server_name server.build.example.com;
root /tmp;
location / {
proxy_pass http://127.0.0.1:8081;
}
}
server {
listen 8080;
server_name clients.build.example.com;
root /tmp;
location / {
proxy_pass http://127.0.0.1:8082;
}
}
}
I have tried the following variants of the first proxy_pass url (and some other that I don't remember):
- http://server_jenkins:8081
- http://172.18.0.3:8081 (ip-number assigned to the server_jenkins when running with --x-networking)
When running with --x-networking I changed the link statements to container_name in docker-compose.yml
Versions:
- docker: 1.9.1, build a34a1d5
- docker-compose: 1.5.2, build 7240ff3
- OS: Debian 8 (running inside Virtualbox)