Имею простого пользовательского бота на pyrogram. Вот код:
Бот
from pyrogram import Client, filters
from pyrogram.types import Message
app = Client(name="my_account", api_id=os.getenv("API_ID"), api_hash=os.getenv("API_HASH"))
@app.on_message(filters.command(commands=["voice", "голос", "гс"], prefixes=["/", "!", "."]))
async def _voice_command(client: Client, message: Message):
pass
app.run()
Я хочу запустить его в Docker, но есть проблема с запуском в нем. При запуске такая ошибка:
Traceback (most recent call last):
2023-12-14T09:20:55.989775181Z File "/app/main.py", line 68, in <module>
2023-12-14T09:20:55.989792321Z app.run()
2023-12-14T09:20:55.989799201Z File "/usr/local/lib/python3.10/site-packages/pyrogram/methods/utilities/run.py", line 84, in run
2023-12-14T09:20:55.989978434Z self.start()
2023-12-14T09:20:55.989989834Z File "/usr/local/lib/python3.10/site-packages/pyrogram/sync.py", line 66, in async_to_sync_wrap
2023-12-14T09:20:55.990067335Z return loop.run_until_complete(coroutine)
2023-12-14T09:20:55.990078855Z File "/usr/local/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
2023-12-14T09:20:55.990322574Z return future.result()
2023-12-14T09:20:55.990370945Z File "/usr/local/lib/python3.10/site-packages/pyrogram/methods/utilities/start.py", line 58, in start
2023-12-14T09:20:55.990512817Z is_authorized = await self.connect()
2023-12-14T09:20:55.990523307Z File "/usr/local/lib/python3.10/site-packages/pyrogram/methods/auth/connect.py", line 40, in connect
2023-12-14T09:20:55.990531307Z await self.load_session()
2023-12-14T09:20:55.990536177Z File "/usr/local/lib/python3.10/site-packages/pyrogram/client.py", line 616, in load_session
2023-12-14T09:20:55.991110220Z await self.storage.open()
2023-12-14T09:20:55.991144821Z File "/usr/local/lib/python3.10/site-packages/pyrogram/storage/file_storage.py", line 63, in open
2023-12-14T09:20:55.991496166Z self.update()
2023-12-14T09:20:55.991534847Z File "/usr/local/lib/python3.10/site-packages/pyrogram/storage/file_storage.py", line 52, in update
2023-12-14T09:20:55.991546757Z self.version(version)
2023-12-14T09:20:55.991553477Z File "/usr/local/lib/python3.10/site-packages/pyrogram/storage/sqlite_storage.py", line 219, in version
2023-12-14T09:20:55.991618798Z self.conn.execute(
2023-12-14T09:20:55.991744595Z sqlite3.OperationalError: attempt to write a readonly database
Dockerfile:
Dockerfile
# syntax=docker/dockerfile:1
ARG PYTHON_VERSION=3.10.9
FROM python:${PYTHON_VERSION}-slim as base
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /app
ARG UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
appuser
COPY Pipfile Pipfile.lock /app/
RUN pip install pipenv && pipenv install --system --deploy --ignore-pipfile && apt update -y && apt install ffmpeg -y
USER appuser
COPY . .
ENTRYPOINT ["python", "main.py"]
Я понимаю, что проблема из за базы данных сессии, но не понимаю как можно ее адекватно решить. Можете подсказать?
p.s. Эксперимента ради я копирую базу данных с сессиями в контейнер. Библиотека позволяет хранить сессии не в базе данных, но я тогда не представляю как с помощью интерактивной оболочки каждый раз входить в аккаунт