hi
this is my compose file
version: '2'
services:
sonarqube:
image: sonarqube:5.1.2
ports:
- "9000:9000"
restart: always
depends_on:
- "db"
environment:
- "SONARQUBE_JDBC_USERNAME="
- "SONARQUBE_JDBC_PASSWORD="
- "SONARQUBE_JDBC_URL=jdbc:mysql://db:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false"
volumes:
- /media/windows-share/docker-sonar-volume/sonar/data:/opt/sonarqube/data
- /media/windows-share/docker-sonar-volume/sonar/conf:/opt/sonarqube/conf
- /media/windows-share/docker-sonar-volume/sonar/extensions:/opt/sonarqube/extensions
db:
image: mysql:latest
restart: always
environment:
- "MYSQL_ROOT_PASSWORD="
- "MYSQL_DATABASE="
- "MYSQL_USER="
- "MYSQL_PASSWORD="
volumes:
- /media/windows-share/docker-sonar-volume/var/lib/mysql:/var/lib/mysql/data
i tried chaging the volume path, but mysql isn't persisting the exisiting data. or it is showing this initialization error. please help me out i stuck with this issue from 3 days. also i am attaching my screenshot error.
i tried emptying the directory too but no luck.

The issue is that the check to see if the $DATADIR exists is wrong in the docker-entrypoint.sh script, I'll submit my fix
Hi, really appreciate for the reply. i am new to this whole docker and terminal using stuff. can you please explain a little bit in detail how to resolve this. TIA
I think
- /media/windows-share/docker-sonar-volume/var/lib/mysql:/var/lib/mysql/data
should be instead
- /media/windows-share/docker-sonar-volume/var/lib/mysql:/var/lib/mysql
(just /var/lib/mysql as the mount target, which is the defined VOLUME of this image -- see https://github.com/docker-library/mysql/blob/6b1dc54320b03b83a89068f49cc796fea0ff6bb4/5.7/Dockerfile#L68)
changed it to the path .. still same error
The entrypoint script checks if DATADIR/mysql exists. If not, it runs --initialize, but if DATADIR/ contains any files other than ones starting with . or specified with --ignore-db-dir, --initialize will fail with that error message.
So the directory you map to :/var/lib/mysql should either contain an existing MySQL database or be completely empty
@ltangvald mysql directory is clean no files in it. here i am attaching the screen shot

I am confused. You did ls on /var/lib/mysql in your vagrant VM, but what you are mounting to the container is /media/windows-share/docker-sonar-volume/var/lib/mysql.
Hi @yosifkit .. he (@ltangvald ) mentioned about right side of the ":" i.e :/var/lib/mysql thats why i showed ls on that.
if i ls on '/media/windows-share/docker-sonar-volume/var/lib/mysql' this will show me all the exisiting the sonar data. thats my requirement; so, i pointed mysql to that host path to start with already existing sonar data.
The right side, ie /var/lib/mysql, is relative to the file system in the container, not the VM. So using your compose file will mount the /media/windows-share/docker-sonar-volume/var/lib/mysql directory as /var/lib/mysql in the container, so its contents are very relevant. It should either be empty so that starting the MySQL container will fill it with its initial database files, or it should be already populated by a previous MySQL server (the MySQL server major/minor version, like "5.7", should be the same, though there are ways to upgrade between versions).
It should look something like the following. The database file that we look for in the entrypoint script to determine if the folder already contains an initialized database is mysql.
root@39ae6038c8e2:/# ls -l /var/lib/mysql
total 188476
-rw-r----- 1 mysql mysql 56 Apr 28 23:04 auto.cnf
-rw------- 1 mysql mysql 1679 Apr 28 23:04 ca-key.pem
-rw-r--r-- 1 mysql mysql 1074 Apr 28 23:04 ca.pem
-rw-r--r-- 1 mysql mysql 1078 Apr 28 23:04 client-cert.pem
-rw------- 1 mysql mysql 1679 Apr 28 23:04 client-key.pem
-rw-r----- 1 mysql mysql 1321 Apr 28 23:04 ib_buffer_pool
-rw-r----- 1 mysql mysql 50331648 Apr 28 23:04 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Apr 28 23:04 ib_logfile1
-rw-r----- 1 mysql mysql 79691776 Apr 28 23:04 ibdata1
-rw-r----- 1 mysql mysql 12582912 Apr 28 23:04 ibtmp1
drwxr-x--- 2 mysql mysql 4096 Apr 28 23:04 mysql
drwxr-x--- 2 mysql mysql 4096 Apr 28 23:04 performance_schema
-rw------- 1 mysql mysql 1675 Apr 28 23:04 private_key.pem
-rw-r--r-- 1 mysql mysql 451 Apr 28 23:04 public_key.pem
-rw-r--r-- 1 mysql mysql 1078 Apr 28 23:04 server-cert.pem
-rw------- 1 mysql mysql 1675 Apr 28 23:04 server-key.pem
drwxr-x--- 2 mysql mysql 12288 Apr 28 23:04 sys
i copied my previous sonar db data into the host directory. if i ls on /media/windows-share/var/lib/mysql then it will be like below screen shot.

may be that why i am getting this error. can you please tell me what shall i do to make my mysql to pick that existing sonar data while starting up.
thanks for all the suggestions .. :)
Those are sql scripts, not a database. Are those the output from a dump operation you want to restore to a docker database?
If those are dump files that can be used to restore the database, you might be able to instead map that directory to /docker-entrypoint-initdb.d/ (but I'm not sure if the ordering will be correct).
The contents of var/lib/mysql should be as yosifkit posted above
@ltangvald yes those from mysql dump. thanks for the suggestion i will try that option
I have same issue but no solution works.
$ docker logs cyrano-project_mysql_1
Initializing database
2018-08-06T06:36:48.947657Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2018-08-06T06:36:48.947796Z 0 [ERROR] Aborting
The Error: "initialize specified but the data directory has files in it" could happen if your system is probably out of disk space. Mysql is writing partial data to test the system. If you see a file: "ibdata1" in your volume this test failed. So check if you have free disc space, delete the file: "ibdata" or remove the volume and start/restart again...
remove all files in {path-to-mysql}\data directory and run:
mysqld --initialize-insecure --basedir={path-to-mysql}\mysql --datadir={path-to-mysql}\data --console
I just ran into this issue using the mysql docker image on my local Mac OS environment. As @koljakutschera mentioned, this seems to be an issue with space. I ran docker system prune --volumes on my system, which freed 45.86GB of space, solving the issue. Be advised that this is a destructive command, I only tested it on my local dev environment.
@rqc It worked! What I don't understand is why it worked, I had 12GB free, when I did docker system prune --volumes, recovered 24GB
But yeah it worked!
I just ran into this issue using the
mysqldocker image on my local Mac OS environment. As @koljakutschera mentioned, this seems to be an issue with space. I randocker system prune --volumeson my system, which freed45.86GBof space, solving the issue. Be advised that this is a destructive command, I only tested it on my local dev environment.
docker system prune --volumes fix my problem
@rqc Why does docker system prune --volumes work when you already had 12GB of free space. How much space is needed to start this database up ?
Hi, sorry for the late reply. docker can leave dangling data from volumes. If you look at the docker prune documentation it says:
By default, volumes are not removed to prevent important data from being deleted if there is currently no container using the volume. Use the --volumes flag when running the command to prune volumes as well:
docker system prune --volumes worked !!
@apigban @tonyg4864 There's a difference between how much disk space you have and how much disk space docker is still allowed to access. On Mac you can see how much Docker can use by clicking the docker icon in the top bar -> preferences -> resources:

In my case the issue occured when mounting a directory from my c drive when using Windows Subsystem for Linux 2 (WSL2). Mounting a directory from my user directory of the wsl linux system worked fine.
If I understand correctly this seems to be a known issue in docker for windows occurring for named volumes: https://github.com/docker/for-win/issues/4812
I am on Mac OS and is brand new but I had the same issue
docker system prune --volumes worked
Does any one have idea what this does
That's deleted all unused Docker volumes on your system (and containers, and untagged images); https://docs.docker.com/engine/reference/commandline/system_prune/
Most helpful comment
I just ran into this issue using the
mysqldocker image on my local Mac OS environment. As @koljakutschera mentioned, this seems to be an issue with space. I randocker system prune --volumeson my system, which freed45.86GBof space, solving the issue. Be advised that this is a destructive command, I only tested it on my local dev environment.