Search code examples
mysqlmacospermissionsdockervolumes

Docker - can not start mysql permission error


I have problem with docker and mysql. I have build an image based on phusion/baseimage. I want to create image where /var/lib/mysql directory is shared with my host (OS X), because I dont want to store my data on container.

Everything works fine when directory /var/lib/mysql is not shared. When I share this directory, mysql service can not start. In logs are informations about problems with permissions while starting.

Result of ls -la from /var/lib is:

[...]
drwxr-xr-x  1 lc      staff    170 Jan  3 16:55 mysql
[...]

The mysql user should be an owner. I tried to do:

sudo chown -R mysql:mysql mysql/

But this command didn't return any error and didn't change owner.

I have also tried to add my user (from container) to mysql group:

lc@cbe25ac0681e:~$ groups lc
lc : lc sudo mysql

But It also didn't work. Have anybody any idea how to solve this issue?

My docker-compose.yml file:

server:
  image: lukasz619/light-core_server
  ports:
    - "40080:80"
    - "40022:22"
    - "40443:443"
    - "43306:3306"
  volumes:
     - /Users/lukasz/Workspace/database/mysql:/var/lib/mysql

This is my Dockerfile:

FROM phusion/baseimage

RUN apt-get update
RUN apt-get install -y apache2

# Enable SSH
RUN rm -f /etc/service/sshd/down
RUN /etc/my_init.d/00_regen_ssh_host_keys.sh

# public key for root
ADD public_key.pub /tmp/public_key.pub
RUN cat /tmp/public_key.pub >> /root/.ssh/authorized_keys && rm -f /tmp/public_key.pub

EXPOSE 80
CMD ["/sbin/my_init"]
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

Solution

  • The problem is OS X.. I ran this docker-composer.yml

    server:
      image: lukasz619/light-core_server
      ports:
        - "40080:80"
        - "40022:22"
        - "40443:443"
        - "43306:3306"
      volumes:
          - /var/mysql:/var/lib/mysql
    

    Its possible to share directories (and do chown) ONLY between boot2docker and container, but do not work properly shareing between Os X and container.