Reputation: 23
I'm trying to build a custom MariaDB docker image based on the newly released Rocky Linux for testing purposes. However it seems that running the service, preparing initial database schema like setting up the root password, importing data, etc. is complicated due to the absence of systemd. Even by enabling systemctl through python (workaround), the build process halts when encountering systemctl start mariadb.
Dockerfile:
FROM rockylinux/rockylinux
# INT
RUN yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y
RUN yum install supervisor -y
ADD ./assets/SYS/supervisor.conf /etc/supervisor.conf
# SYS
RUN yum install python2 -y
RUN ln -s /usr/bin/python2 /usr/bin/python
RUN unlink /usr/bin/systemctl
ADD ./assets/SYS/systemctl /usr/bin/systemctl
RUN chmod +x /usr/bin/systemctl
# DBS
RUN yum install mariadb-server -y
# Method 1
RUN systemctl start mariadb
# [ freezes the build process ]
# Method 2
RUN exec /usr/bin/mysqld_safe
# [ runs the service but there is a mysql.sock error ]
# Method 3
RUN exec /usr/libexec/mysqld --defaults-file=/etc/my.cnf --user=root
# [ does not run the service ]
RUN mysql_upgrade -u root --force
RUN mysql -u root -e 'DELETE FROM mysql.user WHERE User="";'
RUN mysql -u root -e 'DELETE FROM mysql.user WHERE User="root" AND Host NOT IN ("localhost", "127.0.0.1", "::1");'
RUN mysql -u root -e 'GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "";'
RUN mysql -u root -e 'DROP DATABASE IF EXISTS test;'
RUN mysql -u root -e 'DELETE FROM mysql.db WHERE Db="test" OR Db="test\\_%";'
RUN mysql -u root -e 'FLUSH PRIVILEGES;'
RUN mysql -u root -e 'CREATE DATABASE somedatabase;'
ADD ./assets/DBS/database.sql database.sql
RUN mysql -u root somedatabase < database.sql
RUN unlink database.sql
RUN mysqladmin password "somepassword"
RUN systemctl stop mariadb
EXPOSE 3306
CMD ["supervisord", "-c", "/etc/supervisor.conf"]
supervisor.conf
[program:mariadb]
command=/usr/bin/mysqld_safe --basedir=/usr
process_name=%(program_name)s_%(process_num)02d
numprocs=1
autostart=true
autorestart=false
startsecs=0
redirect_stderr=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
Upvotes: 1
Views: 772
Reputation: 3271
I am not sure whether the python workaround refers to the docker-systemctl-replacement script. Then there is only the problem left that single RUN needs both "start" and "stop" of the service.
There is a working example for mysql that can show the defaults about it. https://github.com/gdraheim/docker-systemctl-images/blob/master/centos-lamp-stack.dockerfile
Upvotes: 0