I have a simple Docker container that runs a python script and outputs a csv locally in the same directory where it is run.
FROM python:3 RUN mkdir /app COPY dockertest.py /app RUN mkdir /app/temp/ RUN pip install pandas requests datetime CMD ["python3","/app/dockertest.py"] -- dockertest.py import pandas as pd from pandas import util df= util.testing.makeDataFrame() print(df.head()) df.to_csv('/app/temp/test.csv')
After building, the following command works without any issues in whatever directory it is run, as long as there is a
/app/temp/ in the working directory
$docker run -d --volume "$(pwd)":/app/temp myrepo/myimage:latest
However, when I add a post request into the script and rebuild the image, there is no output despite having tested the script locally, which outputs the file in
response = requests.post(url, data=data, headers=headers) rawData = pd.read_csv(io.StringIO(response.text)) rawData.to_csv('/app/temp/test.csv')
Is there something that needs to be added to the Dockerfile to "wait" for the http request to complete? I have tried exposing a port in the Dockerfile, but this still does not work.
FROM python:3 RUN mkdir /app COPY dockertest.py /app RUN mkdir /app/temp/ RUN pip install pandas requests datetime EXPOSE 8080 CMD ["python3","/app/dockertest.py"]
Is there something specific that I am missing – something needs to be added to a Dockerfile to run http requests in python?
Source: Docker Questions