Docker Community Forums

Share and learn in the Docker community.

MariaDB docker images build failed


(Gladiator67) #1

I try to build MariaDB docker image which contains database, table and simple values. But it failed and even more, I can’t find any log. This is my Dockerfile,

FROM centos:centos7

RUN yum install -y mariadb-server mariadb
RUN mysql_install_db --user=mysql --ldata=/var/lib/mysql/
ADD my.cnf /etc/
RUN sed -i ‘/[mysqld]/aport=3306’ /etc/my.cnf

RUN \
echo “/usr/bin/mysqld_safe --basedir=/usr &” > /tmp/config && \
echo “cat /var/log/mariadb/mariadb.log” >> /tmp/config && \
echo “mysqladmin -u mysql password 11111” >> /tmp/config && \
echo “mysql -u mysql -p -h localhost test” >> /tmp/config &&
bash /tmp/config && \
rm -f /tmp/config

RUN
echo “use test” > /tmp/config1 &&
echo "mysql -e ‘GRANT ALL PRIVILEGES ON . TO mysql@localhost IDENTIFIED BY 1111’ " >> /tmp/config1 && \
echo “FLUSH PRIVILEGES;” >> /tmp/config1 &&
bash /tmp/config1 && \
rm -f /tmp/config1

VOLUME ["/var/lib/mysql"]
WORKDIR /data
EXPOSE 3306
CMD ["/usr/bin/mysqld_safe"]

But docker throws the exception

Step 0 : FROM centos:centos7
—> bb3d629a7cbc
Step 1 : RUN yum install -y mariadb-server mariadb
—> Using cache
—> ca601a1b4536
Step 2 : RUN mysql_install_db --user=mysql --ldata=/var/lib/mysql/
—> Using cache
—> f2ad799ac3ae
Step 3 : ADD my.cnf /etc/
—> Using cache
—> 44849c37620d
Step 4 : RUN sed -i ‘/[mysqld]/aport=3306’ /etc/my.cnf
—> Using cache
—> e787b9d14542
Step 5 : RUN echo “/usr/bin/mysqld_safe --basedir=/usr &” > /tmp/config && echo “cat /var/log/mariadb/mariadb.log” >> /tmp/config && echo “mysqladmin -u mysql password hsj7749” >> /tmp/config && echo “mysql -u mysql -p -h localhost test” >> /tmp/config && bash /tmp/config && rm -f /tmp/config
—> Running in 9ecbc5d0fe53
** mysqladmin: connect to server at ‘localhost’ failed**
> error: ‘Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)’
> Check that mysqld is running and that the socket: ‘/var/lib/mysql/mysql.sock’ exists!
> Enter password: ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
The command ‘/bin/sh -c echo “/usr/bin/mysqld_safe --basedir=/usr &” > /tmp/config && echo “cat /var/log/mariadb/mariadb.log” >> /tmp/config && echo “mysqladmin -u mysql password hsj7749” >> /tmp/config && echo “mysql -u mysql -p -h localhost test” >> /tmp/config && bash /tmp/config && rm -f /tmp/config’ returned a non-zero code: 1

I am stuck with this mariadb dockerfile problem. Pls, inform me of any advice and referrence. Thanks, And I also need your help of how to execute sql file in dockerfile .
Best regards!