I am learning docker these days, and starts with building mysql image by myself.
Dockerfile:
FROM centos MAINTAINER Michael ENV REFRESHED_AT 2016-07-29 RUN yum install -y mysql mariadb-server VOLUME /var/lib/mysql ENTRYPOINT ["/usr/libexec/mysqld", "--user=root"] EXPOSE 3306 docker run command
docker run -d --name mysql -v /root/docker/mysql/data:/var/lib/mysql -p 3306:3306 michael/mysql This gave an error because I have to exec mysql_install_db first to init DB. But I could not add RUN mysql_install_db in the Dockerfile since I want to use Volume as external data store.
So how should I do this ?
I know there's an official image named mysql. I just want to do this as practice.
UPDATE: Thanks to @Pieter . I finally did this by using his solution which is provide another entrypoint.sh combines init & start scripts then make it as ENTRYPOINT in Dockerfile :
FROM centos MAINTAINER Michael ENV REFRESHED_AT 2016-07-29 RUN yum install -y mysql mariadb-server VOLUME /var/lib/mysql COPY entrypoint.sh /usr/local/bin/ ENTRYPOINT ["entrypoint.sh"] EXPOSE 3306 entrypoint.sh
#!/bin/bash if [ ! -d "/var/lib/mysql/mysql" ]; then #check whether the DB is initialized. echo 'Initializing database' mysql_install_db echo 'Database initialized' fi /usr/libexec/mysqld --user=root docker run
docker run -d --name mysql -v /root/docker/mysql/data:/var/lib/mysql -p 3306:3306 michael/mysql And this gives a generic solution for such scenario.