Skip to content

Commit 1cfd07b

Browse files
committed
move to a universal ENV file in config from team feedback
1 parent 098296a commit 1cfd07b

File tree

3 files changed

+67
-31
lines changed

3 files changed

+67
-31
lines changed

README.md

+35-18
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,14 @@ docker create \
6262
--name=mariadb \
6363
-e PUID=1000 \
6464
-e PGID=1000 \
65-
-e MYSQL_ROOT_PASSWORD=<DATABASE PASSWORD> \
65+
-e MYSQL_ROOT_PASSWORD=ROOT_ACCESS_PASSWORD \
6666
-e TZ=Europe/London \
67-
-e MYSQL_DATABASE=<USER DB NAME> `#optional` \
68-
-e MYSQL_USER=<MYSQL USER> `#optional` \
69-
-e MYSQL_PASSWORD=<DATABASE PASSWORD> `#optional` \
70-
-e MYSQL_ROOT_PASSWORD_FILE=/location/of/file `#optional` \
67+
-e MYSQL_DATABASE=USER_DB_NAME `#optional` \
68+
-e MYSQL_USER=MYSQL_USER `#optional` \
69+
-e MYSQL_PASSWORD=DATABASE_PASSWORD `#optional` \
7170
-e REMOTE_SQL=http://URL1/your.sql,https://URL2/your.sql `#optional` \
7271
-p 3306:3306 \
73-
-v <path to data>:/config \
72+
-v path_to_data:/config \
7473
--restart unless-stopped \
7574
linuxserver/mariadb
7675
```
@@ -90,15 +89,14 @@ services:
9089
environment:
9190
- PUID=1000
9291
- PGID=1000
93-
- MYSQL_ROOT_PASSWORD=<DATABASE PASSWORD>
92+
- MYSQL_ROOT_PASSWORD=ROOT_ACCESS_PASSWORD
9493
- TZ=Europe/London
95-
- MYSQL_DATABASE=<USER DB NAME> #optional
96-
- MYSQL_USER=<MYSQL USER> #optional
97-
- MYSQL_PASSWORD=<DATABASE PASSWORD> #optional
98-
- MYSQL_ROOT_PASSWORD_FILE=/location/of/file #optional
94+
- MYSQL_DATABASE=USER_DB_NAME #optional
95+
- MYSQL_USER=MYSQL_USER #optional
96+
- MYSQL_PASSWORD=DATABASE_PASSWORD #optional
9997
- REMOTE_SQL=http://URL1/your.sql,https://URL2/your.sql #optional
10098
volumes:
101-
- <path to data>:/config
99+
- path_to_data:/config
102100
ports:
103101
- 3306:3306
104102
restart: unless-stopped
@@ -113,12 +111,11 @@ Container images are configured using parameters passed at runtime (such as thos
113111
| `-p 3306` | Mariadb listens on this port. |
114112
| `-e PUID=1000` | for UserID - see below for explanation |
115113
| `-e PGID=1000` | for GroupID - see below for explanation |
116-
| `-e MYSQL_ROOT_PASSWORD=<DATABASE PASSWORD>` | Set this to root password for installation (minimum 4 characters). |
114+
| `-e MYSQL_ROOT_PASSWORD=ROOT_ACCESS_PASSWORD` | Set this to root password for installation (minimum 4 characters). |
117115
| `-e TZ=Europe/London` | Specify a timezone to use EG Europe/London. |
118-
| `-e MYSQL_DATABASE=<USER DB NAME>` | Specify the name of a database to be created on image startup. |
119-
| `-e MYSQL_USER=<MYSQL USER>` | This user will have superuser access to the database specified by MYSQL_DATABASE. |
120-
| `-e MYSQL_PASSWORD=<DATABASE PASSWORD>` | Set this to the password you want to use for you MYSQL_USER (minimum 4 characters). |
121-
| `-e MYSQL_ROOT_PASSWORD_FILE=/location/of/file` | Set this to the location of a text file containing your password. |
116+
| `-e MYSQL_DATABASE=USER_DB_NAME` | Specify the name of a database to be created on image startup. |
117+
| `-e MYSQL_USER=MYSQL_USER` | This user will have superuser access to the database specified by MYSQL_DATABASE (do not use root here). |
118+
| `-e MYSQL_PASSWORD=DATABASE_PASSWORD` | Set this to the password you want to use for you MYSQL_USER (minimum 4 characters). |
122119
| `-e REMOTE_SQL=http://URL1/your.sql,https://URL2/your.sql` | Set this to ingest sql files from an http/https endpoint (comma seperated array). |
123120
| `-v /config` | Contains the db itself and all assorted settings. |
124121

@@ -143,7 +140,7 @@ If you didn't set a password during installation, (see logs for warning) use
143140
`mysqladmin -u root password <PASSWORD>`
144141
to set one at the docker prompt...
145142

146-
NOTE changing the MYSQL_ROOT_PASSWORD or MYSQL_ROOT_PASSWORD_FILE variable after the container has set up the initial databases has no effect, use the mysqladmin tool to change your mariadb password.
143+
NOTE changing the MYSQL_ROOT_PASSWORD variable after the container has set up the initial databases has no effect, use the mysqladmin tool to change your mariadb password.
147144

148145
NOTE if you want to use (MYSQL_DATABASE MYSQL_USER MYSQL_PASSWORD) **all three** of these variables need to be set you cannot pick and choose.
149146

@@ -152,6 +149,26 @@ Unraid users, it is advisable to edit the template/webui after setup and remove
152149
Find custom.cnf in /config for config changes (restart container for them to take effect)
153150
, the databases in /config/databases and the log in /config/log/myqsl
154151

152+
### Loading passwords and users from files
153+
154+
The `MYSQL_ROOT_PASSWORD MYSQL_DATABASE MYSQL_USER MYSQL_PASSWORD REMOTE_SQL` env values can be set in a file:
155+
156+
```
157+
/config/env
158+
```
159+
160+
Using the following format:
161+
162+
```
163+
MYSQL_ROOT_PASSWORD="ROOT_ACCESS_PASSWORD"
164+
MYSQL_DATABASE="USER_DB_NAME"
165+
MYSQL_USER="MYSQL_USER"
166+
MYSQL_PASSWORD="DATABASE_PASSWORD"
167+
REMOTE_SQL="http://URL1/your.sql,https://URL2/your.sql"
168+
```
169+
170+
These settings can be mixed and matched with Docker ENV settings as you require, but the settings in the file will always take precedence.
171+
155172
### Bootstrapping a new instance
156173

157174
We support a one time run of custom sql files on init. In order to use this place `*.sql` files in:

readme-vars.yml

+26-7
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ param_container_name: "{{ project_name }}"
2323
param_usage_include_net: false
2424
param_usage_include_env: true
2525
param_env_vars:
26-
- { env_var: "MYSQL_ROOT_PASSWORD", env_value: "<DATABASE PASSWORD>", desc: "Set this to root password for installation (minimum 4 characters)." }
26+
- { env_var: "MYSQL_ROOT_PASSWORD", env_value: "ROOT_ACCESS_PASSWORD", desc: "Set this to root password for installation (minimum 4 characters)." }
2727
- { env_var: "TZ", env_value: "Europe/London", desc: "Specify a timezone to use EG Europe/London." }
2828
param_usage_include_vols: true
2929
param_volumes:
30-
- { vol_path: "/config", vol_host_path: "<path to data>", desc: "Contains the db itself and all assorted settings." }
30+
- { vol_path: "/config", vol_host_path: "path_to_data", desc: "Contains the db itself and all assorted settings." }
3131
param_usage_include_ports: true
3232
param_ports:
3333
- { external_port: "3306", internal_port: "3306", port_desc: "Mariadb listens on this port." }
@@ -37,10 +37,9 @@ cap_add_param: false
3737
# optional container parameters
3838
opt_param_usage_include_env: true
3939
opt_param_env_vars:
40-
- { env_var: "MYSQL_DATABASE", env_value: "<USER DB NAME>", desc: "Specify the name of a database to be created on image startup." }
41-
- { env_var: "MYSQL_USER", env_value: "<MYSQL USER>", desc: "This user will have superuser access to the database specified by MYSQL_DATABASE." }
42-
- { env_var: "MYSQL_PASSWORD", env_value: "<DATABASE PASSWORD>", desc: "Set this to the password you want to use for you MYSQL_USER (minimum 4 characters)." }
43-
- { env_var: "MYSQL_ROOT_PASSWORD_FILE", env_value: "/location/of/file", desc: "Set this to the location of a text file containing your password." }
40+
- { env_var: "MYSQL_DATABASE", env_value: "USER_DB_NAME", desc: "Specify the name of a database to be created on image startup." }
41+
- { env_var: "MYSQL_USER", env_value: "MYSQL_USER", desc: "This user will have superuser access to the database specified by MYSQL_DATABASE (do not use root here)." }
42+
- { env_var: "MYSQL_PASSWORD", env_value: "DATABASE_PASSWORD", desc: "Set this to the password you want to use for you MYSQL_USER (minimum 4 characters)." }
4443
- { env_var: "REMOTE_SQL", env_value: "http://URL1/your.sql,https://URL2/your.sql", desc: "Set this to ingest sql files from an http/https endpoint (comma seperated array)." }
4544
opt_param_usage_include_vols: false
4645
opt_param_usage_include_ports: false
@@ -55,7 +54,7 @@ app_setup_block: |
5554
`mysqladmin -u root password <PASSWORD>`
5655
to set one at the docker prompt...
5756
58-
NOTE changing the MYSQL_ROOT_PASSWORD or MYSQL_ROOT_PASSWORD_FILE variable after the container has set up the initial databases has no effect, use the mysqladmin tool to change your mariadb password.
57+
NOTE changing the MYSQL_ROOT_PASSWORD variable after the container has set up the initial databases has no effect, use the mysqladmin tool to change your mariadb password.
5958
6059
NOTE if you want to use (MYSQL_DATABASE MYSQL_USER MYSQL_PASSWORD) **all three** of these variables need to be set you cannot pick and choose.
6160
@@ -64,6 +63,26 @@ app_setup_block: |
6463
Find custom.cnf in /config for config changes (restart container for them to take effect)
6564
, the databases in /config/databases and the log in /config/log/myqsl
6665
66+
### Loading passwords and users from files
67+
68+
The `MYSQL_ROOT_PASSWORD MYSQL_DATABASE MYSQL_USER MYSQL_PASSWORD REMOTE_SQL` env values can be set in a file:
69+
70+
```
71+
/config/env
72+
```
73+
74+
Using the following format:
75+
76+
```
77+
MYSQL_ROOT_PASSWORD="ROOT_ACCESS_PASSWORD"
78+
MYSQL_DATABASE="USER_DB_NAME"
79+
MYSQL_USER="MYSQL_USER"
80+
MYSQL_PASSWORD="DATABASE_PASSWORD"
81+
REMOTE_SQL="http://URL1/your.sql,https://URL2/your.sql"
82+
```
83+
84+
These settings can be mixed and matched with Docker ENV settings as you require, but the settings in the file will always take precedence.
85+
6786
### Bootstrapping a new instance
6887
6988
We support a one time run of custom sql files on init. In order to use this place `*.sql` files in:

root/etc/cont-init.d/40-initialise-db

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ done
1515
# test for existence of mysql file in datadir and start initialise if not present
1616
if [ ! -d "$DATADIR/mysql" ]; then
1717

18+
# load env file if it exists
19+
if [ -f "/config/env" ]; then
20+
source /config/env
21+
fi
22+
1823
# set basic sql command
1924
tempSqlFile='/tmp/mysql-first-time.sql'
2025
cat > "$tempSqlFile" <<-EOSQL
@@ -34,12 +39,7 @@ EOFPASS
3439

3540
# test for empty password variable, if it's set to 0 or less than 4 characters
3641
if [ -z "$MYSQL_ROOT_PASSWORD" ]; then
37-
if [ -f "$MYSQL_ROOT_PASSWORD_FILE" ]; then
38-
MYSQL_ROOT_PASSWORD=$(< "$MYSQL_ROOT_PASSWORD_FILE")
39-
TEST_LEN=${#MYSQL_ROOT_PASSWORD}
40-
else
41-
TEST_LEN="0"
42-
fi
42+
TEST_LEN="0"
4343
else
4444
TEST_LEN=${#MYSQL_ROOT_PASSWORD}
4545
fi

0 commit comments

Comments
 (0)