@mewmew

Почему не отправляются запросы внутри docker контейнера?

Всем привет!
Есть арендованный сервер на reg.ru, где крутится приложение. Есть необходимость в отправке сетевых запросов. Возникла проблема с их отправкой внутри docker контейнера.
Dockerfile
FROM python:3.11.7
RUN apt-get update \
    && apt-get install -y libpq-dev postgresql-client build-essential libpq-de>
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

EXPOSE 8000
WORKDIR /backend

COPY . .
RUN pip install --no-cache-dir -r req.txt

Для проведения тестов подготовил небольшую функцию (requests==2.30.0)
import requests


def get_data(url):
    try:
        response = requests.get(url, timeout=10)
        print(url, 'good')
    except requests.exceptions.ReadTimeout as e:
        print(url, '------fiasko bratan-------', e)


urls = ['https://google.com', 'https://staminity.com', 'https://fatsecret.com', 'https://habr.ru', 'https://ya.ru']

for i in urls:
    get_data(i)

На сервере запросы успешно отправляются.
Однако, при использовании внутри контейнера и только на сервере (локально работает) выдает ошибку timeout.
Среди тестируемых сайтов 2 прошли 3 нет.
<br>
https://google.com good<br>
https://staminity.com ------fiasko bratan------- HTTPSConnectionPool(host='staminity.com', port=443): Read timed out. (read timeout=10)<br>
https://fatsecret.com ------fiasko bratan------- HTTPSConnectionPool(host='fatsecret.com', port=443): Read timed out. (read timeout=10)<br>
https://habr.ru ------fiasko bratan------- HTTPSConnectionPool(host='habr.ru', port=443): Read timed out. (read timeout=10)<br>
https://ya.ru good<br>
<br>

Также, пробывал ping внутри контейнера:
PING google.com (173.194.222.102) 56(84) bytes of data.
64 bytes from lo-in-f102.1e100.net (173.194.222.102): icmp_seq=1 ttl=107 time=15.9 ms
64 bytes from lo-in-f102.1e100.net (173.194.222.102): icmp_seq=2 ttl=107 time=15.9 ms

PING staminity.com (81.163.31.117) 56(84) bytes of data.
64 bytes from wealthkingusa.com (81.163.31.117): icmp_seq=1 ttl=55 time=1.10 ms
64 bytes from wealthkingusa.com (81.163.31.117): icmp_seq=2 ttl=55 time=1.25 ms

ING fatsecret.com (52.206.184.66) 56(84) bytes of data.
--- fatsecret.com ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 3061ms

PING habr.ru (178.248.233.33) 56(84) bytes of data.
64 bytes from habr.com (178.248.233.33): icmp_seq=1 ttl=55 time=1.63 ms
64 bytes from habr.com (178.248.233.33): icmp_seq=2 ttl=55 time=1.58 ms

Также, что странно, внутри контейнера pip тоже не может соединится с интернетом...
root@****:/home/saligin/deploy# docker-compose exec backend bash
root@****:/backend# pip install python-docx
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/python-docx/

По итогу, везде запроса выполняются успешно, за исключением docker контейнера.
  • Вопрос задан
  • 153 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы