MySQL version: 5.7.12
I send this via command line and the "demo" database is created, as is the "demouser" user:
docker run -e MYSQL_ROOT_PASSWORD=secret -e MYSQL_DATABASE=demo -e MYSQL_USER=demouser -e MYSQL_PASSWORD=demopassword -d mysql:5.7.12
When I run via docker-compose, the "demo" database is _not_ created. Here is the relevant info from docker-compose.yml:
db:
image: mysql:5.7.12
environment:
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_DATABASE=demo
- MYSQL_USER=demouser
- MYSQL_PASSWORD=demopassword
ports:
- 3306:3306
I noticed that the shell process for docker run is "/entrypoint.sh mysql" but docker-composer runs "docker-entrypoint.sh". Why does docker-entrypoint.sh differ in behaviour?
Those two enrypoints are the same file: see dockerfile line 60. I am unable to reproduce using your docker-compose file:
$ docker-compose up -d
$ docker run -it --link tmp_db_1:mysql --rm mysql sh -c 'exec mysql -hmysql -uroot -psecret'mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.12 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| demo |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql>
Did you start your database before you added the MYSQL_DATABASE env? docker-compose tries hard to keep volumes around and those environment variables are only used on the first startup of the container. Try using docker-compose stop db and docker-compose rm -fv db to get rid of the container and any volumes associated with it; then docker-compose up -d should work fine.
That seems to be it. Now getting some _better_ errors (which I'll fix):
ERROR 1130 (HY000): Host '172.17.0.3' is not allowed to connect to this MySQL server
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Will be adding some "cleanup" routines! Thanks.
Most helpful comment
Those two enrypoints are the same file: see dockerfile line 60. I am unable to reproduce using your docker-compose file:
Did you start your database before you added the
MYSQL_DATABASEenv?docker-composetries hard to keep volumes around and those environment variables are only used on the first startup of the container. Try usingdocker-compose stop dbanddocker-compose rm -fv dbto get rid of the container and any volumes associated with it; thendocker-compose up -dshould work fine.