I am developing a Flask application with Docker setup. My Os is Linux Mint. Suddenly can't send any request from my application. It's showing error like this:
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.kickbox.io', port=443):
Max retries exceeded with url: /v2/verify?email=harun1393%40gmail.com&timeout=6000 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f71b5e89c90>:
Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))
ping google.com is working fine from my OS but showing Temporary failure in name resolution inside docker container.
docker exec -it web /bin/bash
root#b72e895be44a:/web# ping google.com
ping: google.com: Temporary failure in name resolution
/etc/resolve.conf from OS:
nameserver 192.168.0.1
/ect/resolve.conf inside docker container
nameserver 127.0.0.11
options ndots:0
cat /etc/docker/daemon.json
{
"dns": ["192.168.0.1", "8.8.8.8"]
}
I used host network in docker-compose.yml, but result is same.
website:
# network_mode: host
build:
context: .
network: host
container_name: web
I have tried a lot, but couldn't solve my problem.
Related
I am running an Apache Phoenix container along with Hbase using the following command,
docker run -it --name phoenix -p 8765:8765 avapno/apache-phoenix
This is done as explained here,
https://hub.docker.com/r/avapno/apache-phoenix
The containers run without a problem.
Now, I want to connect to Phoenix using Python. This is the code I have used to do so,
import phoenixdb
database_url = 'http://localhost:8765/'
conn = phoenixdb.connect(database_url, autocommit=True)
This does not, however, seem to work. I keep getting the following error,
ConnectionError: HTTPConnectionPool(host='localhost', port=8765): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7ffb03782080>: Failed to establish a new connection: [Errno 111] Connection refused'))
How exactly do I get this done correctly?
Also, is there a better way to get Hbase + Phoenix running?
I have a streamlit application (localhost:8501) and an API (127.0.0.1:8000).
My streamlit application tries to access the API.
It works well when I launch the command to start "streamlit". But when streamlit is in a Docker container, I'm not able to access the URL. I have this error:
ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=8000): Max retries exceeded with url: /predict (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f2a5ebae090>: Failed to establish a new connection: [Errno 111] Connection refused'))
This is my dockerfile:
FROM tiangolo/uvicorn-gunicorn:python3.7
ENV PYTHONPATH .
RUN mkdir /streamlit
COPY requirements.txt /streamlit
WORKDIR /streamlit
RUN pip install -r requirements.txt
COPY . /streamlit
EXPOSE 8501
CMD ["streamlit", "run", "web/source/web_api.py"]
And the commands I launch:
docker build --tag web_streamlit.
docker run --publish 8501:8501 --detach --name web_streamlit_container web_streamlit
I'm able to access localhost:8501. Inside I have a streamlit application that is unable to reach localhos:8000 which is another service.
To access service that is running on you have special DNS for mac and window.
host.docker.internal, which resolves to the internal IP address used by the host.
So replace localhost:8000 with host.docker.internal:8000
special DNS for mac and window
or if you Linux then set host to resolve the special DNS for your self.
docker run --publish 8501:8501 -it --rm --add-host="host.docker.internal:192.168.9.100" --name web_streamlit_container web_streamlit
Where 192.168.9.100 is the host IP that you can get using ifconfig in linux.
So you have flexible DNS that will work all platform Linux,window and mac you do not need to modify code.
If you try to ping localhost from the container, the container will ping itself :)
If you want to reach a service that's running on the host itself, from the container, you need to fetch the IP of your docker0 interface:
On your host machine: run ip addr show docker0 to find it
neo#neo-desktop:~$ ip addr show docker0
4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:33:70:c8:74 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
inet6 fe80::42:33ff:fe70:c874/64 scope link
valid_lft forever preferred_lft forever
Fetch the IP (172.17.0.1 in my example) and use 172.17.0.1:8000 to reach your API form the continer.
PS: works on Linux. If you run Docker on Win or Mac, you need to do something else.
Technical overview of your problem & quick fix ☑️
__
Lets assume you have 2 docker images
1st image : Fastapi or any other API backend wrapped using Docker.
2nd image : Streamlit Frontend wrapped using Docker
Now , when you request API from streamlit docker to another docker eg (localhost://predict) it will not work.
Beacuse you are requested API current localhost to same docker localhost and its pointing to itself.
So you need to change that localhost present in your streamlit script to required API host (means another docker IP)
To finding that IP hit following command :-
ip addr show docker0
It will give you ip address something like 172.17.0.1/16.
Now you have change your streamlit localhost request url to ,
http://172.17.0.1/
Then build the streamlit docker again.
docker build -t frontend: version-1
Now run the streamlit docker by,
docker run --rm -it -p 8501/8501/tcp frontend:version-1
Done ✅ 😃
In Python3, I am using get.requests() in a parallel loop to query a server that I have running in a docker container (specifically an OSRM server).
I get this error after it successfully queries a few:
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
I think the Docker container has a limit on the number of queries at a time or from a single IP, but I don't know how to fix it. I'm assuming it's in the Docker settings.
I initiate the docker container using: docker run --name osrm-nc -t -i -p 6002:5000 -v /homedirs/tml62/osm:/data osrm/osrm-backend osrm-routed --algorithm mld /data/north-carolina-latest.osrm, so noteably, I'm assigning the ports
I've set the retries so it can repeat and that sometimes fixes it, but it causes delays and sometimes will still break.
I'm running two docker containers as follows:
one is for selenium/standalone-chrome
$ docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome
and the main container uses host networking to connect to MySQL which is running on localhost
$ docker run --rm --network="host" $(IMAGE_REPO)
but when I tried to initiate the driver in the main container
from selenium import webdriver
driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities=webdriver.DesiredCapabilities.CHROME)
I got error message which is either
urllib3.exceptions.ProtocolError: ('Connection aborted.', BadStatusLine("''",))
or
urllib3.exceptions.ProtocolError: ('Connection aborted.', error(104, 'Connection reset by peer'))
did I forget anything / any parameters when trying to establish the containers? or the value passing to command_executor should not be 'http://127.0.0.1:4444/wd/hub'?
I also tried to use docker bridge networking, but then I have no idea how to connect to MySQL server on localhost
SQLALCHEMY_URI = '{driver}://{user}:{pwd}#{host}/{db}?charset=utf8' \
.format(
driver='mysql+pymysql',
host='127.0.0.1:3306',
user='root',
pwd='0000',
db='default'
)
Update the following libraries in your Dockerfile:
Set Selenium library version to 3.3.1 (selenium==3.3.1).
i.e: Make use of a Selenium image, whose version is 3.3.1.
Use selenium/node-chrome:3.3.1 instead of selenium/node-chrome:3.141.59-gold
I have a client.py sending data to (server_ip,60000). The server side code, which receives data, sits inside a docker container. The codes are in Python and the server runs on Mac OS. Before migrating to docker, I could successfully transmit data. After dockerizing the server.py code, the bind happens, but client.py at connection.sendall(out) says:
socket.error: [Errno 32] Broken pipe
Here is my docker-compose.yml:
version: '2'
services:
server:
build: ./server
ports:
- server_IP:60000:60000
and here is the binding inside server.py:
port = 60000
host = "localhost"
Any idea why this happens?
Well, I could fix it by setting the host at server side to 0.0.0.0 inside docker and removing-rebuilding the image. All works fine.