Can't connect to https from inside a docker container -- how to enable?

I have an API running inside of a Docker container, which I build using docker-compose up --build. Inside of my API code, I need to make a call to an https endpoint online. When attempting to make this request, I am seeing the following error:

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: // (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7fc40e584f90>: Failed to resolve 'https' ([Errno -3] Temporary failure in name resolution)"))

The same code works outside of the container on my local machine.

In fact, this stack overflow question outlines my situation exactly: python 3.x - GET request not responding in docker container - Stack Overflow

After some reading, it seems that maybe the ssl port is not open or there is otherwise an issue routing traffic to https from inside the container.

My question: how do I make GET request from inside a docker container? What can I do to address these errors related to https connection timeouts?


This looks wrong: https is not a host, it’s a protocol, and // is not an url, as it misses the protocol.
It’s a problem on the python level, not on the container level. You need to fix it in your code.

Hi there, thanks for the note @meyay . I blocked out the specific site for this post – but can assure there is a proper url there in my actual error message and code.

I also have run this code locally (not in a Docker container) with success – so am confident it’s not the code/python. Have tried with other request libraries as well, with same results.

I still stick to “it’s your code!”.

If I run this command, it will access and show in the terminal:

docker run -ti --rm python python -c  "from urllib.request import urlopen;resp = urlopen('');

Update: added --rm to the command to clean up test container after execution.