I am trying to setup Docker environment for my discord.py bot. I managed to create a Dockerfile, which uses python:3.9-slim-buster as a base image. Everything is working perfectly, when I run the bot inside Docker container on my Ubuntu machine. However, if I use MacBook with Apple Silicon M1 chip, it behaves differently. After running bot.py script and making it join a voice channel, it crashes on message.author.voice.channel.connect() with segmentation fault.
from discord.ext import commands
bot = commands.Bot('!')
@bot.event
async def on_message(message):
await message.author.voice.channel.connect()
bot.run(DISCORD_TOKEN)
The result is bot joining into my voice channel and immediate crash after that. This is the output I get:
Fatal Python error: Segmentation fault
Thread 0x0000ffffa6c071e0 (most recent call first):
File "/usr/local/lib/python3.9/threading.py", line 316 in wait
File "/usr/local/lib/python3.9/threading.py", line 574 in wait
File "/usr/local/lib/python3.9/site-packages/discord/gateway.py", line 133 in run
File "/usr/local/lib/python3.9/threading.py", line 973 in _bootstrap_inner
File "/usr/local/lib/python3.9/threading.py", line 930 in _bootstrap
Thread 0x0000ffffa74a71e0 (most recent call first):
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 75 in _worker
File "/usr/local/lib/python3.9/threading.py", line 910 in run
File "/usr/local/lib/python3.9/threading.py", line 973 in _bootstrap_inner
File "/usr/local/lib/python3.9/threading.py", line 930 in _bootstrap
Current thread 0x0000ffffa8e22010 (most recent call first):
File "/usr/local/lib/python3.9/ssl.py", line 897 in write
File "/usr/local/lib/python3.9/asyncio/sslproto.py", line 261 in feed_appdata
File "/usr/local/lib/python3.9/asyncio/sslproto.py", line 674 in _process_write_backlog
File "/usr/local/lib/python3.9/asyncio/sslproto.py", line 598 in _write_appdata
File "/usr/local/lib/python3.9/asyncio/sslproto.py", line 386 in write
File "/usr/local/lib/python3.9/site-packages/aiohttp/http_writer.py", line 68 in _write
File "/usr/local/lib/python3.9/site-packages/aiohttp/http_writer.py", line 119 in write_headers
File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 668 in send
File "/usr/local/lib/python3.9/site-packages/aiohttp/client.py", line 542 in _request
File "/usr/local/lib/python3.9/site-packages/aiohttp/client.py", line 754 in _ws_connect
File "/usr/local/lib/python3.9/site-packages/discord/http.py", line 132 in ws_connect
File "/usr/local/lib/python3.9/site-packages/discord/gateway.py", line 765 in from_client
File "/usr/local/lib/python3.9/site-packages/discord/voice_client.py", line 321 in connect_websocket
File "/usr/local/lib/python3.9/site-packages/discord/voice_client.py", line 353 in connect
File "/usr/local/lib/python3.9/site-packages/discord/abc.py", line 1285 in connect
File "/workspace/bot.py", line 7 in on_message
File "/usr/local/lib/python3.9/site-packages/discord/client.py", line 343 in _run_event
File "/usr/local/lib/python3.9/asyncio/events.py", line 80 in _run
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1890 in _run_once
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 596 in run_forever
File "/usr/local/lib/python3.9/site-packages/discord/client.py", line 713 in run
File "/workspace/bot.py", line 9 in <module>
Segmentation fault
Shouldn't Docker containers behave the same on different machines? Do you think it is a Docker bug or is there some way to fix this?
EDIT:
Added Dockerfile:
FROM python:3.9-slim-buster
ENV PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100
RUN apt-get update && apt-get install -y \
build-essential libpq-dev git \
ca-certificates ffmpeg libopus-dev libsodium-dev ansible gcc git libffi-dev libsodium-dev make musl-dev
RUN pip install poetry
WORKDIR /app
COPY poetry.lock pyproject.toml /app/
RUN poetry config virtualenvs.create false && poetry install
COPY . /app
CMD ["python3", "bot.py"]
