forked from noxious/server
Updated Dockerfile
This commit is contained in:
parent
5f02aca6e4
commit
8b9afdf956
14
Dockerfile
14
Dockerfile
@ -5,16 +5,18 @@ RUN apk add --no-cache \
|
||||
redis \
|
||||
mariadb \
|
||||
mariadb-client \
|
||||
tmux
|
||||
tmux \
|
||||
mariadb-server-utils \
|
||||
mariadb-connector-c
|
||||
|
||||
# Create non-root user
|
||||
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
||||
|
||||
# Setup MariaDB
|
||||
# Setup MariaDB with proper permissions
|
||||
RUN mkdir -p /run/mysqld /var/lib/mysql && \
|
||||
chown -R mysql:mysql /run/mysqld && \
|
||||
chown -R mysql:mysql /var/lib/mysql && \
|
||||
mariadb-install-db --user=mysql --datadir=/var/lib/mysql && \
|
||||
mysql_install_db --user=mysql --datadir=/var/lib/mysql && \
|
||||
chmod 777 /run/mysqld
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
@ -28,7 +30,11 @@ RUN npm ci --only=production && \
|
||||
|
||||
# Grant necessary permissions to appuser
|
||||
RUN adduser appuser mysql && \
|
||||
chmod 777 /var/lib/mysql
|
||||
chmod 755 /var/lib/mysql && \
|
||||
mkdir -p /var/log/mysql && \
|
||||
chown -R mysql:mysql /var/log/mysql && \
|
||||
touch /var/log/mysql/error.log && \
|
||||
chown mysql:mysql /var/log/mysql/error.log
|
||||
|
||||
USER appuser
|
||||
|
||||
|
24
start.sh
24
start.sh
@ -27,17 +27,35 @@ fi
|
||||
|
||||
# Start MySQL
|
||||
echo "Starting MySQL..."
|
||||
mysqld --user=mysql --datadir=/var/lib/mysql &
|
||||
|
||||
# Ensure directory permissions are correct
|
||||
chown -R mysql:mysql /var/lib/mysql /run/mysqld
|
||||
chmod 755 /var/lib/mysql
|
||||
|
||||
# Start MariaDB with specific options
|
||||
mysqld --user=mysql \
|
||||
--datadir=/var/lib/mysql \
|
||||
--pid-file=/run/mysqld/mysqld.pid \
|
||||
--socket=/run/mysqld/mysqld.sock \
|
||||
--log-error=/var/log/mysql/error.log \
|
||||
--bind-address=0.0.0.0 &
|
||||
|
||||
# Wait for MySQL with timeout
|
||||
echo "Waiting for MySQL to be ready..."
|
||||
COUNTER=0
|
||||
while ! mysqladmin ping -h localhost --silent; do
|
||||
while true; do
|
||||
if mysqladmin ping -h localhost --silent 2>/dev/null; then
|
||||
break
|
||||
fi
|
||||
|
||||
if [ $COUNTER -gt $MAX_MYSQL_WAIT ]; then
|
||||
echo "MySQL failed to start within $MAX_MYSQL_WAIT seconds"
|
||||
echo "Last few lines of MySQL error log:"
|
||||
tail -n 20 /var/log/mysql/error.log
|
||||
exit 1
|
||||
fi
|
||||
echo "Still waiting..."
|
||||
|
||||
echo "Still waiting... (${COUNTER}s)"
|
||||
sleep 2
|
||||
COUNTER=$((COUNTER+2))
|
||||
done
|
||||
|
Loading…
x
Reference in New Issue
Block a user