45 lines
1.2 KiB
Docker
45 lines
1.2 KiB
Docker
FROM alpine:3.20
|
|
|
|
RUN apk update && apk upgrade && \
|
|
apk add --no-cache \
|
|
mariadb \
|
|
mariadb-client \
|
|
mariadb-server-utils && \
|
|
rm -rf /var/cache/apk/*
|
|
|
|
# Create a new user and group
|
|
RUN addgroup -S mariadb && adduser -S mariadb -G mariadb
|
|
# Create the data directory
|
|
RUN mkdir -p /var/lib/mysql && \
|
|
chown -R mariadb:mariadb /var/lib/mysql && \
|
|
chmod 700 /var/lib/mysql
|
|
# Create the socket directory
|
|
RUN mkdir -p /var/run/mysqld && \
|
|
chown -R mariadb:mariadb /var/run/mysqld && \
|
|
chmod 755 /var/run/mysqld
|
|
# Create the configuration directory
|
|
# Set the working directory
|
|
WORKDIR /var/lib/mysql
|
|
# Expose the MySQL port
|
|
EXPOSE 3306
|
|
# Set the default environment variables
|
|
|
|
# Copy the configuration file
|
|
COPY ./conf/my.cnf /etc/my.cnf
|
|
# Make the configuration file readable by the user
|
|
RUN chown mariadb:mariadb /etc/my.cnf
|
|
|
|
|
|
# Copy the entrypoint script
|
|
COPY ./tools/entrypoint.sh /usr/local/bin/entrypoint.sh
|
|
# Make the entrypoint script executable
|
|
RUN chmod +x /usr/local/bin/entrypoint.sh
|
|
# Set the default user to run the container
|
|
USER mariadb
|
|
|
|
# # Set the entrypoint script
|
|
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
|
# Set the default command to run when the container starts
|
|
CMD ["mysqld", "--bind-address=0.0.0.0"]
|
|
|