0

I don't know what's going on. A script run by Django works fine, but not through Docker and Django. An error is returned:

Pic Errno 2 No such file or directory

Below is the code of the function with the error and the code of the Dockerfile.

'''

def mediainfo(filepath):
    

Original code:

    prober = get_prober_name()
    command_args = [
        "-v", "quiet",
        "-show_format",
        "-show_streams",
        filepath
    ]

    command = [prober, '-of', 'old'] + command_args

Modified code:

    command = f"ffprobe -v error -show_format -show_streams -select_streams v:0 {filepath}"

The rest of the functions:

    res = Popen(command, stdout=PIPE)
    output = res.communicate()[0].decode("utf-8")

    if res.returncode != 0:
        output = Popen(command, stdout=PIPE).communicate()[0].decode("utf-8")

    rgx = re.compile(r"(?:(?P<inner_dict>.*?):)?(?P<key>.*?)\=(?P<value>.*?)$")
    info = {}

    if sys.platform == 'win32':
        output = output.replace("\r", "")

    for line in output.split("\n"):
        # print(line)
        mobj = rgx.match(line)

        if mobj:
            # print(mobj.groups())
            inner_dict, key, value = mobj.groups()

            if inner_dict:
                try:
                    info[inner_dict]
                except KeyError:
                    info[inner_dict] = {}
                info[inner_dict][key] = value
            else:
                info[key] = value

    return info

'''

Code of the Dockerfile

'''

FROM python:3.7 as base

EXPOSE 80

WORKDIR /app
COPY . /app


ENV PYTHONDONTWRITEBYTECODE=1

ENV PYTHONUNBUFFERED=1

RUN pip install --upgrade pip
RUN echo 'deb http://deb.debian.org/debian buster-backports main contrib non-free' >> /etc/apt/sources.list
RUN apt-get update

RUN apt-get -y install ffmpeg
RUN apt-get update

COPY requirements.txt .
RUN python -m pip install -r requirements.txt

FROM base as prod

ENTRYPOINT ["python","manage.py","runserver","0.0.0.0:80"]

'''

1 Answers1

0

Is the missing file actually in the container? You could check for instance like this when container is running: docker exec <your-container-name> ls /app/data/<blacked-out-part-from-your-screenshot>

Reason I ask is because you have that COPY . /app in your Dockerfile, but there's no mention of volumes or bind mounts or anything on how you run container for that matter. If that's all you have for moving data into container, that copy happens once, at image build time and is not synced with source directory.

Normally you don't copy data into image, but share data with container using volumes or bind mounts for persistence & app code.

If my guess about missing file is correct and you really need it in the image, not in container, rebuild image without cache. E.g.: docker build --no-cache <rest-of-the-command-here>. Generally that's a bad practice. And your Dockerfile isn't well layered either. Go with volumes/mounts if you can.

apo
  • 106
  • 5
  • Dear @napovi, the problem is that files are added while the docker is running. The website opens when the docker is working; allows me to add a file. But when I want to work with this file then the given error occurs. If I comment on the "mediainfo function" the whole script works great. Thanks for the links, I will improve my code. Have a nice day. – Agata Kokoszka Feb 09 '21 at 07:49