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

Expose the mysql database #39

Closed Aerics84 closed 2 years ago

Aerics84 commented 2 years ago

I`m running your docker container on my synology. After an update i lost my database. If i map /opt/lampp/var/mysql to a path it create a few databse files in my folder. But phpmyadmin is not working anymore: _mysqli::realconnect(): (HY000/2002): Connection refused

And this is the error from the log: _2022-03-07 13:03:16 0 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded 2022-03-07 13:03:16 0 [ERROR] Can't open and lock privilege tables: Table 'mysql.servers' doesn't exist 2022-03-07 13:03:16 0 [Note] Server socket created on IP: '::'. 2022-03-07 13:03:16 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.db' doesn't exist 2022-03-07 13:03:16 0 [ERROR] Aborting 2022-03-07 13:03:19 137 mysqldsafe mysqld from pid file /opt/lampp/var/mysql/xampp.pid ended

How i can keep the database, if i update the container?

tomsik68 commented 2 years ago

Hello, I'm sorry to hear you lost your database. This container is really intended just for development purposes where the database doesn't need to be preserved.

I believe you need to use Docker volumes to persist data between container migrations. Sorry to say that I don't know how to do that myself. Please refer to the Docker volume reference to find out more.

romarcg commented 2 years ago

I managed to do it using volumes.

The idea is to first create a volume via

docker volume create my_volume

Then mount the volume when running the container in a similar way as it's done with bind, except you indicate the volume type:

docker run --name xamppContainer -p 41061:22 -p 41062:80 -d --mount type=volume,source=my_volume,target=/opt/lampp/var/mysql -v ~/path/to/apache_conf:/opt/lampp/apache2/conf.d -v ~/path/to/www:/www xamppImage:latest

You can inspect the volume via docker volume inspect my_volume to find the path where the volume data is stored.

To save the MyISAM table folders and InnoDB blocks, I set the volume target (in the mount option) to /opt/lampp/var/mysql. The volume driver will populate the volume if the container has files at the target location, which is the case. The volume will keep the persistent data and can be shared with other containers.

See @tomsik68 's link suggestion https://docs.docker.com/storage/volumes/ to find more information regarding volumes.

Note: I'm using podman instead of docker, but the solution is the same.

tomsik68 commented 2 years ago

Thank you for sharing the solution!