首页 > 解决方案 > Docker 中的 Django 应用程序给出 FileNotFoundError: [Errno 2] No such file or directory: '/tmp/

问题描述

我正在使用带有图像的Docker来对Django应用程序进行 dockerize。python:3.7.6-slim

我正在使用django-import-export插件在管理面板中导入数据,该管理面板将上传的文件存储在临时目录中以在导入时读取。

但是在导入时,它给出了一个错误

FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmppk01nf3d'

不使用 docker 时也是如此。

Dockerfile

FROM python:3.7.6-slim

ARG APP_USER=appuser
RUN groupadd -r ${APP_USER} && useradd --no-log-init -r -g ${APP_USER} ${APP_USER}

RUN set -ex \
    && RUN_DEPS=" \
    libpcre3 \
    mime-support \
    default-libmysqlclient-dev \
    inkscape \
    libcurl4-nss-dev libssl-dev \
    " \
    && seq 1 8 | xargs -I{} mkdir -p /usr/share/man/man{} \
    && apt-get update && apt-get install -y --no-install-recommends $RUN_DEPS \
    && pip install pipenv \
    && rm -rf /var/lib/apt/lists/* \
    && mkdir -p /home/${APP_USER}/.config/inkscape \
    && chown -R ${APP_USER} /home/${APP_USER}/.config/inkscape \
    # Create directories
    && mkdir /app/ \
    && mkdir /app/config/ \
    && mkdir /app/scripts/ \
    && mkdir -p /static_cdn/static_root/ \
    && chown -R ${APP_USER} /static_cdn/

WORKDIR /app/

COPY Pipfile Pipfile.lock /app/

RUN set -ex \
    && BUILD_DEPS=" \
    build-essential \
    libpcre3-dev \
    libpq-dev \
    " \
    && apt-get update && apt-get install -y --no-install-recommends $BUILD_DEPS \
    && pipenv install --deploy --system \
    \
    && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $BUILD_DEPS \
    && rm -rf /var/lib/apt/lists/*

COPY ./src /app/
COPY scripts/ /app/scripts/
COPY configs/ /app/configs/

EXPOSE 8000

ENV UWSGI_WSGI_FILE=qcg/wsgi.py
ENV UWSGI_HTTP=:8000 UWSGI_MASTER=1 UWSGI_HTTP_AUTO_CHUNKED=1 UWSGI_HTTP_KEEPALIVE=1 UWSGI_LAZY_APPS=1 UWSGI_WSGI_ENV_BEHAVIOR=holy
ENV UWSGI_WORKERS=2 UWSGI_THREADS=4
ENV UWSGI_STATIC_MAP="/static/=/static_cdn/static_root/" UWSGI_STATIC_EXPIRES_URI="/static/.*\.[a-f0-9]{12,}\.(css|js|png|jpg|jpeg|gif|ico|woff|ttf|otf|svg|scss|map|txt) 315360000"
USER ${APP_USER}:${APP_USER}

ENTRYPOINT ["/app/scripts/docker/entrypoint.sh"]

和运行命令

docker run my-image uwsgi --show-config

标签: djangodockerdjango-import-export

解决方案


推荐阅读