0

I'm fairly new to Docker and am trying to have a python Discord bot in a container.

My project folder structure is the following:

- util
- - logger.py
- cogs
- - part-of-the-bot.py
- requirements.txt
- run.py

I've checked some tutorials and the official python docker hub page to help me create the Dockerfile:

FROM python:3.9

WORKDIR /usr/src/app

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY . .
RUN chmod +x run.py
 
CMD [ "python", "run.py" ]

After that, I use docker build -t bot . and docker-compose with the following YAML file:

version: '3'

services: 
  discord-bot:
     image: bot:latest
     restart: unless-stopped
     volumes:
       - ~/volumes/bot:/usr/src/app

However, there are some issues with it: Currently I get an error about the file /usr/src/app/run.py not existing:

python: can't open file '/usr/src/app/run.py': [Errno 2] No such file or directory
python: can't open file '/usr/src/app/run.py': [Errno 2] No such file or directory
python: can't open file '/usr/src/app/run.py': [Errno 2] No such file or directory
python: can't open file '/usr/src/app/run.py': [Errno 2] No such file or directory
python: can't open file '/usr/src/app/run.py': [Errno 2] No such file or directory
python: can't open file '/usr/src/app/run.py': [Errno 2] No such file or directory
python: can't open file '/usr/src/app/run.py': [Errno 2] No such file or directory
python: can't open file '/usr/src/app/run.py': [Errno 2] No such file or directory
python: can't open file '/usr/src/app/run.py': [Errno 2] No such file or directory
python: can't open file '/usr/src/app/run.py': [Errno 2] No such file or directory
python: can't open file '/usr/src/app/run.py': [Errno 2] No such file or directory
python: can't open file '/usr/src/app/run.py': [Errno 2] No such file or directory
python: can't open file '/usr/src/app/run.py': [Errno 2] No such file or directory
python: can't open file '/usr/src/app/run.py': [Errno 2] No such file or directory

I have checked this with some RUN pwd and RUN ls in the Dockerfile and everything seems to have been copied correctly.

I'm also having trouble figuring out if I need to open a port for the Discord bot to work.

EDIT: I had tried the discord.py image on docker hub but it seems it is not suited for the Raspberry Pi architecture.

Lithimlin
  • 542
  • 1
  • 6
  • 24
  • Have you checked out existing Docker Hub images like [this](https://hub.docker.com/r/gorialis/discord.py) for inspiration/retrieving a prebuild image? Maybe the [repo](https://gitlab.com/Gorialis/discord.py-docker/blob/master/dockerfiles/README.md) associated with the aforementioned Docker Hub Image helps. – Daniel B. Jan 07 '21 at 18:27
  • @DanielB. In hindsight, I should have checked if there was a discord.py image on docker hub. I'm gonna try that out now. – Lithimlin Jan 07 '21 at 18:33
  • Unfortunately, I'm getting the following error when using their `Dockerfile`: `standard_init_linux.go:219: exec user process caused: exec format error` – Lithimlin Jan 07 '21 at 18:37
  • Maybe this stackoverflow [post](https://stackoverflow.com/a/58299100/11478452) helps? – Daniel B. Jan 07 '21 at 18:42
  • I'd looked at that as well. However, the issue already arises while attempting to install the requirements. – Lithimlin Jan 07 '21 at 18:44
  • The problem may lie with the post below it where this image is not made for raspberry pis. – Lithimlin Jan 07 '21 at 18:48
  • You could try re-building their image according to the instructions provided in their [README](https://gitlab.com/Gorialis/discord.py-docker/blob/master/dockerfiles/README.md). So, start by cloning their repo and then following the instructions. That way, you either get a container running on your system or (hopefully) at least a more descriptive/indicative error message. – Daniel B. Jan 07 '21 at 18:54
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/226991/discussion-between-lithimlin-and-daniel-b). – Lithimlin Jan 07 '21 at 19:06
  • Btw: Regarding your Dockerfile code snippet above: I am not entirely sure, but I suspect that there is some issue with how you specify your paths. `WORKDIR /usr/src/app` declares the path of the working directory to be `/usr/src/app`. Afterwards, however, you exclusively save contents to some 'present' directory specified by `.` (as in `COPY requirements.txt ./` and `COPY . .`). Might be that you have to specify the saving directory and the WORKDIR to be the same, hence either shall both be `.` or `/usr/src/app`, but not `.` and `/usr/src/app` at the same time. – Daniel B. Jan 07 '21 at 19:06
  • I checked with some `RUN ls`and `RUN pwd` and `WORKDIR` sets up everything correctly so it should work. As far as I can tell, everything is in the right place – Lithimlin Jan 07 '21 at 19:08
  • `.` refers to `WORKDIR` for `COPY` command (and some others) after it is defined, so your `Dockerfile` looks fine. Can you please update the question with the logs of the command that you use to build the image? – vpalmerini Jan 07 '21 at 20:42
  • Good! It looks like `docker-compose` tries to find your file in the specified `volume`, which does not have it, of course. You can either build your image from `docker-compose` by adding in your `discord-bot` service: `build: context: .` or removing the `volumes` option in your `docker-compose.yml`. I don't know if there is another approach :( – vpalmerini Jan 08 '21 at 15:34
  • Removing the `volumes` option does not seem to work. At least I can't find any logs in portainer when I do so. Adding your proposed `build: context: .` does not work either. – Lithimlin Jan 08 '21 at 15:56

0 Answers0