Docker-compose: Database is uninitialized

后端 未结 5 1444
轻奢々
轻奢々 2021-02-18 17:02

I have a problem with docker-compose and mysql:

docker-compose.yml

version: \'2\' 
  services:
   db:
    image: mysql
    volumes:
      - \"./sito/db/:         


        
5条回答
  •  一个人的身影
    2021-02-18 17:58

    The problem will appear if you don't specify a value for MYSQL_ROOT_PASSWORD (other cases explained below).

    You can use one of the following syntax below:

    # syntax 1
    environment:
      MYSQL_ROOT_PASSWORD: strongrootpassword
    
    # syntax 2
    environment:
     - MYSQL_ROOT_PASSWORD=strongrootpassword
    

    If you wish to use blank/empty password then use the following:

    MYSQL_ALLOW_EMPTY_PASSWORD=1
    

    If you wish to set a random password then use the following:

    MYSQL_RANDOM_ROOT_PASSWORD=1
    

    Then you can get the generated password using

    docker logs container_name_or_id 
    

    In the end you need to specify ONE of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD according to the entrypoint of MySQL image:

    • -z is to verify that the variable is not empty
    if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" -a -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
        echo >&2 'error: database is uninitialized and password option is not specified '
        echo >&2 '  You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD'
        exit 1
    fi
    

提交回复
热议问题