This is what I see when I am in the container created by docker-compose:
mysql> SELECT user FROM mysql.user;
+------+
| user |
+------+
| root |
+------+
1 row in set (0.00 sec)
root@541e4d686184:/# echo $MYSQL_USER
dbuser
So dbuser
is not present in the users table even though the $MYSQL_USER
is set properly .
In docker-compose.yml
I have this:
version: '2'
services:
db:
image: mysql:latest
environment:
MYSQL_DATABASE: mydb
MYSQL_USER: dbuser
MYSQL_PASSWORD: userpass
MYSQL_ROOT_PASSWORD: password
ports:
- "3306"
volumes:
- ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
- my-datavolume:/var/lib/mysql
volumes:
my-datavolume:
I expected dbuser
to be created automatically, but that didn't happen.
I also have a sql
file to create my database and tables if they don't already exist, but right now tomcat can't connect to my database.
Same symptoms as this question, but I am already using a dictionary for my usernames/passwords.
UPDATE:
I am getting close. When inside container I manually did:
/docker-entrypoint-initdb.d/create_users.sh
Then the user was created inside MySQL
table and I was able to deploy my application to my tomcat
server and I didn't get an error about dbuser
being denied access.
So, why did I have to run this command myself, it should be run by docker-compose, according to the mysql docker docs under Initializing a fresh instance.
docker logs
? The mysql logs? Did you consider user permissions issues? Did you consider using the mysql client for running your sql script? (e.g./usr/bin/mysql < /path/to/script.sql
) – TrilobateMYSQL_ALLOW_EMPTY_PASSWORD
but this only applies to the root user not theMYSQL_USER
There was a message in the logsMYSQL_USER specified, but missing MYSQL_PASSWORD; MYSQL_USER will not be created
– Devious