0

This is my docker-compose.yml file, which has the environment variables specified (root username, password etc). However, when I run "docker-compose up", it is saying that MySQL is initializing with empty password!

Why? Is there a workaround?

This is the docker-compose.yml

version: '3.3'

services:
  db:
    image: mysql:5.7
          #build: sqldocker
    ports:
           -  "3306:3306"
    environment:
           - MYSQL_ROOT_PASSWORD=123456
           - MYSQL_DATABASE=testdb
           - MYSQL_USER=root
           - MYSQL_PASSWORD=123456
             # volumes:
            # - my-datavolume:/var/lib/mysql
    healthcheck:
           test: ["CMD", "mysqladmin", "ping"]
           timeout: 20s
           retries: 10
    restart: always
  backendserver:
    build: ./docker-demo-backend/
    ports:
           - "8080:8080"
    links:
           - "db"
    depends_on:
           - "db"
             # restart: always
  frontend:
    build: ./docker-demo-frontend/frontcrud
    links:
           - "backendserver"
    depends_on:
           - "backendserver"
    ports:
           - "80:80"
awesomemypro
  • 531
  • 1
  • 11
  • 32

3 Answers3

1

When you used this image mysql/5.7 , the startup is split into 2 steps .

The first step is to do the init of the db and you have this message

2019-11-05T15:01:23.167671Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

But just after the DB is stopped , and restarted . and you don't have anymore the warning .

EchoMike444
  • 1,513
  • 1
  • 9
  • 8
0

Please take a look at the workaround proposed at: How to use environment variables in docker compose

The method 2 suggest a way to define an .ENV file that contains the values for this kind of elements (passwords). It applies to PostgreSQL but it seems it might be of help. Kind regards.

thosleaf
  • 31
  • 5
0

Remove MYSQL_PASSWORD AND MYSQL_USER

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.

Do note that there is no need to use this mechanism to create the root superuser, that user gets created by default with the password specified by the MYSQL_ROOT_PASSWORD variable.

Meiram Chuzhenbayev
  • 898
  • 1
  • 10
  • 26