Score:0

Docker Debian: ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock' (111)

ss flag

On a Debian 12 container: I have the ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock' (111).

The mariadb service is started but doesn't works.

This is my Dockerfile:

FROM debian:latest
EXPOSE 80/tcp
EXPOSE 3306/tcp
EXPOSE 22/tcp
RUN export LANG=fr_FR.UTF-8
RUN apt clean
RUN apt update
RUN apt install -y curl lsb-release apt-transport-https software-properties-common
RUN add-apt-repository contrib
RUN add-apt-repository non-free
RUN dpkg --configure -a
RUN apt clean
RUN apt update
RUN apt install -y python3.11
RUN rm /usr/lib/python3.11/EXTERNALLY-MANAGED
RUN curl -o get-pip.py https://bootstrap.pypa.io/get-pip.py
RUN python3 get-pip.py
RUN mkdir -p /etc/apt/keyrings
RUN curl -o /etc/apt/keyrings/mariadb-keyring.pgp 'https://mariadb.org/mariadb_release_signing_key.pgp'
RUN curl -sSL https://packages.sury.org/php/README.txt | bash -x
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
RUN apt clean
RUN apt update
RUN apt upgrade -y
RUN apt install -y openssl python3-cryptography nodejs
RUN apt install -y sudo nano openssh-server apache2 libapache2-mod-fcgid libapache2-mpm-itk php php-fpm php-mbstring php-zip php-intl php-imagick php-mysql php-ps php-bcmath php-bz2 php-cli php-curl php-date php-geoip php-mail php-psr php-xml php-yaml mariadb-server mariadb-client
RUN service apache2 stop
RUN a2dismod mpm_itk php$(php -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;")
RUN a2dismod mpm_prefork
RUN a2enmod mpm_event
RUN a2enconf php$(php -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;")-fpm
RUN a2enmod proxy
RUN a2enmod proxy_fcgi
RUN a2enmod rewrite
RUN npm install -g npm
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php composer-setup.php
RUN php -r "unlink('composer-setup.php');"
RUN mv composer.phar /usr/local/bin/composer
RUN sed -i 's/^bind-address\s*=.*/bind-address = 0.0.0.0/' /etc/mysql/my.cnf
RUN service mariadb start
RUN mysql -u root -e "CREATE USER 'docker'@'%' IDENTIFIED BY 'docker';"
RUN mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'docker'@'%' WITH GRANT OPTION;"
RUN mysql -u root -e "FLUSH PRIVILEGES;"
RUN service mariadb stop
VOLUME /var/www/html
CMD service php$(php -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;")-fpm start && service apache2 start && service mariadb start && service ssh start && bash -c "while true; do sleep 3600; done"

[39/42] RUN mysql -u root -e "CREATE USER 'docker'@'%' IDENTIFIED BY 'docker';": #0 0.243 ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock' (111)


Dockerfile:42

djdomi avatar
za flag
it looks for me that the daemon is not listening to the specific path you provide
danblack avatar
dz flag
[see reasons](https://stackoverflow.com/questions/76550551/cant-load-sql-dump-to-the-containered-mariadb/76552495#76552495). Its not a VM and doesn't have a service manager. Use docker-compose and put ~4 connected services.
danblack avatar
dz flag
Also see comments/links on [this question](https://stackoverflow.com/questions/76644222/mariadb-docker-dockerfile).
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.