From 9e6ca6cc920c0ff3dca4d0a04ca87889952290a2 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Mon, 27 Aug 2018 15:56:29 -0700 Subject: [PATCH] Add an "arbitrary user" section to MySQL --- mysql/content.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mysql/content.md b/mysql/content.md index ae89e5e64..54d3a6386 100644 --- a/mysql/content.md +++ b/mysql/content.md @@ -176,6 +176,17 @@ If the application you're trying to connect to MySQL does not handle MySQL downt If you start your `%%IMAGE%%` container instance with a data directory that already contains a database (specifically, a `mysql` subdirectory), the `$MYSQL_ROOT_PASSWORD` variable should be omitted from the run command line; it will in any case be ignored, and the pre-existing database will not be changed in any way. +## Running as an arbitrary user + +If you know the permissions of your directory are already set appropriately (such as running against an existing database, as described above) or you have need of running `mysqld` with a specific UID/GID, it is possible to invoke this image with `--user` set to any value (other than `root`/`0`) in order to achieve the desired access/configuration: + +```console +$ mkdir data +$ ls -lnd data +drwxr-xr-x 2 1000 1000 4096 Aug 27 15:54 data +$ docker run -v "$PWD/data":/var/lib/mysql --user 1000:1000 --name some-%%REPO%% -e MYSQL_ROOT_PASSWORD=my-secret-pw -d %%IMAGE%%:tag +``` + ## Creating database dumps Most of the normal tools will work, although their usage might be a little convoluted in some cases to ensure they have access to the `mysqld` server. A simple way to ensure this is to use `docker exec` and run the tool from the same container, similar to the following: