1

I'm wondering how I can make a basic http requests inside a docker container:

https_example.py

import requests
x = requests.get('https://w3schools.com')
print(x.status_code)

Dockerfile

FROM python:3.8-slim-buster

WORKDIR /

COPY requirements.txt .
COPY https_example.py .

RUN pip install --no-cache-dir -r requirements.txt

CMD ["python", "https_example.py"]

My requirements file just has requests

If I run this locally I don't get a response in the logs.

Ryan Marr
  • 83
  • 7
  • I tried building it, and it printed out 200, as it should. Perhaps add the exact commands you're using to build and run it? Do you get ANY outputs from within the docker container (add a constant message print before the `get`)? It could be something with your docker networking setup, I guess? – Dominik Stańczak Aug 04 '22 at 05:46
  • Do you need to set the `PYTHONUNBUFFERED` environment variable or `python -u` command-line option, as in [Python app does not print anything when running detached in docker](https://stackoverflow.com/questions/29663459/python-app-does-not-print-anything-when-running-detached-in-docker)? – David Maze Aug 04 '22 at 10:52

0 Answers0