Docker: How to connect to locally available servers from within docker - docker

I run docker on windows. I have a docker container running a python application that needs a database connection.
Installing a DB on my machine and connecting to it via "docker.for.win.localhost" in my container works fine.
Now I want to connect to a database running on a server that is available over my local network. I can't seem to connect to it from inside my docker container. I don't quite understand how I can proxy the server to my container. The error indicates that it can't establish a connection to this server:
(psycopg2.OperationalError) could not connect to server: No route to host
Is the server running on host "XX.XXX.XX.XX" and accepting
TCP/IP connections on port 5555?
I'm sure this is supposed to work somehow, right?

you can add IP of host to the container
docker run --add-host="yourhost:IPOFTHEHOST"
and yourhost will be connected to host

Related

connect ECONNREFUSED 127.0.0.1:8046 when connecting to host app from Docker container - Windows 10

I have a standalone app running on my machine (not in a docker container) listening to port 8046 (localhost:8046) using an ngrok tunnel (http ngrok 8046). I am trying to connect to it sending a POST from my docker container which I'm also running on my local machine using http://host.docker.internal:8046. I have tried many different approaches but nothing seems to work:
I have tried to disable my firewall to make sure that wasn't the issue.
Tried http://localhost:8046 in the container to connect to the app
Tried serving the standalone app on 0.0.0.0 with the same port 8046 and setting http://0.0.0.0:8046 in the container to connect to it, unsuccessfully
I keep having connect ECONNREFUSED 127.0.0.1:8046
my etc/hosts is configured with the IP added by docker desktop for host.docker.internal and gateway.docker.internal
I'm running out of ideas and can't figure out what I could be missing. Any ideas? Thanks in advance
Inside container localhost, 127.0.0.1, 0.0.0.0 represent the container itself. To connect to the host machine please try using its domain name or IP address in the LAN, which the host machine belongs to.

docker containerized zabbix server monitoring same host running the zabbix server : connection refused

I m running a dockerized version of zabbix server (centos 6.0) on my host. I m also running zabbix-agent2 on this host with configuration of server with ip adress of 127.0.0.1.
When i go into zabbix frontend web interface i get these error on the detected host:
When the ip is at default value 127.0.0.1:10050:
Get value from agent failed: cannot connect to [[127.0.0.1]:10050]: [111] Connection refused
When i change the default value to 172.17.0.1:10050 (the docker cant identify localhost of the host naturally) :
Get value from agent failed: ZBX_TCP_READ() failed: [104] Connection reset by peer
When i go to host and i ping or traceroute the host it works well.
When i go to host and i try detect operating system i get the error
Cannot execute script.
sh: sudo: command not found
What can i do to make the host work properly?
I have tried to check these posts :
Access localhost from docker container
(when i use 172.17.0.1).
I have tried to use network_mode: host but it conflicts with network being defined in the docker-compose.yml
I have tried this solution How to use the host network, and any other user-defined network together in Docker-Compose?
but it doesnt work either
The port of the docker-compose is well defined and mapped (10051:10051)

I want to connect a Docker Superset container to an existing external MySQL database

I am trying to add an existing MySQL database as a source database to a docker container running Apache Superset. The MySQL database that I am trying to add is not running in a docker container. It's an existing MySQL database running on a Windows machine.
I've added mysqlclient==1.4.6 to requirements.txt. The error message seems to indicate that the driver is installed.
I've used mysql://user:password#127.0.0.1:3306/database_name and mysql://user:password#localhost:3306/database_name
The error I get is:
"ERROR: Connection failed, please check your connection settings."
I am using image: apache / 'incubator-superset' v. 0.36.0
Are there any settings or config that needs to be changed to be able to communicate to an external database from within a running docker container?
So I figured it out. For Windows, run ipconfig (maybe ifconfig linux, mac) in terminal/powershell and check what ip address docker ethernet port is using (listed as WSL), let's say ip is: 172.x(x).x(x).x(x). Then configure connection string with ip address on docker ethernet port as follows: 'mysql://user:password#172.x(x).x(x).x(x):3306/database_name'.
Follow-up question if anybody knows: How can I connect my docker container running apache/superset to another server/ip address on my local network running a MySQL server? In other words I want to connect the apache/superset app that is running on my computer in a docker container, to another computer on my local network that is running a MySQL server. The MySQL sever is not in a docker container.
maybe the steps of this blog can help.
If your mysql is in other docker it it is not 127.0.0.1 and in addition if you don't want the requirements to be updated every time that you git pull a new docker, it is better to use the requirements-local.txt
You should be able to do that but your MySQL has to have external IP that you can access from your Supserset Machine. First do a telnet to see if you can listen from port 3306 to that machine and if you can Supserset should work with very similar URI that you have.

gRPC in docker container can't connect to services on host machine

I have slightly modified this example: https://github.com/grpc/grpc-web/tree/master/net/grpc/gateway/examples/echo. I am running envoy on a docker container with exposed port 8080 (running this proxy server is required because the browser can't speak directly to a backend gRPC service). I am running all the services on my localhost (the host machine of the envoy docker container). However, I cannot seem to connect envoy in the docker container to the services running on the host machine.
I compiled grpc_cli in the container and when I run grpc_cli ls 192.168.1.10:9000 (host's LAN IP address and the port the service is running on), I get
root#bdc9ac396a87:~/grpc# ./bins/opt/grpc_cli ls 192.168.1.10:9000
Received an error when querying services endpoint.
ServerReflectionInfo rpc failed. Error code: 14, message: failed to connect to all addresses, debug info: {"created":"#1569023274.866465052","description":"Failed to pick subchannel","file"
:"src/core/ext/filters/client_channel/client_channel.cc","file_line":3876,"referenced_errors":[{"created":"#1569023274.866463178","description":"failed to connect to all addresses","file":"
src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":395,"grpc_status":14}]}
I get an almost identical error when I use the IP address of the docker0 interface, which should also provide a connection to the host machine.
root#bdc9ac396a87:~/grpc# ./bins/opt/grpc_cli ls 172.17.0.1:9000
Received an error when querying services endpoint.
ServerReflectionInfo rpc failed. Error code: 14, message: failed to connect to all addresses, debug info: {"created":"#1569022455.801913949","description":"Failed to pick subchannel","file"
:"src/core/ext/filters/client_channel/client_channel.cc","file_line":3876,"referenced_errors":[{"created":"#1569022455.801910006","description":"failed to connect to all addresses","file":"
src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":395,"grpc_status":14}]}
However, running a simple http server from the host with
python -m http.server
I can run the following commands from the container just fine:
wget 172.17.0.1:8000/test.txt // works
wget 192.168.1.10:8000/test.txt // works
A client on the host (not in the container) connects and works just fine with the service, so it's not a server problem.
Does docker block certain types of traffic? I noticed in the example the server was placed on another docker container, and it worked (it also worked locally for me), but I'd prefer to have my services running on my host machine while I build and test them. Is there a setting somewhere to enable gRPC from the container to a service on the host machine?
Docker version 1.13.1, build 47e2230/1.13.1
Fedora 29

Share localhost with docker container

I have a localhost application running on port 5001.
I also have a docker container running that I want to be able to access the application described above but I receive a connection refused error.
I imagine this is because the container needs additional configuration to access the application via the port 5001.

Resources