2

Problem

Using a data container to store the MySQL data does not work properly if I mount the parent directory /var/lib instead of /var/lib/mysql

Infrastructure

I'm using 3 docker containers to provide a website:

  • nginx container to run a webserver
  • mariadb container for the database
  • data container for the created user data

The data container is created using the following docker command:

$ docker create \
     -v /var/lib \
     -v /var/www \
     --name [appname]-data \
     tianon/true /bin/true

Checking the available mounts for [appname]-data with $ docker inspect [appname]-data:

"Mounts": [
        {
            "Name": "361ed7b3e38371653f2df75652973e1c48db52d59c4c5371f634c1930291af0c",
            "Source": "/var/lib/docker/volumes/361ed7b3e38371653f2df75652973e1c48db52d59c4c5371f634c1930291af0c/_data",
            "Destination": "/var/lib",
            "Driver": "local",
            "Mode": "",
            "RW": true,
            "Propagation": ""
        },
        ...

The containers are started with docker-compose. Both containers should use all mounts available on the data container. My docker-compose.yml:

[appname]-nginx:
  container_name: [appname]-nginx
  image: nginx:9-apache
  links:
    - [appname]-mariadb:mysql
  volumes_from:
    - [appname]-data
  restart: always
  expose:
    - "80"

[appname]-mariadb:
  image: mariadb:10.1
  container_name: [appname]-mariadb
  restart: always
  volumes_from:
    - [appname]-data
  environment:
    MYSQL_ROOT_PASSWORD: pas$w0rd
    TERM: dumb

The output of $ docker exec -it [appname]-nginx ls -lha /var/lib/mysql:

total 8.0K
drwxr-xr-x 2 root root 4.0K Jun 27 16:30 .
drwxr-xr-x 3 root root 4.0K Jul 21 10:19 ..

The output of $ docker exec -it [appname]-mariadb ls -lha /var/lib/mysql:

total 109M
drwxr-xr-x 4 mysql mysql 4.0K Jul 21 10:19 .
drwxr-xr-x 3 root  root  4.0K Jul 21 10:19 ..
-rw-rw---- 1 mysql mysql  16K Jul 21 07:57 aria_log.00000001
-rw-rw---- 1 mysql mysql   52 Jul 21 07:57 aria_log_control
-rw-rw---- 1 mysql mysql  48M Jul 21 07:57 ib_logfile0
-rw-rw---- 1 mysql mysql  48M Jul 21 07:56 ib_logfile1
-rw-rw---- 1 mysql mysql  12M Jul 21 07:57 ibdata1
-rw-rw---- 1 mysql mysql    0 Jul 21 07:56 multi-master.info
drwx------ 2 mysql mysql 4.0K Jul 21 07:57 mysql
drwx------ 2 mysql mysql 4.0K Jul 21 07:56 performance_schema
-rw-rw---- 1 mysql mysql  24K Jul 21 07:57 tc.log

Executing mount on both containers shows the same:

/dev/dm-0 on /var/lib type ext4 (rw,relatime,data=ordered)
/dev/dm-0 on /var/www type ext4 (rw,relatime,data=ordered)

However for [appname]-mariadb has an additional mount for /var/lib/mysql exists:

/dev/dm-0 on /var/lib/mysql type ext4 (rw,relatime,data=ordered)

Question

Why is it not possible to create a volume mount on /var/lib to save all stored data in the data container?

Do I miss something?

Is it a problem of MySQL / MariaDB?

0

Why don't you create your docker volume from docker-compose.yml as well? The following should work:

version: '2'                       

services:                          
  nginx:                           
    image: nginx:9-apache          
    expose:                        
      - '80'                       
    volumes:                       
      - app-data:/var/www          
  mariadb:                         
    image: mariadb:10.1            
    volumes:                       
      - app-data:/var/lib          
    environment:                   
      MYSQL_ROOT_PASSWORD: pas$w0rd
      TERM: dumb                   

volumes:                           
  app-data:

I wonder why you'd want both containers to store their data on the same volume though. I'd imagine it preferable to store nginx's and mariadb's data in separate volumes.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.