Under CentOS 7, I understand we're moving from mysql-server
to implementation-compatible MariaDB. I'm using a docker image of centos:latest
, which puts me under the auspices of Centos 7.
mysqld_safe
runs blocking in the foreground. That makes it easy: I just need to 0) install the package 1) change the root password and 2) run a server from within a Dockerfile
In the docker paradigm, for I need to be able to install MariaDB as if it were in a bash script. I've found various ways to do this using aptitude
under Ubuntu but have yet to find an equivalent answer under yum
: How do I install, configure and run mariadb on Centos 7 as if it were being installed via Bash script? mysql_secure_installation
appears to require a TTY.
I've tried running the mysqladmin
password command manually, but it complaints that it can't connect to a running MySQL instance. Because the containers are thrown away between steps, I believe I need to somehow run mysql and change the password in the same step.
I've tried installing initscripts
package gets me /bin/service
but it tries to redirect me to use systemctl start mariadb.service
, which isn't usable because Docker containers get a fakesystemd
and not systemd
. Any ideas?
Here's my current Dockerfile variant (in this one, trying a tail -f
to keep the process alive as a CMD
)
FROM centos:latest
MAINTAINER Me ([email protected])
RUN yum -y install wget epel-release
RUN cd /usr/local/src && wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm && rpm -Uvh remi-*.rpm && rm remi-*.rpm
RUN sed -i 's/enabled=0/enabled=1/' /etc/yum.repos.d/remi*.repo
RUN cd /usr/local/src && wget http://apt.sw.be/redhat/el7/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm && rpm -Uvh rpmforge-*.rpm && rm rpmforge-*.rpm
RUN rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
RUN sed -i 's/enabled=0/enabled=1/' /etc/yum.repos.d/rpmforge*.repo
RUN yum -y update
RUN yum -y upgrade
# mysql
RUN yum -y install mariadb-server
RUN yum -y install initscripts
WORKDIR /usr
#RUN echo "bind-address=0.0.0.0" >> /etc/my.cnf
RUN /usr/bin/mysql_install_db --datadir="/var/lib/mysql" --user=mysql
RUN /usr/bin/mysqld_safe --datadir="/var/lib/mysql" --socket="/var/lib/mysql/mysql.sock" --user=mysql >/dev/null 2>&1 &
RUN /usr/bin/mysqladmin -u root password SOMEPASSWORD
CMD tail -f /var/log/mariadb/mariadb.log
EXPOSE 3306
Related:
- Scripted install of MySQL on Ubuntu
- https://askubuntu.com/questions/79257/how-do-i-install-mysql-without-a-password-prompt
- https://stackoverflow.com/questions/1202347/how-can-i-pass-a-password-from-a-bash-script-to-aptitude-for-installing-mysql
- https://stackoverflow.com/questions/7739645/install-mysql-on-ubuntu-without-password-prompt
I'm working on a similar issue, setting up mariadb in a Docker container. I found this looking for ways to run mysql_secure_install. There are ways to feed the input to the script, or you can simply run the commands that the script would run. I opted for the latter.
I also ran into the same problem of the commands not finding a running MySQL instance. The problem is that each step of your build is run in a separate container, so you would have to start mysql for each command, or run them all in one step. This is what I have in my Dockerfile:
You can then build it with
You can find the documentation for --build-arg here.