MariaDB / mariadb-docker

Docker Official Image packaging for MariaDB
https://mariadb.org
GNU General Public License v2.0
770 stars 438 forks source link

Allow setting bind-addresss via env #312

Closed oliv3r closed 4 years ago

oliv3r commented 4 years ago

Using the database server as a container is great, but it currently only works by either volume mounting the socket, which only works on the same host or by entering the container, editing the config file and restarting the db, but not the container [0]. As docker containers tend to be ephemeral, these changes are lost of restart/update of the container, and have to be repeated.

One solution is to copy the config file into the volume (/var/lib/mysql) and volume mount the config file as well. But this makes the config files to get out of sync, if one does not really care about the config file and trusts the official docker image.

Alternatively the above solution could be forced, by changing '/etc/mysql/my.cnf' into a symlink point to '/var/lib/mysql/my.cnf' and copying a template '/usr/share/mysql/my.cnf.example' to '/var/lb/mysql/my.cnf' for example. This still has the same drawback as above.

The solution here, allows for the user to simply pass an environment variable and if set, we replace it in the config file. For the user, this is the most trivial way to host a mysql server. Obviously, this also puts the responsibility with the user, however as this user forced, the default remains the current 'more secure' way.

[0] https://mariadb.com/kb/en/installing-and-using-mariadb-via-docker/

Signed-off-by: Olliver Schinagl oliver@schinagl.nl

tianon commented 4 years ago

This is already trivial to accomplish via a custom command / args (see "Configuration without a cnf file" on https://hub.docker.com/_/mariadb):

$ docker pull mariadb:10.4
10.4: Pulling from library/mariadb
Digest: sha256:ade8a0e295a3c098e471fca9ca015df6b9c08c9b63cb6ac701d0f917a89c0a7b
Status: Image is up to date for mariadb:10.4
docker.io/library/mariadb:10.4

$ docker run -it --rm -e MYSQL_RANDOM_ROOT_PASSWORD=1 mariadb:10.4 --bind-address 1.2.3.4
2020-06-04 21:44:23+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.4.13+maria~bionic started.
...
2020-06-04 21:44:38 0 [Note] Server socket created on IP: '1.2.3.4'.
...
yosifkit commented 4 years ago

The images here (and the ones provided by MariaDB, mariadb/server) already comment out the bind-address of the default config in order to make the database accessible from other containers.

Here: https://github.com/docker-library/mariadb/blob/e680bfc5c70d133616141a495b9121d251682a92/Dockerfile.template#L112-L115

mariadb/server: https://github.com/mariadb-corporation/mariadb-server-docker/blob/e110b744fb3636fa0791ceab8249c031753a5651/10.4/Dockerfile#L118-L120

The MariaDB documentation you linked to is wrong about needing to comment out the bind address.

oliv3r commented 4 years ago

Ah, thanks! sorry for the noise, I was following the documentation :) I'll try again.

P.S. @yosifkit is anybody going to update the documentation? As surely it is confusing. Btw, I did check `/etc/mysql/my.cnf' and that setting was indeed still commented as far as I saw ..., as I did write the sed script while looking/checking the container ;)