1

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?

4
  • did you reload the nginx configuration before trying? Commented Apr 6, 2017 at 21:34
  • yes, i did reload the config Commented Apr 6, 2017 at 21:34
  • how did you modify the hosts file? during docker run or build? Commented Apr 6, 2017 at 21:49
  • the /etc/hosts file is on my server and I modified it after creating the 2 containers Commented Apr 6, 2017 at 22:08

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

5 Comments

When i do that, i get docker:` Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"--add-host\": executable file not found in $PATH".`
@pyjg what is your docker version?
Docker version 17.03.0-ce,
My dokcerfile is just FROM nginx:latest
@pyjg sorry, command line order is incorrect. I've modified my command, can you try it again?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.