即使在 chmod 777 之后"sqlite3.OperationalError: attempt to write a readonly database"



我正在docker容器中运行一个Django应用程序。我收到这个错误sqlite3.OperationalError: attempt to write a readonly database。我已经尝试了Dockerfile 中的所有内容

RUN chown username db.sqlite3
RUN chmod 777 db.sqlite3

我也尝试以root用户的身份运行该应用程序,但仍然出现了同样的错误。

这是我的Dockerfile

FROM python:3.9.5-alpine
RUN addgroup -S apigroup && adduser -S weatherapi -G apigroup
WORKDIR /app
ADD requirements.txt .
RUN apk update && apk upgrade
RUN python3 -m pip install --upgrade pip && python3 -m pip install --no-cache-dir -r requirements.txt
COPY . . 
USER root
EXPOSE 8000
RUN chmod 777 db.sqlite3
USER weatherapi
RUN python3 manage.py migrate
CMD ["sh", "-c", "python3 manage.py runserver 0.0.0.0:8000"]

我的码头工人撰写

version: '3.7'
networks: 
weather_api_net:
driver: bridge
driver_opts:
com.docker.network.enable_ipv6: "false"

services:
web:
restart: unless-stopped
image: weatherapi:1.0
container_name: weatherapi
ports:
- "8000:8000"
volumes:
- .:/app
deploy:
replicas: 1
update_config:
parallelism: 2
delay: 10s
order: start-first
rollback_config:
parallelism: 2
delay: 10s
failure_action: continue
monitor: 60s
order: stop-first
restart_policy:
condition: on-failure
networks:
- weather_api_net

我只需要将基础图像更改为基于Debian的图像。

FROM python:3.8-buster

显然Alpine不喜欢SQLite。

相关内容