/var/lib/mysql/mysql.sock is not created sometimes

I have been using a self-built mariaDB container in a stack for many years. Now I have set up a new machine based on Debian and found that the container is not running.

The cause is simply that /var/lib/mysql/mysql.sock cannot be found within the container. Various authors have searched for this error several times, but there is no convincing solution anywhere.

It is the same image that also runs perfectly under Ubuntu and has run for years under coreOS 8. How can the creation of the /var/lib/mysql/mysql.sock depend on the underlying operating system?

Incidentally, I have occasionally noticed the same misbehavior under Ubuntu, but have not been able to clarify it further. So the error does not seem to depend on the underlying operating system.

And this is also in line with expectations. Docker containers are supposed to run identically and flawlessly in every environment, which is one of the advantages of containerization.

As far as I know, the socket is created automatically when the server is started in the container. However, this seems to fail under certain circumstances. I have made sure that there is enough space both in RAM and on the hard disk. Incidentally, mysql.sock hardly takes up any space.

How can I understand this error?

What are the circumstances and how can the error be corrected?

Are you running the same commands? Would you please show it and/or the compose files?

Yes, the machines are set up identically, copied from the coreOS 8 original.

I start with a batch job ~/bin/1up

/usr/bin/docker swarm init
/usr/bin/docker network create -d overlay --attachable proxy
docker stack deploy -c   /root/external.net/wp/docker-compose.yml wp --detach=false
docker compose -f /root/external.net/1proxy/docker-compose.yml up -d 

Here is my docker-compose.yml for the stack:

# 2020-05-20 18:02 

networks:
  back_ntw:
  proxy:
    external: true  

services:

#-- WEB CLIENT =======================================================
  wp:                                                     # 
    image: kklepper/nginx-php7-mysqli-memcached:alpine
    hostname: wp
    environment:
      - HOST_HOSTNAME={{.Node.Hostname}}
    depends_on:
      - master
    volumes:
      - /var/www/:/var/www/
      - /tmp:/tmp
      - /etc/php:/etc/php
      - /etc/nginx/nginx.82.conf:/etc/nginx/nginx.conf  # ???
    networks:
      - proxy
      - back_ntw

#-- DATABASE CLIENT =======================================================
  master:
    image: kklepper/mariadb33:alpine
    command: "/start-v3.sh"
    hostname: master
    volumes:
      - /tmp:/tmp
      - /var/lib/mysql:/var/lib/mysql
      - /etc/mysql:/etc/mysql   
    environment:
      - MYSQL_ROOT_PASSWORD=mypassword
    networks:
      - proxy           
      - back_ntw

# ADMINER =======================================================
  adm:
    image: adminer:latest
    ports:
      - 8071:8080      
    environment:
      - ADMINER_DEFAULT_SERVER=master
    networks:
      - proxy           # for web
      - back_ntw        # for master

# JOE ======================================================= 
  joe:                                                   
    image: kklepper/nginx-php7-mysqli-graphicsmagick:alpine 
    hostname: joe
    environment:
      - HOST_HOSTNAME={{.Node.Hostname}}
    depends_on:
      - master
    volumes:
      - /root/external.net/wp/nginx_joe.conf:/etc/nginx/nginx.conf
      - /var/www/myexample.com:/var/www/myexample.com
      - /tmp:/tmp
      - /etc/php:/etc/php
    networks:
      - back_ntw
      - proxy

And here is the docker-compose.yml for the proxy:

# 2020-05-23 22:28 

networks:
  nc:  
  proxy:
    external: true  

services:
  nginx: 
    image: kklepper/nginx-php7-mysqli-memcached:alpine
    volumes:
      - /etc/nginx/nginx.conf.443:/etc/nginx/nginx.conf    
      - /etc/letsencrypt:/etc/letsencrypt
      - /var/www/:/var/www/
      - /tmp:/tmp
    environment:
      - ENV=development
    ports:
      - 80:80
      - 443:443
    networks:
      - nc
      - proxy

What are the errors you’re getting?

Are the mounted host files’ contents and location the same?

And as the proxy network is external, is it set the same?

1 Like

Yes, everything is identical.

This is the error that the container displays in the log:

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2 “No such file or directory”)

And this error is repeated 60 times until the machine gives up.

But I have found out something. The machine on which the container is running properly has 1 GB RAM, the machine with the error only has 0.5 GB of RAM. I have now set up a swap file with 1 GB RAM there.

The container is now running correctly. The error therefore seems to be related to the lack of memory.

However, the log file also shows the error mentioned above, but surprisingly the server starts nevertheless:

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2 “No such file or directory”)
mariadb33 => Waiting for confirmation of MySQL service startup DONE

And I can access the database via the container:

id=master && my=$(docker ps -a | grep “$id.” | grep -v “xited” | awk ‘{print $1}’) && $(docker exec -it $my mysql -e “SET GLOBAL max_connections = 1000”) && docker exec -it $my mysql my_db
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.1.26-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [my_db]> SHOW TABLES LIKE ‘%’;

At the moment, the case seems to be halfway resolved. As long as I don’t get this error again, I can’t investigate further. It remains strange that the creation of the socket should have been prevented by the lack of memory and that the error also occurs when setting up a swap file, but has no effect.

I am waiting for an explanation.

Oh, I forgot to say that I replaced debian on the faulty machine with ubuntu 24.04 as well as this error did not relate to the OS version.