【问题标题】:How to copy a Django SQlite database to a Docker container?如何将 Django SQlite 数据库复制到 Docker 容器?
【发布时间】:2021-06-30 05:35:58
【问题描述】:

我是 Docker 新手。我正在尝试对 Django 应用程序进行 dockerize。

我的项目包含一个 Wagtail 应用程序,我正在使用 Wagtail 自动生成的 Dockerfile。

FROM python:3.8.6-slim-buster

RUN useradd wagtail

EXPOSE 8000

ENV PYTHONUNBUFFERED=1 \
    PORT=8000

RUN apt-get update --yes --quiet && apt-get install --yes --quiet --no-install-recommends \
    build-essential \
    libpq-dev \
    libmariadbclient-dev \
    libjpeg62-turbo-dev \
    zlib1g-dev \
    libwebp-dev \
    nano \
    vim \
 && rm -rf /var/lib/apt/lists/*

RUN pip install "gunicorn==20.0.4"

COPY requirements.txt /

RUN pip install -r /requirements.txt

WORKDIR /app

RUN chown wagtail:wagtail /app

COPY --chown=wagtail:wagtail . .

USER wagtail

RUN python manage.py collectstatic --noinput --clear

CMD set -xe; python manage.py migrate --noinput; gunicorn mysite.wsgi:application

它运行良好,但我的 sqlite 数据库是空的,我想用我将在本地创建的 wagtail 页面运行我的容器。

我怎样才能更改 Dockerfile 来进行这项工作?

【问题讨论】:

标签: django docker sqlite wagtail


【解决方案1】:

只需在 Docker 中转储和重新加载数据。

我发现在 Docker 容器中使用 sqlite3 非常糟糕。

我最好使用 Docker + PostGres 解决方案:https://docs.docker.com/samples/django/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-13
    • 2019-07-16
    • 1970-01-01
    相关资源
    最近更新 更多