I want to deploy a small Python app that connects with a (currently running locally) MySQL server. Within ./fzwk-app/ I created a module database with DBController.py:
class DbController(object):
def __init__(self):
self._db_connection = mysql.connector.connect(
host='localhost',
user='foo',
passwd='bar',
database='mydb'
)
self._db_cur = self._db_connection.cursor()
# ...
When running my small app by running ./fzwk-app/__init__.py locally on my dev device, the db connection works just fine.
Now I wanted to start deploying to a docker container.
First, I set up the Dockerfile like this:
FROM python:3.6
ADD ./fzwk-app/ /
RUN pip3 install mysql-connector
CMD [ "python", "./__init__.py" ]
Building the Docker Image works just fine (docker build -t fzwk-app:0.1 .), but when I try to create and run a container (docker run fzwk-app), I am greeted with the following Python traceback:
Traceback (most recent call last):
File "./__init__.py", line 21, in <module>
from database import DbController as db
File "/database/DbController.py", line 18, in <module>
import mysql.connector
ModuleNotFoundError: No module named 'mysql'
Where's my mistake?
docker-compose.ymlsetup; for now my task is just to create an image that will work an run my small Python app... So, no need to expose anything so far...