tomsik68 / docker-xampp

Dockerfile to build an image containing XAMPP(MySQL + PHP + PHPMyAdmin) running on Debian system with SSH server
https://hub.docker.com/r/tomsik68/xampp/
MIT License
197 stars 109 forks source link

Separate mysql socket of mysql data #53

Closed sanslash332 closed 1 year ago

sanslash332 commented 1 year ago

Bug Report

I'm running Docker on: wsl

XAMPP start command

I used the following command to start the xampp container:

docker stack deploy -c docker-compose.yml xampp

I've created a compose file with the following content:

version: '3.8'
services:
  xampp:
    image: tomsik68/xampp:7
    ports:
      - 10022:22
      - 10080:80
      - 10443:443
    volumes:
      - "../:/opt/lampp/htdocs"
      # - "~/db:/opt/lampp/var/mysql"
    deploy:
      replicas: 1
      update_config:
        parallelism: 1
        delay: 30s
        order: start-first
    logging:
      driver: json-file
      options:
        max-size: 10m

OK, more explanation here.

If you read carefulli the compose, you see that the volume for the mysql data is commented. ON a simple way, this could work without problem; I did see it on other project; if you mount the directory where the database files are plased you can preserve it without a problem. You can use a bind mount like this, or other kind of docker volume to store the data.

The problem is, that on /opt/lampp/var/mysql/ is too the mysql.sock file; the binding socket for stablish mysql connections on the machine. And these kind of files can't be mounted on a volume, so. If you active the volume, and start the container, mysql says that can't find the mysql.sock file and crash instandly, after create the first db files.

So, the solution for this is edit the /opt/lampp/etc/my.cnf config file, and put the mysql.sock file on other location. something like /opt/lampp/var/sockets/. With that, you can mount your db folder and works without problem. Maybe this change could be as default on the image, to allow people mount the db directory and persist the db data.

I'll check if is easy to do this change on the image to give you a PR :-)

thanks for your work, the image is awesome!

sanslash332 commented 1 year ago

Hello! I have to retreat of my previews issue, because really isn't a problem have the socket on the same folder than the db-data.

So, if you want to use... for example a bind mount,, OK is correct separate the socket and pid from the data it self, but that has the drawback that on mount time the current populated data on the container will by overwriten with the data of the host. And well if you mount a empty folder your database will start empty, that give to you problems because the basic data structure of mysql will be unexistent and with that the database will doesn't work.

This can be util only when you have a existing database data on your host machine and you want to use it directly on the container.

But, well. for a default behavior for have a persistent database on time, you just need to have a named volume mounted on /opt/lampp/var/mysql

example:

docker run -v "db:/opt/lampp/var/mysql" -v "/var/www:/opt/lampp/htdocs/www" -p "8080:80" tomsik68/xampp

And this will work.

If you destroy your container and next restart it. or start a different instanse of it but mounting the same named volume (db) all your old data will keep and still works.

Could be cool put this information on the readme :-)

Thanks.