Skip to content

Commit 07cb671

Browse files
Merge pull request #1 from smarterclayton/add_mariadb
Add a MariaDB example that runs as non-root and inits itself
2 parents 5bcea1b + 5f1493b commit 07cb671

File tree

3 files changed

+223
-0
lines changed

3 files changed

+223
-0
lines changed

fedora-mariadb/Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM fedora:20
2+
MAINTAINER Clayton Coleman <[email protected]>
3+
4+
RUN yum install -y mariadb mariadb-server && yum clean all
5+
6+
RUN mkdir -p /var/log/mysql && \
7+
chown mysql:mysql /var/log/mysql /var/lib/mysql && \
8+
touch /var/log/mysql/.keep /var/lib/mysql/.keep
9+
VOLUME ["/var/lib/mysql", "/var/log/mysql"]
10+
11+
USER mysql
12+
ADD ./simple.cnf /etc/my.cnf.d/
13+
ADD ./start /usr/bin/run
14+
15+
EXPOSE 3306
16+
CMD ["/usr/bin/run"]

fedora-mariadb/simple.cnf

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Simple MariaDB database server configuration file.
2+
#
3+
# =================================================================
4+
# Base configuration courtesy of Open Query (http://openquery.com/)
5+
# For production use, case-specific preparation is still required.
6+
# 2009-10-07
7+
#
8+
# This is *not* an optimised config, merely a more sane baseline:
9+
# - binary and slow log enabled, with enhancements
10+
# - InnoDB default (e.g., ACID out-of-the-box, same as on Windows)
11+
# - strict mode (for proper input checks, same as on Windows)
12+
# - various other useful settings
13+
# - make use of MariaDB/Percona/OurDelta enhancements/extensions
14+
#
15+
# For tuning assistance, please see http://openquery.com/services
16+
# =================================================================
17+
18+
[client]
19+
default-character-set = utf8
20+
21+
# Here is entries for some specific programs
22+
# The following values assume you have at least 32M ram
23+
24+
# This was formally known as [safe_mysqld]. Both versions are currently parsed.
25+
[mysqld_safe]
26+
nice = 0
27+
log-error=/var/log/mysql/mysqld.log
28+
29+
[server]
30+
#
31+
# * Basic Settings
32+
#
33+
user = mysql
34+
tmpdir = /tmp
35+
skip-external-locking
36+
37+
#
38+
# * Fine Tuning
39+
#
40+
max_connections = 32
41+
connect_timeout = 5
42+
wait_timeout = 600
43+
max_allowed_packet = 16M
44+
thread_cache_size = 128
45+
sort_buffer_size = 4M
46+
bulk_insert_buffer_size = 16M
47+
tmp_table_size = 32M
48+
max_heap_table_size = 32M
49+
#
50+
# * MyISAM
51+
#
52+
# This replaces the startup script and checks MyISAM tables if needed
53+
# the first time they are touched. On error, make copy and try a repair.
54+
myisam_recover = BACKUP
55+
key_buffer_size = 128M
56+
#open-files-limit = 2000
57+
table_cache = 400
58+
myisam_sort_buffer_size = 512M
59+
concurrent_insert = 2
60+
read_buffer_size = 2M
61+
read_rnd_buffer_size = 1M
62+
#
63+
# * Query Cache Configuration
64+
#
65+
# Cache only tiny result sets, so we can fit more in the query cache.
66+
query_cache_limit = 128K
67+
query_cache_size = 64M
68+
# for more write intensive setups, set to DEMAND or OFF
69+
#query_cache_type = DEMAND
70+
#
71+
# * Logging and Replication
72+
#
73+
# Both location gets rotated by the cronjob.
74+
# Be aware that this log type is a performance killer.
75+
# As of 5.1 you can enable the log at runtime!
76+
#general_log_file = /var/log/mysql/mysql.log
77+
#general_log = 1
78+
#
79+
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
80+
#
81+
# we do want to know about network errors and such
82+
log_warnings = 2
83+
#
84+
# Here you can see queries with especially long duration
85+
slow_query_log
86+
slow_query_log_file = /var/log/mysql/mariadb-slow.log
87+
long_query_time = 10
88+
#log_slow_rate_limit = 1000
89+
log_slow_verbosity = query_plan
90+
91+
#log-queries-not-using-indexes
92+
log_slow_admin_statements
93+
#
94+
# The following can be used as easy to replay backup logs or for replication.
95+
# note: if you are setting up a replication slave, see README.Debian about
96+
# other settings you may need to change.
97+
#server-id = 1
98+
#report_host = master1
99+
#auto_increment_increment = 2
100+
#auto_increment_offset = 1
101+
log_bin = /var/log/mysql/mariadb-bin
102+
log_bin_index = /var/log/mysql/mariadb-bin.index
103+
# not fab for performance, but safer
104+
#sync_binlog = 1
105+
expire_logs_days = 10
106+
max_binlog_size = 100M
107+
# slaves
108+
#relay_log = /var/log/mysql/relay-bin
109+
#relay_log_index = /var/log/mysql/relay-bin.index
110+
#relay_log_info_file = /var/log/mysql/relay-bin.info
111+
#log_slave_updates
112+
#read_only
113+
#
114+
#
115+
# * InnoDB
116+
#
117+
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
118+
# Read the manual for more InnoDB related options. There are many!
119+
default_storage_engine = InnoDB
120+
sql_mode = NO_ENGINE_SUBSTITUTION,TRADITIONAL
121+
# you can't just change log file size, requires special procedure
122+
innodb_log_file_size = 16M
123+
innodb_buffer_pool_size = 265M
124+
innodb_log_buffer_size = 8M
125+
innodb_file_per_table = 1
126+
innodb_open_files = 400
127+
innodb_io_capacity = 400
128+
innodb_flush_method = O_DIRECT
129+
#
130+
# * Security Features
131+
#
132+
# Read the manual, too, if you want chroot!
133+
# chroot = /var/lib/mysql/
134+
#
135+
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
136+
#
137+
# ssl-ca=/etc/mysql/cacert.pem
138+
# ssl-cert=/etc/mysql/server-cert.pem
139+
# ssl-key=/etc/mysql/server-key.pem
140+
141+
142+
143+
[mysqldump]
144+
quick
145+
quote-names
146+
max_allowed_packet = 16M
147+
148+
[mysql]
149+
#no-auto-rehash # faster start of mysql but no tab completition
150+
151+
[isamchk]
152+
key_buffer = 16M

fedora-mariadb/start

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash -e
2+
3+
ln -s /dev/stderr /var/log/mysql/mysqld.log
4+
if [ ! -f /var/lib/mysql/.created ]; then
5+
function wait_for_mysqld_start {
6+
for i in {1..30}; do
7+
if echo 'select 1' | mysql -u root > /dev/null 2>&1; then
8+
return 0
9+
fi
10+
sleep 1
11+
done
12+
13+
echo "MariaDB did not start in time"
14+
exit 1
15+
}
16+
17+
password=${DB_PASSWORD:-password}
18+
dbname=${DB_NAME:-master}
19+
20+
/usr/bin/mysql_install_db -u mysql
21+
22+
/usr/libexec/mysqld &
23+
pid=$!
24+
25+
wait_for_mysqld_start
26+
27+
echo "Creating database $dbname ..."
28+
29+
sql=$(cat <<SQL
30+
drop database if exists test;
31+
create database \`$dbname\`
32+
DEFAULT CHARACTER SET utf8 DEFAULT
33+
COLLATE utf8_general_ci;
34+
SQL
35+
)
36+
echo $sql | mysql -u root
37+
38+
#delete from user;
39+
40+
sql=$(cat <<SQL
41+
delete from user where user='';
42+
grant all on *.* to 'mysql'@'localhost' identified by '$password' with grant option;
43+
grant all on *.* to 'mysql'@'%' identified by '$password' with grant option;
44+
flush privileges;
45+
SQL
46+
)
47+
echo $sql | mysql -u root mysql
48+
49+
touch /var/lib/mysql/.created
50+
kill -TERM $pid
51+
52+
echo "Starting mysqld ..."
53+
fi
54+
55+
exec /usr/libexec/mysqld

0 commit comments

Comments
 (0)