Hi
Starting my docker journey, I want to create a container that runs a nagios monitoring box and an extra app called Nagvis that requires a tool called NDOUTILS.
This tool requires a mysql instance and I am trying to set it up in my Dockerfile but no joy so far
Here is the Dockerfile part
#ENV BUILD=aarch64-unknown-linux-gnu
RUN apt-get update && apt-get install -y mysql-server libmysqlclient-dev libdbd-mysql-perl
EXPOSE 3306
RUN service mysql restart && \
'printf "CREATE DATABASE nagios DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; " ' | mysql -u root && \
'printf "CREATE USER 'ndoutils'@'localhost' IDENTIFIED BY 'ndoutils_password' ;" '| mysql -u root && \
'printf "GRANT ALL PRIVILEGES ON nagios.* TO 'ndoutils'@'localhost' WITH GRANT OPTION ;" ' | mysql -u root && \
'printf "GRANT USAGE ON *.* TO 'ndoutils'@'localhost' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;" ' | mysql -u root && \
git clone https://github.com/NagiosEnterprises/ndoutils.git && \
cd ndoutils && \
./configure --prefix /opt/nagios --build=aarch64-unknown-linux-gnu --with-init-type=systemd &&\
make all && make install && make install-init && make install-config && \
cd db && \
./installdb -u ndoutils -p 'ndoutils_password' -h localhost -d nagios
RUN mv /opt/nagios/etc/ndo2db.cfg-sample /opt/nagios/etc/ndo2db.cfg
RUN sh -c 'sed -i 's/^db_user=.*/db_user=ndoutils/g' /opt/nagios/etc/ndo2db.cfg'
RUN sh -c 'sed -i 's/^db_pass=.*/db_pass=ndoutils_password/g' /opt/nagios/etc/ndo2db.cfg'
RUN mv /opt/nagios/etc/ndomod.cfg-sample /opt/nagios/etc/ndomod.cfg
And here is the Docker build output:
* Starting MySQL database server mysqld
su: warning: cannot change directory to /nonexistent: No such file or directory
...done.
/bin/sh: 1: printf "CREATE DATABASE nagios DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; " : not found
/bin/sh: 1: printf "CREATE USER ndoutils@localhost IDENTIFIED BY ndoutils_password ;" : not found
/bin/sh: 1: printf "GRANT ALL PRIVILEGES ON nagios.* TO ndoutils@localhost WITH GRANT OPTION ;" : not found
/bin/sh: 1: printf "GRANT USAGE ON *.* TO ndoutils@localhost WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;" : not found
Cloning into 'ndoutils'...
checking for a BSD-compatible install.../usr/bin/install -c
...
The console output:
8.323 DBI connect('nagios;localhost:','ndoutils',...) failed: Access denied for user 'ndoutils'@'localhost' (using password: YES) at ./installdb line 42.
------
Dockerfile:190
--------------------
189 | EXPOSE 3306
190 | >>> RUN service mysql restart && \
191 | >>> 'printf "CREATE DATABASE nagios DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; " ' | mysql -u root && \
192 | >>> 'printf "CREATE USER 'ndoutils'@'localhost' IDENTIFIED BY 'ndoutils_password' ;" '| mysql -u root && \
193 | >>> 'printf "GRANT ALL PRIVILEGES ON nagios.* TO 'ndoutils'@'localhost' WITH GRANT OPTION ;" ' | mysql -u root && \
194 | >>> 'printf "GRANT USAGE ON *.* TO 'ndoutils'@'localhost' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;" ' | mysql -u root && \
195 | >>> git clone https://github.com/NagiosEnterprises/ndoutils.git && \
196 | >>> cd ndoutils && \
197 | >>> ./configure --prefix /opt/nagios --build=aarch64-unknown-linux-gnu --with-init-type=systemd &&\
198 | >>> make all && make install && make install-init && make install-config && \
199 | >>> cd db && \
200 | >>> ./installdb -u ndoutils -p 'ndoutils_password' -h localhost -d nagios
201 |
--------------------
ERROR: failed to solve: process "/bin/sh -c service mysql restart && 'printf \"CREATE DATABASE nagios DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; \" ' | mysql -u root && 'printf \"CREATE USER 'ndoutils'@'localhost' IDENTIFIED BY 'ndoutils_password' ;\" '| mysql -u root && 'printf \"GRANT ALL PRIVILEGES ON nagios.* TO 'ndoutils'@'localhost' WITH GRANT OPTION ;\" ' | mysql -u root && 'printf \"GRANT USAGE ON *.* TO 'ndoutils'@'localhost' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;\" ' | mysql -u root && git clone https://github.com/NagiosEnterprises/ndoutils.git && cd ndoutils && ./configure --prefix /opt/nagios --build=aarch64-unknown-linux-gnu --with-init-type=systemd && make all && make install && make install-init && make install-config && cd db && ./installdb -u ndoutils -p 'ndoutils_password' -h localhost -d nagios" did not complete successfully: exit code: 255
Looks like none of the SQL statements I am trying to run are executed, I have tried many format options…