Nginx proxy manager is not being able to serve the page from another docker container - docker

I am trying for nginx proxy manager (running in a docker container) to connect to another docker container that has port 8080 open on it. When I setup the proxy to connect to 192.168.0.29:8080 the ip address of the host, but it doesn't work, the browser just says that the site didn't send any data.
I tried setting up the reverse proxy with other services (that weren't running inside a docker container), and they worked flawlessly. So, I've concluded, the problem is something with the docker containers.
First, I tried replacing the ip address with the address of the container (shown in portainer) which showed to be 172.17.0.2. But, that didn't work. I can confirm that both containers are in the same network, bridge.
I could not find any solutions for this problem either here, at Stack Overflow, or anywhere else. Hope there's enough data to solve this problem. Thanks ahead of time!
Edit:
running arp -na from within the container gives this output:
[root#docker-00244f7ab2cc:/app]# arp -na
? (172.17.0.1) at 02:42:d1:fc:fc:6b [ether] on eth0

I found the solution to my question after lots of searching and testing and it's quite simple. The solution is to start the nginx proxy manager docker container on the host network instead of the bridge network. Then, you can use localhost and then the port to refer to which service you want to redirect to.

Related

From docker container cant access 192.168.2.* network which is under VPN

The container connects to external servers and executes code there.
These external servers are behind a VPN.
From the local host I can connect to them, either by name or by direct IP.
But for some reason, to the servers in the subnet 192.168.2.* I can not connect from the container. But I can connect to subnets 192.168.123.* (also under VPN).
DNS servers are given to me through the VPN 192.168.2.1 and 192.168.123.1. I tried to assign the same DNS to the container through the key --dns, nothing changes.
Pinging by domain name server1.company.com extracts correct address 192.168.2.200 and thats all.
Does anyone have any ideas?
Answering my own question.
There's no magic here, after all.
with the command scutil --dns I found out which nameservers added by VPN and just added them to docker run ... command like:
--dns=192.168.2.1 --dns=192.168.123.1 --publish-all
and now it works fine.
PS: But I still dont have any idea how it worked before (.

Exposing a docker container to the internet

I deployed a ghost blogging platform on my server using docker. Now I want to expose it to the internet but I'm having some difficulties doing so.
I opened port 8000 in my router a forwarded it to port 32769 which is the one assign to that container. Using port 32769 inside my network I can access the website fine but when I try to access it from the internet it gives a took too long to respond error.
Local IP + PORT: http://10.0.0.140:32769/
Docker port config
Port tester
Router settings
This post was also added to Super User since it has been said that it would be responded better in there.
Let's say your application inside docker is now working on port 8000
You want to expose your application to internet.
The request would go: internet -> router -> physical computer (host machine) -> docker.
You need to export your application to your host machine, this could be done via EXPOSE 8000 instruction in Dockerfile.
That port should be accessible from your host machine first, so, when starting your docker image as docker container, you should add -p parameter, such as
sudo docker run -d -it -p 8000:8000 --name docker_contaier_name docker_image_name
From now on, your docker application can be access within your host machine, let's say it is your physical computer.
Forward port from your router to your host machine
This time, you may want to do as what you did in your question.
Access your application from internet.
If I am thinking correctly, the ip address 10.0.0.140 is just your computer LAN IP address, it cannot accessible from internet.
You can only able to connect to your app via an internet IP, to do that, you can check your router to see what is your WAN IP address, which will be assigned to your router by your internet service provider. Or go google with "what is my IP"
What works for me, more or less, is setting up Apache2 as reverse proxy, redirecting a path in Apache2 to the port of the Docker container. This probably could also be done for example with NGINX.
This way the traffic from the net gets proxied to the container and back to the net, and I see the WordPress site. So regarding the question of OP, the docker container is now exposed to the internet.
However 1: This still doesn't explain why I don't get return traffic from the Docker container if I access it directly from the net.
However 2: Not all the url's in the WordPress site are correct, but that seems to be a WordPress issue and not a Docker / routing issue.

How to Make Docker Use Specific IP Address for Browser Access from the Host

I'm using docker for building both UI and some backend microservices, and using Spring Zuul as the Proxy to pass Restful API calls from UI to the downstream microservices. My UI project needs to specify an IP address in the JS file before the build, and the Zuul project also needs to specify the IP addresses for the downstream microservices. So that after starting the containers, I can access my application using my docker machine IP http://192.168.10.1/myapp and the restful API calls in the browser network tab will be http://192.168.10.1/mymicroservices/getProduct, etc.
I can set all the IPs to my docker machine IP and build them without issues. However for my colleagues located in other countries, their docker machine IP will be different. How can I make docker use a specific IP, for example, 192.168.10.50, which I can set in the UI project and Zuul Proxy project, so that the docker IP will be the same for everyone, regardless of what their actual docker machine IP is?
What I've tried:
I've tried port forwarding in VirtualBox. It works for the UI, however the restful API calls failed.
I also tried the solution mentioned in this post:
Assign static IP to Docker container
However I can't access the services from the browser using the container IP address.
Do you have any better ideas? Thank you!
first of to clarify couple things,
If you are doin docker run ..... then you just starting container in your docker which is installed on the host machine. And there now way docker can change ip of your host machine. Thus if your other services are running somewhere else they will have to know something about docker host machine, ip or dns name.
so basically docker does runs on 127.0.0.1 if you are trying it on docker host machine, or on host machine IP if from outside of it. So docker don't need IP of host to start.
The other thing is if you are doing docker-composer up/start. Which means all services are in that docker compose file. In this case docker composer creates docker network for all containers in it. in this case you definitely can use fixed IPs for containers, though most often you don't need to because docker takes care of name resolution in that network.
if you are doing k8s way - then it is third way (production way), and it os another story.
if that is neither of above then please provide more info on how are you doing stuff.
EDIT - to:
if you are using docker composer and need to expose any of your containers to host machine you can do it through port mapping:
web:
image: some image here
ports:
- 8181:8080
left is the host machine port, right is container port
and then in browser on the host you can do request to localhost:8181
here is doc
https://docs.docker.com/compose/compose-file/#ports

Docker container DNS - Resolve URL

I have a docker container that needs to access an network server on the LAN. This server is visible from the docker host machine and I can access it from within the container when I reference the IP address directly.
However I need to be able to specify a url and port (e.g http://myserver:8080) rather than an IP address, which the docker container cannot resolve.
How can I configure the container to resolve this? ideally using the docker hosts dns. I have looked at many of the docs, but not being a DNS expert, it doesn't seem straightforward.
UPDATE:
I have tried this, which seems to work, but does this have any downsides or unintended consequences?
--network host
Thanks,
The rigth way to do this is to configure the docker daemon dns as specified under daemon-dns-options.
Using the host network is not recommended as it has some downsides https://docs.docker.com/network/host/

How to configure docker containers so that I can access them outside the host

I know many would say that this is a redundant question. But I am putting this thread as my last straw. I have gone through many threads in this community regarding my query, but was not able to achieve what I need.
Here's what I need to do.
Make docker containers such that it's IP would come in the same network as my host's. Just like a virtual machine in bridged network.
I need to be able to ssh to these dockers via external machines in my host m/c's network.
I simple replace Virtual Machines with docker in my system. And for that I need to ssh them just like I have been doing with the Virtual Machine nodes.
What I have tried?
Able to ssh the container via my host m/c. Where I installed ssh on container and enabled the port 22. Also I set UsePAM to no in /etc/ssh/sshd_config file.
Followed Ben Whaley on this thread.
I tried IP aliasing, But after all that, when I did ssh <IP address> -p 5000 , I got ssh: connect to host <IP address> port 5000: Connection refused error.
Tried to follow Regan on this page. But those documents were pulled down, and The documents that I found was not helpful either, as they were proving hard for me to understand.
Tried to make a bridge from this reference. But there too, my virtual0 bridge was not taking any IP address. If I manually give one to it, it wasn't accepting any connection through that IP.
Please can anyone help me out here?
I just need to replace my VM's with the docker containers so that I can improve my resource utilization.

Resources