Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Not Adding User To MariaDB With Dockerfile

Tags:

docker

mariadb

So this is my Dockerfile,

FROM mariadb:10.3.5

RUN apt-get update & apt-get upgrade -y

ENV MYSQL_USER=user1 \
    MYSQL_USER_PASSWORD=pass5 \
    MYSQL_DATABASE=db \
    MYSQL_ROOT_PASSWORD=XXX

ADD . /

WORKDIR /

However, this does not add my user1 to the database build. The root password works but that is it. I have completely removed all the pass tests i have done, including all volume data but still does not add the user. So what am I doing wrong?

Thanks,

like image 737
Coder99 Avatar asked Mar 27 '18 12:03

Coder99


People also ask

How do I connect to MariaDB in docker container?

Execute the following to connect to MariaDB using the command-line client: > docker exec -it mdb mariadb --user root -pPassword123! And that's it! That's all you need to connect to and start using (querying) MariaDB.


1 Answers

Official mariadb docker image has built-in enviromental variables MYSQL_USER and MYSQL_PASSWORD:

These variables are optional, used in conjunction to create a new user and to set that user's password. This user will be granted superuser permissions (see above) for the database specified by the MYSQL_DATABASE variable. Both variables are required for a user to be created.

So, the variable MYSQL_PASSWORD was misspelled (it was defined as MYSQL_USER_PASSWORD) and that's why mysql user was not created at all.

The correct Dockerfile is:

FROM mariadb:10.3.5

RUN apt-get update & apt-get upgrade -y

ENV MYSQL_USER=user1 \
    MYSQL_PASSWORD=pass5 \
    MYSQL_DATABASE=db \
    MYSQL_ROOT_PASSWORD=XXX

ADD . /

WORKDIR /
like image 116
nickgryg Avatar answered Oct 14 '22 04:10

nickgryg