Home > OS >  issues with Docker on wsl (ubuntu 22.04)
issues with Docker on wsl (ubuntu 22.04)

Time:10-19

An attempt to build a docker image fails on RUN pip install -r requirements.txt step with the following error:

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/asgiref/
WARNING: Retrying (Retry(total=3, 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/asgiref/
WARNING: Retrying (Retry(total=2, 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/asgiref/
WARNING: Retrying (Retry(total=1, 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/asgiref/`

for some reason, asgiref==3.5.2 doesn't want to install. What could be the reason for this?

System used:

  • OS: Windows 11
  • WSL 2 with Ubuntu 22.04 on board
  • Docker version 20.10.19, build d85ef84
  • Dockerfile contents:
# Pull base image
FROM python:3.10.6-slim-bullseye

# Set enviroment variables

ENV PIP_DISABLE_PIP_VERSION_CHECK 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory

WORKDIR /code

# Install dependencies

COPY ./requirements.txt .
RUN pip install -r requirements.txt

# Copy project

COPY . .
  • requirements.txt contents:
asgiref==3.5.2
Django==4.1.2
sqlparse==0.4.3

CodePudding user response:

I had this problem today. So, you can fix this issue with a --network host in your Docker build line.

The reason for this is issue is an MTU mismatch of your network interfaces. If you open the base image from your Dockerfile in interactive mode: sudo docker run -it {your base image repo} /bin/bash, and run ip a, then do the same on your host OS, you will probably find that they are different. This means that the Docker bridge is dropping packets / failing transmission. If you want bridge networking to work as opposed to host, create a file on your host OS at /etc/docker/daemon.json with the contents

{
    "mtu": whatever_your_host_os_MTU_is
}

and then run sudo systemctl restart docker, this should probably fix your bridge networking.

EDIT: I should add that this is only the case (most likely) if you have internet connectivity from your container (i.e. apt/yum works but something else like pip breaks). If you cannot pull anything, you probably have a DNS/firewall issue.

  • Related