简体   繁体   中英

Mysql server on docker container

Using Dockerfile to buils mysql-sever 5.7 image with ubuntu:16.04 (customized) . When building an image without specifying - v arguments, mysql- server inside container starting successfully.

But for container persistency, when using - v with / my own/ hostdirectory:/var/lib/mysql , then mysql- server not starting when running command, service mysql restart inside the container itself... Please answer if anyone has an idea about it.

Dockerfile:

FROM ubuntu:16.04 RUN apt-get -y update && \\ apt-get -y dist-upgrade && \\ apt-get -y autoremove && \\ apt-get -y clean RUN echo "mysql-server-5.7 mysql-server/root_password password root" | debconf-set-selections RUN echo "mysql-server-5.7 mysql-server/root_password_again password root" | debconf-set-selections RUN apt-get -y -f install mysql-server-5.7 EXPOSE 3306

Thanks

There are at least two requirements for mounted mysql data directory to work:

  1. It has to be readable and writable for mysql process
  2. It has to either contain valid mysql data or be initialized during container bootstrap

The best way to handle both probles is to build image with appropriate entrypoint, that will ensure valid permissions of mysql data directory and performs its initialization if needed.

Please take a look how official mysql image takes care of mounted mysql data directory: https://github.com/docker-library/mysql/blob/master/5.7/docker-entrypoint.sh#L80-L200

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM