Rate This Document
Findability
Accuracy
Completeness
Readability

Solution to "urllib3.exceptions.URLSchemeUnknown: Not supported URL scheme http+docker"

Symptom

When the PYTHONNOUSERSITE=1 docker-compose -f docker-compose.yaml up command is executed on openEuler 24.03 LTS SP3, the error message "urllib3.exceptions.URLSchemeUnknown: Not supported URL scheme http+docker" is displayed.

Analysis

  • docker-py mounts a custom URL scheme http+docker:// through UnixHTTPAdapter for Unix socket communication.
  • In requests 2.31.0, get_connection_with_tls_context() is introduced in HTTPAdapter.send() to replace the deprecated get_connection(). This bypasses the override of get_connection() by UnixHTTPAdapter.
  • The default PoolManager of urllib3 cannot identify the custom http+docker scheme.

Solution

Add get_connection_with_tls_context() to UnixHTTPAdapter. The procedure is as follows:

  1. Open the unixconn.py file.
    1
    vim /usr/lib/python3.11/site-packages/docker/transport/unixconn.py
    
  2. Press i to enter the insert mode and add the following content after line 66 (or after super().__init__()) and before the get_connection method:
    1
    2
        def get_connection_with_tls_context(self, request, verify, proxies=None, cert=None):
            return self.get_connection(request.url, proxies=proxies)
    
  3. Press Esc to exit the insert mode. Type :wq! and press Enter to save the file and exit.