I am kinda new to Docker and I am trying to build an image for a Django App using MySQL. The problem that I am having is, after running my image I get the following error : django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)") . As a base for the image I am using FROM django:python2 , I have installed the server using the following commands:
RUN echo "mysql-server mysql-server/root_password password X" | debconf-set-selectionsRUN echo "mysql-server mysql-server/root_password_again password X" | debconf-set-selectionsRUN apt-get update && apt-get install -y mysql-server
To fix the problem I tried multiple solutions, which I found on the internet such as:
RUN touch /var/run/mysqld/mysqld.sockRUN chmod -R 755 /var/run/mysqld/mysqld.sockEXPOSE 3306
Sadly, nothing worked. I also made sure the server is running, yet the problem is still there.
Dockerfileanddocker-compose.ymlfiles. The database settings insettings.pycould also help provide some insight.Dockerfilein the post except theapt-getfor different modules etc. As for thedocker-composeI wrote something briefly and it failed with the same error, so I decided to first get myDockerfilerunning.docker exec -it [your container name here] /bin/bashwill give you a shell where you can do some debugging. From inside the container you can try to see if mysql is even running (it doens't look like it is):/etc/init.d/mysql statusRUN service mysql startHOSTto in your database config ?