gpt4 book ai didi

python - 如何使用MariaDB运行dockerized Django REST Framework后端?

转载 作者:行者123 更新时间:2023-12-02 19:16:44 30 4
gpt4 key购买 nike

如标题中所示:使用Docker时,我很难切换到MariaDB。
只要我从磁盘本地启动了许多不同的数据库(默认SQLite,PostgreSQL和MariaDB),每种配置都可以正常工作。 SQLite和PostgreSQL也可以与Docker一起使用(Postgres驱动程序的安装顺利进行),但是MariaDB报告了获取MariaDB Connector/C的问题。Dockerfile:

FROM python:3.8.5-alpine3.12

ENV PYTHONUNBUFFERED 1

COPY ./requirements.txt /requirements.txt
RUN apk add libmariadb3
RUN pip install -r /requirements.txt

RUN mkdir /app
WORKDIR /app
COPY ./app /app

RUN adduser --disabled-password user
USER user
docker-compose.yml:
version: "3"

services:
app:
build:
context: .
ports:
- "8000:8000"
volumes:
- ./app:/app
command:
sh -c "python manage.py runserver 0.0.0.0:8000"
environment:
[...]
depends_on:
- db

db:
image: mariadb:10.5.4
environment:
[...]
我得到的错误是:
[...]
Step 4/11 : RUN apk add libmariadb3
---> Running in 5a3e568b8ac3
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
libmariadb3 (missing):
required by: world[libmariadb3]
ERROR: Service 'app' failed to build: The command '/bin/sh -c apk add libmariadb3' returned a non-zero code: 1
根据 documentation的说明,可以将 MariaDB Connector/Capt-getyumdnfzypper或从源安装在一起,但显然不能与 apk一起安装。
考虑的解决方案:
  • MariaDB Connector/C tar.gz下载到项目目录,并在构建镜像时将其复制。缺点:必须照顾手动更新驱动程序。
  • 使用在Ubuntu上运行的Python镜像。缺点:足够小吗?是否仍然受支持(在Docker Hub的列表中不可见)?

  • 正如我在上面所写,这些解决方案似乎并不令人满意。您知道配置MariaDB与Python一起使用的其他方法吗?

    最佳答案

    似乎python:3.9.0b5-buster已经具备956MB的所有功能:$ cat Dockerfile

    FROM python:3.9.0b5-buster 
    RUN apt-get update
    RUN apt-get install libmariadb3
    $ docker build -t py-booster-with-maria .
    Step 3/3 : RUN apt-get install libmariadb3
    ---> Running in 40be8f94b3de
    Reading package lists...
    Building dependency tree...
    Reading state information...
    libmariadb3 is already the newest version (1:10.3.22-0+deb10u1).
    libmariadb3 set to manually installed.
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    docker image ls | grep py-booster-with-maria
    py-booster-with-maria              latest                       e7c61439835f        7 minutes ago       956MB

    关于python - 如何使用MariaDB运行dockerized Django REST Framework后端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63162275/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com