Reputation: 8636
I am running 2 containers on a server. They are both docker containers with the default nginx image.
I am trying to use Container1 as a reverse proxy for Container2.
Container1 is at ip address 172.17.0.3
Container2 is at ip address 172.17.0.4
when I curl Container1 i get the default Nginx homepage.
I have edited the default homepage for container 2 so that it is just
<p> HI </p>
which is verified by a curl on the ip.
on my servers etc/hosts file, i added this line
172.17.0.3 testapp.net
My Container1's /etc/nginx/conf.d/default.conf
is this
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#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;
}
}
server {
listen 80;
server_name testapp.net;
location / {
proxy_pass http://172.17.0.4
}
}
when i do curl testapp.net
i get the home page for Container1's nginx(the basic hello nginx html file) and am not directed to Container2. Why is this happening?
Upvotes: 1
Views: 132
Reputation: 1967
So your problem is that you just modify the /etc/hosts file on your server, not that in the docker container. The container has its own file system and own network, that's why your modification does not work.
The solution is to modify the /etc/hosts on your container during docker run.
docker run --add-host testapp.net:172.17.0.3 your_image
Upvotes: 1