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

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

    editd docker-compose.yaml is not work when you already start that container,

    so I support this way:

    1: chack you db containers that already exist

    docker ps
    
    CONTAINER ID        NAMES               PORTS       STATUS
    1cbfe602466a        mysql5.7                        Exited (0) About an hour ago
    

    2: if the container has been stared,then stop it and rm

    docker stop 1cbfe602466a //(mysql5.7)
    docker rm 1cbfe602466a
    

    3: now you can Restart mysql container,

    docker-compose.yaml //(Pay attention to formatting your code)

      mysql5.7:
        container_name: mysql5.7
        image: mysql:5.7
        restart: always
        environment:
          - MYSQL_ROOT_PASSWORD=root
        ports:
          - 3306:3306
    

    4: run commend:

    docker-compose up -d mysql5.7
    

    5: you are success! you can check it into container .

    docker exec -it mysql5.7 /bin/bash
    
    root@1719480b6716:/# mysql -u root -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 3
    Server version: 5.7.29-log MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>
    
    
    
    0 讨论(0)
提交回复
热议问题