Can't access SQL db inside Docker container

I have a SQL db running successfully. However, I cannot access it in my SQL client.

docker run -it --name sql_key_container -e MYSQL_ROOT_PASSWORD=testpw -e MYSQL_DATABASE=key_volume -p 3306:3306 -d myimgname/ubuntumaria:0.2

I verified it’s running by docker exec fcd12bf1da81 /etc/init.d/mysql status

  • Unable to connect to SQL Server Linux Docker container via SQL Server Management Studio
  • Running Client program and API in same Docker Machine
  • Registry can't find all images in the repository when doing Docker search
  • CrashLoopBackOff when args are added in Kubernetes
  • Docker compose redundancy?
  • Regarding docker daemon to spawn containers in a custom CIDR block
  • I mapped 3306 -> 3306 and using the host IP. Still getting a timeout. What could this be?

  • Synced Folder Error with Docker Provider on Vagrant
  • How to see tree view of docker images?
  • lsb_release of the host OS in a Docker
  • Laradock (container) files on Windows
  • Docker with GUI application
  • What are the possibilities to debug a docker swarm?
  • One Solution collect form web for “Can't access SQL db inside Docker container”

    You have now a database in container fcd12bf1da81 running, listening on its local IP and on the host IP on port 3306.

    If you want your new container sql_key_container to access that database, then the container needs access to fcd12bf1da81.

    You need to --link:

    docker run -it --link fcd12bf1da81:mydb --name sql_key_container -e MYSQL_ROOT_PASSWORD=testpw -e MYSQL_DATABASE=key_volume -p 3306:3306 -d myimgname/ubuntumaria:0.2 
    

    and now you can access the db inside that container with mydb:3306.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.