As the title says I have a problem regarding one of my dockerfile, indeed once the image is built it immediately stops after being run with the docker run command, my dockerfile base image is alpine:3.18 and I run mariadb inside the container. Here is the dockerfile:
FROM alpine:3.18
ARG APP_USER=mysql
RUN apk update && apk add --no-cache mariadb mariadb-client
RUN mkdir -p /var/log/${APP_USER}
RUN mkdir -p /var/run/mysqld && \
chown -R ${APP_USER}:${APP_USER} /var/run/mysqld && \
chmod -R 750 /var/run/mysqld
RUN mkdir -p /var/lib/${APP_USER} && \
chown -R ${APP_USER}:${APP_USER} /var/lib/${APP_USER} && \
chmod -R 750 /var/lib/${APP_USER} && \
mkdir -p /var/run/${APP_USER} && \
chown -R ${APP_USER}:${APP_USER} /var/run/${APP_USER} && \
chmod -R 750 /var/run/${APP_USER} && \
chown -R ${APP_USER}:${APP_USER} /var/log/${APP_USER} && \
chmod -R 750 /var/log/${APP_USER}
COPY ./conf/my.cnf /etc/${APP_USER}/my.cnf
COPY ./tools/init.sql /docker-entrypoint-initdb.d/init.sql
EXPOSE 3306
USER ${APP_USER}:${APP_USER}
CMD ["mysqld_safe"]
here is the my.cnf file:
[mysqld]
datadir=/var/lib/mysql
socket=/var/run/mysqld/mysqld.sock
log-error=/var/log/mysql/error.log
# Security
skip-networking
here is the script that will create an admin user and set a password for root user.
CREATE USER ${ADMIN_USERNAME}@'localhost' IDENTIFIED BY ${ADMIN_PASSWORD};
GRANT ALL PRIVILEGES ON ${MARIADB_DB_NAME}.* TO ${ADMIN_USERNAME}@'localhost' IDENTIFIED BY ${ADMIN_PASSWORD};
ALTER USER 'root'@'localhost' IDENTIFIED BY ${ROOT_PASSWORD};
FLUSH PRIVILEGES;
CREATE DATABASE wordpress;
I checked the exit status of my container, and the status is 0 it seems that all is ok but my container stops immediately when started using docker run command.