diff options
-rw-r--r-- | Services/mariadb/Dockerfile | 15 | ||||
-rw-r--r-- | Services/mariadb/README.md | 14 | ||||
-rw-r--r-- | Services/mariadb/example.sql | 3 | ||||
-rw-r--r-- | Services/mariadb/sx/mariadb.sh | 10 | ||||
-rw-r--r-- | Services/mariadb/sx/mariadb_run.sh | 7 |
5 files changed, 32 insertions, 17 deletions
diff --git a/Services/mariadb/Dockerfile b/Services/mariadb/Dockerfile index 9140c96..eaead31 100644 --- a/Services/mariadb/Dockerfile +++ b/Services/mariadb/Dockerfile @@ -1,29 +1,28 @@ FROM startx/fedora MAINTAINER Christophe LARUE <dev@startx.fr> -COPY sx/* /sx/ RUN yum -y install \ mariadb-libs \ mariadb-server \ mariadb \ - \ - psmisc \ - \ && yum clean all \ && mkdir -p /var/log/mysql \ && mkdir -p /sx \ && touch /var/log/mysql/.keep /var/lib/mysql/.keep \ && chown -R mysql:mysql /var/log/mysql /var/lib/mysql \ - && chmod ug+rx /sx/mariadb* \ - && chown -R mysql:mysql /sx/mariadb* + && mkdir -p /tmp/sql +COPY sx/* /sx/ +COPY *.sql /tmp/sql/ +RUN chmod ug+rx /sx/mariadb* /tmp/sql \ + && chown -R mysql:mysql /sx/mariadb* /tmp/sql -USER mysql EXPOSE 3306 VOLUME ["/var/lib/mysql", "/var/log/mysql"] +USER mysql # if you wan't to set root password, otherwise auto-generated # see docker logs <containerId> -ENV mysql_newadminpwd "newRootPassword" +ENV mysql_newadminpwd newRootPassword #ENDPOINT ["/sx/mariadb_run.sh"] diff --git a/Services/mariadb/README.md b/Services/mariadb/README.md index 0d4dad8..db7e14e 100644 --- a/Services/mariadb/README.md +++ b/Services/mariadb/README.md @@ -19,6 +19,8 @@ Copy sources in your docker host cd startx-docker-images; git clone https://github.com/startxfr/docker-images.git . +Change configuration and personalize your base image. See sx/mariadb_run.sh to perform some usefull task against the database, especially importing sql script, adding users and changing passwords. See also example.sql for injecting sql content when creating container. + Build the container docker build -t sv-mariadb Services/mariadb/ @@ -28,16 +30,24 @@ Build the container docker run -d -p 3306:3306 --name="mariadb" sv-mariadb ## Accessing server +get connection information's, use docker logs to see result and connection details + + docker logs mariadb + access to the running database mysql -h localhost -p 3306 access to the container itself - docker exec -it mariadb bash + docker exec -it mariadb /bin/bash ## Related Resources * [Sources files](https://github.com/startxfr/docker-images/tree/master/Services/mariadb) * [Github STARTX profile](https://github.com/startxfr/docker-images) * [Docker registry for this container](https://registry.hub.docker.com/u/startx/sv-mariadb/) -* [Docker registry for Fedora](https://registry.hub.docker.com/u/fedora/)
\ No newline at end of file +* [Docker registry for Fedora](https://registry.hub.docker.com/u/fedora/) +* [Fedora-files mariadb container](https://github.com/fedora-cloud/Fedora-Dockerfiles/tree/master/mariadb) +* [Tutum mariadb container](https://registry.hub.docker.com/u/tutum/mariadb/) +* [Tutum mariadb github](https://github.com/tutumcloud/tutum-docker-mariadb) +* [Dylan Lindgren mariadb container](https://registry.hub.docker.com/u/dylanlindgren/docker-mariadb/)
\ No newline at end of file diff --git a/Services/mariadb/example.sql b/Services/mariadb/example.sql new file mode 100644 index 0000000..498de07 --- /dev/null +++ b/Services/mariadb/example.sql @@ -0,0 +1,3 @@ +# add SQL queries to execute when configuring the database +# see mariadb_run.sh to activate this feature +SHOW DATABASES;
\ No newline at end of file diff --git a/Services/mariadb/sx/mariadb.sh b/Services/mariadb/sx/mariadb.sh index af6124b..5b2857d 100644 --- a/Services/mariadb/sx/mariadb.sh +++ b/Services/mariadb/sx/mariadb.sh @@ -88,11 +88,11 @@ function update_rootuser { # Find all sqlfiles in /tmp/ and import then using admin user function import_sqlfiles { - local filedir=$1; local p=$MARIADB_ROOTPWD; + local filedir=$1; local p=$MARIADB_ROOTPWD; local del=$2; if [ "$(ls -1 $filedir | wc -l)" -ge "1" ]; then echo "=> Found SQL files to import ..." for filename in "$filedir"; do - import_sqlfile $filename + import_sqlfile $filename $del done; fi; return 0 @@ -100,10 +100,14 @@ function import_sqlfiles { # Find all sqlfiles in /tmp/ and import then using admin user function import_sqlfile { - local filename=$1; local p=$MARIADB_ROOTPWD; + local filename=$1; local p=$MARIADB_ROOTPWD; local del=$2; if [ -f "$filename" ]; then echo "===> Importing sql file : $filename" mysql -u root -p$p < $filename + if [ "$del" = "delete"]; then + rm -f $filename + echo "====> Deleting $filename after import" + fi; else echo "====> Could not find sql file $filename. Skip import..." fi; diff --git a/Services/mariadb/sx/mariadb_run.sh b/Services/mariadb/sx/mariadb_run.sh index 07a4c03..7dcf9b2 100644 --- a/Services/mariadb/sx/mariadb_run.sh +++ b/Services/mariadb/sx/mariadb_run.sh @@ -2,7 +2,6 @@ source /sx/mariadb.sh begin_config - ## if you wan't to add a new user with database #create_userdb 'dbuser1' 'password' ## if you wan't to add a new user with database (generated password) @@ -15,8 +14,8 @@ begin_config #mysql -u root -p$MARIADB_ROOTPWD -e 'select user, host FROM mysql.user;' ## Execute SQL scripts located into a directory #import_sqlfiles /tmp/sql/*.sql -## Execute a single SQL script -#import_sqlfile /tmp/sql/example.sql - +## Execute a single SQL script and delete it +#import_sqlfile /tmp/sql/example.sql delete end_config + start_daemon
\ No newline at end of file |