Skip to content

Commit f239b95

Browse files
authored
Add dockerfile (#11)
* add dockerfile * upload dockerfile * update dockerfile * updates * delete fixed cfg for customized cfg
1 parent c456c25 commit f239b95

5 files changed

Lines changed: 67 additions & 1 deletion

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ sqlancer-logs/
44
__pycache__/
55
**/__pycache__/
66

7-
Dockerfile
87
.env

entrypoint.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
MYSQL_BASEDIR=/usr/local/mysql
6+
MYSQL_DATADIR=$MYSQL_BASEDIR/data
7+
8+
if [ ! -d "$MYSQL_DATADIR/mysql" ]; then
9+
echo "Initializing MySQL data directory..."
10+
chown -R mysql:mysql "$MYSQL_BASEDIR"
11+
mysqld --initialize-insecure --user=mysql --basedir="$MYSQL_BASEDIR" --datadir="$MYSQL_DATADIR"
12+
fi
13+
14+
echo "Starting MySQL server..."
15+
exec mysqld --user=mysql --basedir="$MYSQL_BASEDIR" --datadir="$MYSQL_DATADIR"

mysql/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM ubuntu:22.04
2+
3+
RUN apt-get update && \
4+
apt-get install -y wget libaio1 libncurses6 libnuma1 xz-utils pwgen lsb-release gnupg libssl-dev && \
5+
apt-get clean
6+
7+
ENV MYSQL_VERSION=8.3.0 \
8+
MYSQL_USER=mysql \
9+
MYSQL_BASE=/usr/local/mysql \
10+
MYSQL_DATADIR=/var/lib/mysql
11+
12+
RUN wget https://downloads.mysql.com/archives/get/p/23/file/mysql-${MYSQL_VERSION}-linux-glibc2.28-x86_64.tar.xz && \
13+
tar -xf mysql-${MYSQL_VERSION}-linux-glibc2.28-x86_64.tar.xz && \
14+
mv mysql-${MYSQL_VERSION}-linux-glibc2.28-x86_64 ${MYSQL_BASE} && \
15+
rm mysql-${MYSQL_VERSION}-linux-glibc2.28-x86_64.tar.xz
16+
17+
RUN useradd -r -s /bin/false ${MYSQL_USER} && \
18+
mkdir -p ${MYSQL_DATADIR} /var/run/mysqld && \
19+
chown -R ${MYSQL_USER}:${MYSQL_USER} ${MYSQL_DATADIR} /var/run/mysqld ${MYSQL_BASE}
20+
21+
RUN ${MYSQL_BASE}/bin/mysqld --initialize-insecure --basedir=${MYSQL_BASE} --datadir=${MYSQL_DATADIR} --user=${MYSQL_USER}
22+
23+
COPY init.sql /init.sql
24+
25+
COPY entrypoint.sh /entrypoint.sh
26+
RUN chmod +x /entrypoint.sh
27+
28+
ENV PATH=${MYSQL_BASE}/bin:$PATH
29+
30+
EXPOSE 3306
31+
32+
ENTRYPOINT ["/entrypoint.sh"]

mysql/entrypoint.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "Starting mysqld in background..."
5+
/usr/local/mysql/bin/mysqld --user=mysql --datadir=/var/lib/mysql --basedir=/usr/local/mysql --skip-networking &
6+
pid="$!"
7+
8+
sleep 10
9+
10+
echo "Running init.sql to grant privileges..."
11+
/usr/local/mysql/bin/mysql -uroot < /init.sql
12+
13+
kill "$pid"
14+
sleep 5
15+
16+
echo "Starting MySQL server..."
17+
exec /usr/local/mysql/bin/mysqld --user=mysql --datadir=/var/lib/mysql --basedir=/usr/local/mysql --bind-address=0.0.0.0

mysql/init.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CREATE USER IF NOT EXISTS 'root'@'%' IDENTIFIED BY '12345678';
2+
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
3+
FLUSH PRIVILEGES;

0 commit comments

Comments
 (0)