Inception/srcs/requirements/mariadb/Dockerfile
2025-05-16 14:54:18 +02:00

50 lines
1.5 KiB
Docker

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/*
# Create a new user and group
RUN addgroup -S mariadb && \
adduser -S 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
# 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 ./docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
COPY ./my.cnf /etc/my.cnf
COPY ./init.sql /usr/local/bin/init.sql
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Expose the MySQL port
EXPOSE 3306
# Set the user and group to run the container
USER mariadb:mariadb
# 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
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
# Start the MariaDB server
CMD ["mysqld"]