connecting to a docker-compose mysql container denies access but docker running same image does not

前端 未结 7 497
情歌与酒
情歌与酒 2020-12-01 05:26

I am having some issues connecting to the mysql docker container that I have launched with docker-compose. This is a long post (sorry!).

Here is my docker-compose.ym

7条回答
  •  眼角桃花
    2020-12-01 05:35

    Environment variables in docker-compose.yml file should not have quotes when using array definition:

    db:
      image: mysql:5.7
      ports:
        - "3306:3306"
      environment:
        - MYSQL_ROOT_PASSWORD=secret
        - MYSQL_USER=django
        - MYSQL_PASSWORD=secret
        - MYSQL_DATABASE=myAppDB
    

    If you use them in your docker-compose.yml file:

    db:
      image: mysql:5.7
      ports:
        - "3306:3306"
      environment:
        - MYSQL_ROOT_PASSWORD="secret"
        - MYSQL_USER="django"
        - MYSQL_PASSWORD="secret"
        - MYSQL_DATABASE="myAppDB"
    

    and run:

    $ docker-compose up -d
    

    and enter running container:

    $ docker-compose exec db /bin/bash
    

    you will see the output:

    root@979813643b0c:/# echo $MYSQL_ROOT_PASSWORD                                                                                                                                              
    "secret"
    

提交回复
热议问题