aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXicheng Chang <xicheng.chang@huawei.com>2016-11-02 01:10:18 +0000
committerXicheng Chang <xicheng.chang@huawei.com>2016-11-02 01:10:18 +0000
commitb5f39ea924bbb6bf94c072eaa9a11b93f4ac7dc0 (patch)
tree4462e703fb0650913a28108a30ae5be581b99a83
parent7268ca16b750e038ee0dc9387828af390d9b71c7 (diff)
update dockerfile
-rw-r--r--Dockerfile12
-rw-r--r--entrypoint.sh41
2 files changed, 53 insertions, 0 deletions
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..eba5569
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,12 @@
+FROM ubuntu:trusty
+
+EXPOSE 3306/tcp
+
+RUN apt-get update && \
+ DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server && \
+ rm -rf /var/lib/apt/lists/*
+
+COPY entrypoint.sh /sbin/entrypoint.sh
+RUN chmod 755 /sbin/entrypoint.sh
+
+CMD ["/sbin/entrypoint.sh"]
diff --git a/entrypoint.sh b/entrypoint.sh
new file mode 100644
index 0000000..e01d29c
--- /dev/null
+++ b/entrypoint.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+set -x
+
+create_users_and_dbs() {
+ /usr/bin/mysqld_safe > /dev/null 2>&1 &
+
+ timeout=30
+ # wait up to 30 secs...
+ while ! /usr/bin/mysqladmin -u root status > /dev/null 2>&1
+ do
+ timeout=$(($timeout - 1))
+ if [ $timeout -eq 0 ]; then
+ echo -e "\nCould not connect to database server. Aborting..."
+ exit 1
+ fi
+ echo -n "."
+ sleep 1
+ done
+
+ echo "Creating user..."
+ mysqladmin -h127.0.0.1 --port=3306 -u root password root
+ mysql -h127.0.0.1 --port=3306 -uroot -proot -e "create database compass"
+ mysql -h127.0.0.1 --port=3306 -uroot -proot -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root'"
+ mysqladmin -uroot -proot shutdown
+}
+
+listen_on_all_interfaces() {
+ cat > /etc/mysql/conf.d/mysql-listen.cnf <<EOF
+[mysqld]
+bind-address=0.0.0.0
+[mysqld_safe]
+bind-address=0.0.0.0
+EOF
+}
+
+
+if [[ -z ${1} ]]; then
+ create_users_and_dbs
+ listen_on_all_interfaces
+ /usr/bin/mysqld_safe
+fi