0

I am quite new to Docker and I have run into a problem. The basic thing I'm trying to do, is to connect a java service to a mysql database.

The setup is that I have one Dockerfile for the service, and a separate one for mysql. Then I'm connecting these through a docker-compose file.

The Dockerfile for the database copies a db dump into the container, but it's not working when I check it in mysql workbench (or sequel pro). Both containers are up and running.

I have created a new user in workbench called dbuser with the right password. But this user is not granted access to create this database.

I had problems with the passwords in workbench earlier on, and got passed them by changing the mysql image from :latest to :5.7.

I can connect to localhost:3307 in Workbench but there is no database there.

The dump grants all access to my dbuser. I have inspected the container and the image so I know the dump is in there. But it seems like Docker never get to the point of running the dump, and I suspect that this is due to something I have done wrong.

All help is very appreciated!

Dockerfile for db

FROM mysql:5.7

ENV MYSQL_ROOT_PASSWORD=root
ENV MYSQL_ALLOW_SECRET_PASSWORD=yes

COPY Dump20180430.sql /docker-entrypoint-initdb.d

docker-compose

version: '3.4'

services:
  productservicejava:
    image: productservicejava
    build:
      context: .
      dockerfile: Dockerfile
    depends_on:
      - db
    ports:
      - "8080:8080"
  db:
    image: productservicedb
    build:
      context: .
      dockerfile: DockerfileDb
    ports:
      - "3307:3306"

Edit: adding part of the log from running the db container. No errors but some warnings.

db_1                  | 2018-05-24T12:13:38.522966Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1                  | 2018-05-24T12:13:38.524314Z 0 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
db_1                  | 2018-05-24T12:13:38.524363Z 0 [Warning] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1                  | 2018-05-24T12:13:38.524377Z 0 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1                  | 2018-05-24T12:13:38.524412Z 0 [Warning] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1                  | 2018-05-24T12:13:38.524419Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
db_1                  | 2018-05-24T12:13:38.524432Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
db_1                  | 2018-05-24T12:13:38.527659Z 0 [Warning] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
db_1                  | 2018-05-24T12:13:38.527679Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
fofoky
  • 11
  • 1
  • 6
  • 1
    do you have any error in the logs when you run the mysql image? – b0gusb May 24 '18 at 14:49
  • I don't get any errors, just warnings, I'll add them to the question @b0gusb – fofoky May 24 '18 at 17:22
  • Also, I tried to open a db connection for the user in MySql Workbench and then manually add a db called productdb, but then get the error: ERROR 1044: Access denied for user 'dbuser'@'%' to database 'productdb' SQL Statement: CREATE SCHEMA `productdb`. I guess this is because the permission is granted in the dump, which is never read, but I also tried to add these permissions manually, but no success. – fofoky May 24 '18 at 17:45
  • The scripts in ``docker-entrypoint-initdb.d`` are run only once during the initialization of the container. If you just stop/start the container this part is obviously skipped. The configuration seems right so if you run the container with docker run you should see the output from the dump. – b0gusb May 25 '18 at 06:26
  • @b0gusb I run it with docker-compose up which builds and run, and I can tell by the logs that it sometimes initiates the Dump file. The log will either state: /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/Dump20180430.sql ERROR 1273 (HY000) at line 32: Unknown collation: 'utf8mb4_0900_ai_ci' In the above case it will create the db productdb, but not the tables and the content. But when changing this error, to 'utf8mb4_general_ci', neither the info that the dump is running, nor the error occurs. And the db is not created. – fofoky May 25 '18 at 15:58
  • You're probably using a newer version of mysql. This might help you. https://stackoverflow.com/questions/29916610/1273-unknown-collation-utf8mb4-unicode-ci-cpanel. – b0gusb May 29 '18 at 05:17
  • thanks again @b0gusb - What I needed to do was to change the order of events in the Dump, so that the user get permission to the database before the database is created. No one could've known since the dump is not provided in my question. – fofoky May 29 '18 at 08:28

0 Answers0