Seth
Seth

Reputation: 145

Docker not saving ouput to file

Originally posted this on the subject. After answer the csv was saving to the indicated directory. Now it'll create a new directory(/data) but the csv isn't there. I'm not sure why this is no longer working. Without the docker the python script runs as intended.

Commands I'm running:

docker build -t dock ./search_api
docker run -v ~/twitter-data/data:/app/ dock

And getting the following ouput:

Downloaded 220 tweets, Saved to /search/tweets.csv

Here is the Dockerfile

# Use an official Python runtime as a parent image
FROM python:3.6-slim

# Set the working directory to /app
WORKDIR /search

# Copy the current directory contents into the container at /app
ADD . /search

# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt

# Run app.py when the container launches
CMD ["python", "search.py"]

Search.py is appending to tweets.csv

Upvotes: 0

Views: 2337

Answers (2)

Seth
Seth

Reputation: 145

Okay it's because the volume was ~/twitter-data/data but the search.py/app.py was in the search_api directory. Thanks for the help, sorry I didn't give all the info.

twitter-data
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── __pycache__
│   └── config.cpython-36.pyc
├── ci
│   └── build-images.sh
├── data
│   └── tweets.csv
├── images
│   └── test
│       └── Dockerfile
└── search_api
    ├── Dockerfile
    ├── __pycache__
    │   └── config.cpython-36.pyc
    ├── app.py
    ├── config.py
    └── requirements.txt

Upvotes: 0

Jack Gore
Jack Gore

Reputation: 4242

Your binding to the wrong directory in the container. If you are receiving output saying Saved to /search/tweets.csv then you need to bind mount a directory to /search not to app.

As of now you are mapping the directory /app from inside the container to your host machine, which I presume is empty even inside the container.

To fix your problem simply change your docker run command to:

$ docker run -v ~/twitter-data/data:/search/ dock

Upvotes: 1

Related Questions