skip to Main Content

Hello currently I get in touch with Docker. I am doing their getting started and I ran into a problem which I cant solve and I dont understand why it dont work. First of all I create a network using.

$ docker network create todo-app

After that, I set up a Container mysql database and connect it with the network with following code.

$  docker run -d 
 --network todo-app --network-alias mysql 
 -v todo-mysql-data:/var/lib/mysql 
 -e MYSQL_ROOT_PASSWORD=secret 
 -e MYSQL_DATABASE=todos 
 mysql:5.7

I check for the Container id with

$ docker ps 

After that I use the command to get into the mysql CLI ? (not sure on that yet)

$ docker exec -it mysql -u root -p

After getting there I use

mysql> SHOW DATABASES; 

to show all DB on my PC? But there is non listed named todos and i dont know why it dont appear.

I would like to hear what you are thinking im struggeling a little there. Thanks for the replies. Sorry for my english skills.

3

Answers


  1. Chosen as BEST ANSWER

    Sorry for the trouble it was my fault I guess cause I used the Command I pointed out above but I definetly had to use this command :

     docker run -d 
     --network todo-app --network-alias mysql 
     --platform "linux/amd64" 
     -v todo-mysql-data:/var/lib/mysql 
     -e MYSQL_ROOT_PASSWORD=secret 
     -e MYSQL_DATABASE=todos 
     mysql:5.7
    

    Because im using Linux... Such a dumb mistake but i swear this wasnt there two months ago when I asked this Qeustion.


  2. Run container in the foreground and check the logs.

    Login or Signup to reply.
  3. Following Part 7: Multi-container apps, I ran into this exact issue just now.

    Chances are, you have run that same command at least once.

    # command to run as per the docs
    docker run -d 
        --network todo-app --network-alias mysql 
        -v todo-mysql-data:/var/lib/mysql 
        -e MYSQL_ROOT_PASSWORD=secret 
        -e MYSQL_DATABASE=todos 
        mysql:5.7
    

    And the first time you ran the command you unknowingly made a mistake. For me, I mistyped MYSQL_DATABASE FOR MYSQL_ROOT_PASSWORD. Yours might be different. In any case, it seems making small mistakes like this might have caused the mysql:5.7 image to not be set up correctly with the todos database. (Not entirely sure.)

    Adding to that, the first time you run that command, Docker creates a todo-mysql-data volume, which does not get overwritten when you run that same command again.

    So as a "fix", you might have to delete the todo-mysql-data volume first.

    docker volume rm todo-mysql-data
    

    And then re-create the todo-mysql-data volume implicitly by re-running the image with the above command; this time without mistakes.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search