Search code examples
dockerpercona

How to mount data directory?


I am not able to start percona mysql dockerized instance if I try to mount the data directory like this:

docker run --name percona57f -p 3384:3306 -v /my/custom3384:/etc/mysql/conf.d -v /storage/data3384:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=india3384 -e INIT_TOKUDB=1 -d percona/percona-server:5.7 

The error is as shown below:

[ERROR] --initialize specified but the data directory exists and is not writable. Aborting.
[ERROR] Aborting

The command will work if I do not include the data directory like this...

docker run --name percona57g -p 3384:3306 -v /my/custom3384:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=india3384 -e INIT_TOKUDB=1 -d percona/percona-server:5.7 

But it is very important for me to mount the data directory on host machine. Any way to enable this -v /storage/data3384:/var/lib/mysql


Solution

  • Run this command before docker run:

    chown 1001 /my/custom3384
    

    This is the UID for the mysql user, as shown in the Dockerfile for the percona image:

    https://github.com/percona/percona-docker/blob/master/percona-server/Dockerfile

    RUN useradd -u 1001 -r -g 0 -s /sbin/nologin \
                -c "Default Application User" mysql