python - How to run dockerized Django REST Framework backend with MariaDB?
问题描述
As in the title: I have troubles switching to MariaDB when I use Docker.
As long as I launched many different databases locally from my disk (default SQLite, PostgreSQL and MariaDB), every configuration worked fine. SQLite and PostgreSQL work with Docker as well (installation of Postgres' driver goes smoothly), but MariaDB reports issues with fetching 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:
[...]
The error I'm getting is:
[...]
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
According to documentation, MariaDB Connector/C
can be installed with apt-get
, yum
, dnf
, zypper
, or from source, but apparently not with apk
.
Considered solutions:
- Download
MariaDB Connector/C
tar.gz to the project directory and copy it while building image. Cons: one has to take care of updating the driver manually. - Use a Python image run on Ubuntu. Cons: is it small enough? Is it still supported (not visible on the list in Docker's Hub)?
As I wrote above, these solutions don't seem to be satisfactory. Do you know other ways to configure MariaDB to work with 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
推荐阅读
- reactjs - react-redux-firebase 查询返回交错数据
- sql - SQL 查询 - 仅计算满足特定条件的月份
- php - 上传使用PHP里面的文件和html文档
- c# - 在 ASP.NET 中的一组单选按钮(与 GroupName 属性相关联)中查找选定单选按钮的值的最佳方法
- css - 当我在头部导入时,反应 css 导入在 cdn 中不起作用
- excel - VLookUp 和格式化
- java - 如何删除工具栏上方的空间?
- macos - NLTK 数据下载在 Anaconda 环境中的 MacOS 上挂起
- ruby-on-rails - 如何将我的代码库恢复到我最近的部署?
- mongodb - 如何在 mongodb 中将当前时间戳插入或更新为 NumberLong