0

I have a "point of sales" application in Django that uses a mysql database.
I followed this Docker guide: Python getting started guide

In order to setup the mysql container I created a couple of volumes and its network:

docker volume create mysql
docker volume create mysql_config

docker network create mysqlnet

My Dockerfile looks like this:
(I don't want to use docker-compose yet becouse I want to learn the bases)

Dockerfile

# syntax=docker/dockerfile:1

FROM python:3.8-slim-buster

RUN apt update
RUN apt upgrade -y
RUN apt dist-upgrade
RUN apt-get install procps -y
RUN apt install curl -y
RUN apt install net-tools -y

WORKDIR /home/pos

COPY requirements.txt ./.

RUN pip3 install -r requirements.txt

COPY ./src ./src

CMD ["python", "./src/manage.py", "runserver", "0.0.0.0:8000"]

And in the Django project my database settings and requirements looks like:

settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'point-of-sales',
        'USER': 'root',
        'PASSWORD': 'r00t',
        'HOST': 'localhost',
        'PORT': '3307'
    }
}

requirements.txt

# Django
django>=3.1,<3.2

# DRF
djangorestframework>=3.12,<3.13

# Databases
mysqlclient

What I want is to build an image of the Django application that I could run and attach to the mysql network.

The problem is that I can't build the image of my django app becouse it throws the following error when trying to install mysqlclient:

OSError: mysql_config not found

Looking around I found another topic that suggest to install mysql-config which is another package but I want to kept everything of mysql isolated in the mysql container.

Is there any way to do that without using docker-compose?

  • 1
    You need the client libraries installed in your container to connect to the database, which is where the `mysql_config` command comes in. You do in fact need to install it in your image, in the same way you need the `mysqlclient` Python package listed in your `requirements.txt` file. – David Maze Apr 24 '22 at 21:02
  • 1
    Also please [don't use](https://stackoverflow.com/questions/23176592/deploying-django-by-python-manage-py-runserver-to-production-on-vps) `manage.py runserver` for production deployment, it is considered a bad practice ([docs](https://docs.djangoproject.com/en/4.0/ref/django-admin/#runserver)). – STerliakov Apr 24 '22 at 21:47
  • 1
    So deployment is [wsgi](https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/), with [gunicorn test:app](https://docs.gunicorn.org/en/latest/run.html), [uwsgi](https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/uwsgi/#configuring-and-starting-the-uwsgi-server-for-django) etc? Suggest someone knowledgeable update [docker hub](https://hub.docker.com/_/django) [docs](https://github.com/docker-library/docs) since it seems like a common copying point. – danblack Apr 24 '22 at 22:34
  • Oh thanks everyone for the suggestions! I learn from all your comments, just to clarify, this is not a real app, is a small project to learn about docker and CI/CD pipelines, here is the repo if you want to check it out: https://github.com/santiagortiiz/Point-of-sale-Python-Django-CICD – Santiago Ortiz Ceballos Apr 24 '22 at 22:47

0 Answers0