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

前端 未结 7 471
情歌与酒
情歌与酒 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:31

    In my case I had mariadb installed and was trying to start a mysql container. Somehow starting the container didn't fail and running docker ps showed the container as listening on 3306, but in reality, the mariad mysqld was running and I was getting access denied. to that db rather than the one in the container. I'm using a Mac and was able to stop mariadb with: launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist

    0 讨论(0)
  • 2020-12-01 05:34

    I had a similar issue, and this helped me:

    https://github.com/docker-library/mysql/issues/51#issuecomment-76989402

    Have you changed the passwords since you first tried running the containers? docker-compose does extra work to preserve volumes between runs (thus preserving the database); you may want to try docker-compose rm -v to delete everything and try starting it up again.

    0 讨论(0)
  • 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"
    
    0 讨论(0)
  • 2020-12-01 05:40

    It looks like your problem is solved. I thought I'd discuss my problems similar to this.

    I am running tomcat (web) and mysql (db) using docker-compose on a Synology NAS (DSM 6.0.2). It worked fine on an Ubuntu box I have but not on the NAS.

    The problem was the firewall on the NAS - I had modified my firewall rules to allow certain ports open but then DENY ALL at end. When I added :3306 to the allowed ports it worked!

    This is not a good solution and I don't know why DSM would require this since the docker-compose is running on a BRIDGE network. I've put in a support ticket about this.

    This answer may help others with this blocked container issue.

    0 讨论(0)
  • 2020-12-01 05:43

    I had the same error "Access denied for user 'admin'@'172.20.0.1' (using password: YES)". And for the long time could not figure out how to resolve it. In my situation docker-compose takes configuration from .env file.

    environment:
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_USER: ${DB_USERNAME}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
    

    Finally I have found issue! The problem was in double quots in parameters.

    DB_PASSWORD="dbpassword"
    

    doesn't work

    DB_PASSWORD=dbpassword
    

    work

    0 讨论(0)
  • 2020-12-01 05:49

    I am using the official mysql image with docker-compose and not having a problem. The only difference in my compose file is that I am using a dictionary instead of an array:

    environment:
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_USER: django
      MYSQL_PASSWORD: secret
      MYSQL_DATABASE: myAppDB
    

    I have noticed that the compose file documentation is still stuck in V1 in some places, so you could try this, if you're using V2. Otherwise, for debugging you can use docker-compose exec to interact with the container created by compose directly.

    docker-compose exec db /bin/bash will get you a shell on the container that is giving you trouble and you can check things like SHOW GRANTS FOR django@'%' or whether the ports are being forwarded correctly. I hope this helps.

    0 讨论(0)
提交回复
热议问题