d-Rickyy-b / Python-BlackJackBot

A Telegram bot written in Python to play the game BlackJack alone or with your friends
https://telegram.me/BlackJackBot
GNU General Public License v3.0
76 stars 37 forks source link

The Docker container that has been built is not launching. #112

Closed dfyzicka closed 1 year ago

dfyzicka commented 1 year ago

Hello, could you please advise me on what I might be doing wrong. When running the bot using Python - the bot works perfectly fine, but when I build the container, it fails to launch and returns an error:

Traceback (most recent call last): File "/blackjackbot/bot.py", line 9, in import config ModuleNotFoundError: No module named 'config'

d-Rickyy-b commented 1 year ago

Hi, the docker container expects a config.py file which contains e.g. the bot token etc. Check this for an example config file.

As can be seen in the docker-compose.yml you need to pass the config.py as a docker volume to the container.

dfyzicka commented 1 year ago

I renamed config.sample.py to config.py and added the bot token. When I usepython3 bot.py, the code runs without errors. However, when I build the container (docker build -t blackjack .), it builds without errors. But when I try to run it using docker run blackjack or docker compose up, it complains about the config. And I reviewed the Dockerfile and docker-compose.yml files, which indicate that the config.py file should be copied into the working directory.

d-Rickyy-b commented 1 year ago

The config.py is never included into the container since it contains secrets (such as the bot token). I explicitly excluded it via the .dockerignore file

https://github.com/d-Rickyy-b/Python-BlackJackBot/blob/3d93215a5027ff611e56c6889d3394aefacb4d6e/.dockerignore#L103

Instead you should mount the file via a docker volume.

docker run -v ./config.py:/blackjackbot/config.py blackjack

dfyzicka commented 1 year ago

Thank you very much, I'm just a Docker enthusiast and didn't quite understand it at first, thank you again.