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

  • Docker Container Best Practices
  • Copy directory to other directory at Docker using ADD command
  • Docker in IntelliJ IDEA for Mac not working
  • Kubernetes 1.2.2: api-server fails: can't find mounted certs for TLS on etcd
  • copy file from container to the host before the container dies
  • Docker: Output shown at http://192.168.99.100:8000/ instead of http://0.0.0.0:8000/
  • I mapped 3306 -> 3306 and using the host IP. Still getting a timeout. What could this be?

  • curl: (7) Failed to connect to 172.17.0.8 port 80: Connection refused
  • Docker Push Fails
  • tar command not found in Dockerfile
  • Gradle build fails in jenkins:alpine container: UnsatisfiedLinkError: linux-amd64/libnative-platform.so: libstdc++.so.6:
  • Wordpress inside docker container behind nginx proxy with ssl
  • Pull a local image to run a pod in Kubernetes
  • 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.