FROM alpine:3.20 # Install MariaDB and MariaDB client # The --no-cache option is used to prevent the package manager from caching the downloaded packages # rm -rf /var/cache/apk/* is used to remove any cached files after installation # This helps to keep the image size small RUN apk add --no-cache \ mariadb \ mariadb-client && \ rm -rf /var/cache/apk/* ARG HOST_UID # Create a new user and group RUN addgroup -S -g $HOST_UID mariadb && \ adduser -S -u $HOST_UID mariadb -G mariadb # Create the necessary directories RUN mkdir -p /var/run/mysqld && \ chown -R mariadb:mariadb /var/run/mysqld && \ chown -R mariadb:mariadb /var/lib/mysql && \ chmod -R 750 /var/lib/mysql # Copy the entrypoint script and configuration files # and set the necessary permissions # The entrypoint script will be responsible for initializing the database # and starting the MariaDB server # The configuration file will be used to set the server settings # The init.sql file will be executed when the container is started for the first time COPY ./tools/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh COPY ./conf/my.cnf /etc/my.cnf # COPY ./init.sql /usr/local/bin/init.sql # Expose the MySQL port #EXPOSE 3306 # Set the user and group to run the container RUN chmod +x /usr/local/bin/docker-entrypoint.sh # Set the working directory WORKDIR /var/lib/mysql # Set the entrypoint script to be executed when the container starts # The entrypoint script will initialize the database and start the server USER mariadb ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] # Start the MariaDB server CMD ["mysqld", "--datadir=/var/lib/mysql", "--user=mariadb"] HEALTHCHECK --interval=5s --timeout=3s --start-period=5s --retries=1 CMD mysqladmin ping -h localhost || exit 1