docker: use container storage for MySQL data
authorGregory Szorc <gps@mozilla.com>
Fri, 03 Oct 2014 11:16:17 -0700
changeset 1147 68eca557382b
parent 1146 bd51c5329ab2
child 1148 287a5e7bfc39
push id168
push usergszorc@mozilla.com
push date2014-10-03 19:07 +0000
docker: use container storage for MySQL data
testing/docker/builder-bmodb-volatile/Dockerfile
testing/docker/builder-bmodb-volatile/entrypoint.sh
--- a/testing/docker/builder-bmodb-volatile/Dockerfile
+++ b/testing/docker/builder-bmodb-volatile/Dockerfile
@@ -4,11 +4,15 @@
 
 # The container is similar to bmodb, but it stores its data in the local
 # image, not in a volume. This is necessary to work around a bug in
 # volume garbage collection in Docker where the old volumes don't get
 # deleted on container deletion.
 
 FROM mysql:5.6.20
 
+RUN mkdir /var/lib/mysql-local
+
 COPY my.cnf /etc/mysql/my.cnf
 
 COPY entrypoint.sh /entrypoint.sh
+
+CMD ["mysqld", "--datadir=/var/lib/mysql-local", "--user=mysql"]
--- a/testing/docker/builder-bmodb-volatile/entrypoint.sh
+++ b/testing/docker/builder-bmodb-volatile/entrypoint.sh
@@ -1,19 +1,21 @@
 #!/bin/bash
 set -e
 
-if [ -z "$(ls -A /var/lib/mysql)" -a "${1%_safe}" = 'mysqld' ]; then
+DATADIR=/var/lib/mysql-local
+
+if [ -z "$(ls -A $DATADIR)" -a "${1%_safe}" = 'mysqld' ]; then
 	if [ -z "$MYSQL_ROOT_PASSWORD" ]; then
 		echo >&2 'error: database is uninitialized and MYSQL_ROOT_PASSWORD not set'
 		echo >&2 '  Did you forget to add -e MYSQL_ROOT_PASSWORD=... ?'
 		exit 1
 	fi
 	
-	mysql_install_db --user=mysql --datadir=/var/lib/mysql
+	mysql_install_db --user=mysql --datadir=$DATADIR
 	
 	# These statements _must_ be on individual lines, and _must_ end with
 	# semicolons (no line breaks or comments are permitted).
 	# TODO proper SQL escaping on ALL the things D:
 	TEMP_FILE='/tmp/mysql-first-time.sql'
 	cat > "$TEMP_FILE" <<-EOSQL
 		DELETE FROM mysql.user ;
 		CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;
@@ -33,10 +35,10 @@ if [ -z "$(ls -A /var/lib/mysql)" -a "${
 		fi
 	fi
 	
 	echo 'FLUSH PRIVILEGES ;' >> "$TEMP_FILE"
 	
 	set -- "$@" --init-file="$TEMP_FILE"
 fi
 
-chown -R mysql:mysql /var/lib/mysql
+chown -R mysql:mysql $DATADIR
 exec "$@"