Mysql: container volumes not working

Created on 20 Jan 2018  路  11Comments  路  Source: docker-library/mysql

my container is not working when i use volumes in docker-compose.yml file
docker container stop using this

Initializing database
2018-01-20T10:25:42.337424Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-01-20T10:25:42.341018Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2018-01-20T10:25:42.341307Z 0 [ERROR] Aborting
2018-01-20T10:25:42.341374490Z

This is my docker-compose.yml file

services:
  mysqlnet:
    image: mysql:5.7
    container_name: mysqlnet
    volumes:
      - /virtual-server/Docker/lamp/mysql/data:/var/lib/mysql
    ports:
      - "33006:3306"
    environment:
      - "MYSQL_ROOT_PASSWORD=secret"

Without volumes in docker-compose.yml file it is working fine.

Most helpful comment

Found the cause for my problem!

    volumes:
       - dbdata:/var/lib/mysql/data

In my stack file, I was trying to mount the volume to /var/lib/mysql/data but mysql init script checks /var/lib/mysql , whether it's empty or not. Problem solved after changing it to

    volumes:
       - dbdata:/var/lib/mysql

PS: Just saw that this has been pointed out by @tianon on #290 's thread, though the cause for that user's problem seems to be different.

All 11 comments

The workaround for issue #361 worked for me on MacOS

@romulodl I tried your suggestion, but stile getting same error :(

This definitely needs more information for folks to be able to help you effectively.

How are you running Docker (native Linux install, Docker for Mac, Docker for Windows, Docker Toolbox, etc)? Is /virtual-server/Docker/lamp/mysql/data on a filesystem that MySQL supports? Does it exist (and is it an empty directory) before you try to start the container?

Since we can't reproduce a failure while using a volume, I'm going to close (because this appears either environmental or usage-related); for additional help, I'd recommend posting to the Docker Community Forums, the Docker Community Slack, or Stack Overflow. Thanks!

@kdsonit i added innodb_use_native_aio=0 to the docker.cnf of mysql.

@tianon I am running Docker using Docker Toolbox for Windows 7.

@kdsonit, what is in /virtual-server/Docker/lamp/mysql/data on your host? It must be empty or an already initialized database. That would be why you get the data directory has files in it. Aborting. error.

Similar issues: #69, #186, #290

@yosifkit /virtual-server/Docker/lamp/mysql/data It is an empty directory that i want to store all files for backup.

Docker Toolbox only sets up a shared folder for C:\users from Windows host to Linux VM. That doesn't look like a Windows path, so as far as I can tell Docker will be creating that directory inside the VM with no connection to the Windows host and using it. In the default setup that should just work (minus the fact that it would get deleted every reboot of the VM, since it is not in the persistent storage area)

Did you setup a second Shared Folder via VirtualBox to share "C:\virtual-server" to the VM as /virtual-server/? Is it an NFS mount in the VM? Something else?

Did you mean the absolute path /virtual-server/Docker/lamp/mysql/data or the relative one ./virtual-server/Docker/lamp/mysql/data in your compose file?

@yosifkit Yes, I already setup /virtual-server/ folder to VirtualBox and it is mount successfully. Because i also setup other containers from this folder like /virtual-server/Docker/lamp/72/apache/www/:/var/www/html all are working fine.

Same problem here..

I'm running docker(native linux install) on ubuntu 16.04

Docker version 17.12.0-ce, build c97c6d6
docker-compose version 1.18.0, build 8dd22a9

My stack file looks something like this

version: "3.3"
services:
  mysql:
    image: mysql:5.7
    # command: "--innodb_use_native_aio=0",
    # command: '--ignore-db-dir=lost+found'
    ports:
      - 3306:3306
    volumes:
       - dbdata:/var/lib/mysql/data
    networks:
       - mynet
    environment:
      MYSQL_ROOT_PASSWORD: secretpw
      MYSQL_DATABASE: dbname
      deploy:
        # replicas: 2
volumes:
  dbdata:
networks:
  mynet:

After docker swarm init and docker stack deploy -c stack.yml mystack, below is the log from docker service logs mystack_mysql -f

mystack_mysql.1.eko3wwars8sm@oo    | Initializing database
mystack_mysql.1.eko3wwars8sm@oo    | 2018-02-12T07:07:33.641969Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mystack_mysql.1.eko3wwars8sm@oo    | 2018-02-12T07:07:33.645653Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
mystack_mysql.1.eko3wwars8sm@oo    | 2018-02-12T07:07:33.645696Z 0 [ERROR] Aborting
mystack_mysql.1.eko3wwars8sm@oo    |
mystack_mysql.1.sfxfmmwrzcy2@oo    | Initializing database
mystack_mysql.1.sfxfmmwrzcy2@oo    | 2018-02-12T07:07:42.247086Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mystack_mysql.1.sfxfmmwrzcy2@oo    | 2018-02-12T07:07:42.250934Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
mystack_mysql.1.sfxfmmwrzcy2@oo    | 2018-02-12T07:07:42.251150Z 0 [ERROR] Aborting
mystack_mysql.1.sfxfmmwrzcy2@oo    |

Then I terminated the deployment with docker stack rm mystack .
Now, docker volums ls gives

DRIVER              VOLUME NAME
local               a8cf621cfa96eddc64c9a6d4a514ed7e58f3e8ef624b303e9e8e68e049453064
local               fd81075fed55e608f7dacf005939c686a994a332f6b511636d7ea7d43065693c
local               mystack_dbdata

I didn't create the volume mystack_dbdata manually, prior to deploy command.
docker inspect mystack_dbdata gives ..

[
    {
        "CreatedAt": "2018-02-12T12:38:25+05:30",
        "Driver": "local",
        "Labels": {
            "com.docker.stack.namespace": "mystack"
        },
        "Mountpoint": "/var/lib/docker/volumes/mystack_dbdata/_data",
        "Name": "mystack_dbdata",
        "Options": {},
        "Scope": "local"
    }
]

The mount point is empty too. sudo ls /var/lib/docker/volumes/mystack_dbdata/_data -al gives

total 8
drwxr-xr-x 2  999 docker 4096 Feb 12 12:37 .
drwxr-xr-x 3 root root   4096 Feb 12 12:37 ..

There are a couple more threads with similar problem, I have tried these suggestions

   # command: "--innodb_use_native_aio=0",
   # command: '--ignore-db-dir=lost+found'

but no success.

can someone help me please. @kdsonit were you able to solve this?
@yosifkit @tianon Any suggestions?

69 , #290

Found the cause for my problem!

    volumes:
       - dbdata:/var/lib/mysql/data

In my stack file, I was trying to mount the volume to /var/lib/mysql/data but mysql init script checks /var/lib/mysql , whether it's empty or not. Problem solved after changing it to

    volumes:
       - dbdata:/var/lib/mysql

PS: Just saw that this has been pointed out by @tianon on #290 's thread, though the cause for that user's problem seems to be different.

Was this page helpful?
0 / 5 - 0 ratings