Accessing vagrant provider docker from vagrant virtualbox

I am running Vagrant and Virtualbox on Mac OS X. I have created one vagrant box using Virtualbox provider (some_centos machine) and second box using docker provider. Below you will see docker definition.

config.vm.define "mysql" do |m|
    m.vm.hostname = "mysql-host"
    m.vm.synced_folder ".", "/vagrant", disabled: true
    m.ssh.insert_key = false
      m.ssh.username = 'docker'
      m.ssh.password = 'tcuser' "public_network", use_dhcp_assigned_default_route: true

m.vm.provider "docker" do |docker|

  # Specify the Docker image to use
  docker.image = "mysql/mysql-server"

  # Specify port mappings
  # If omitted, no ports are mapped!

  docker.create_args = ["-p", "3306:3306","-e","MYSQL_ROOT_PASSWORD=password", "-e", "MYSQL_DATABASE=database"]

  # Specify a friendly name for the Docker container = 'mysql-server-container'

  #We want to keep it running.
  docker.remains_running = true


  • AWS Elastic Beanstalk, and multiple ports on docker run [duplicate]
  • how to list the nodes in docker swarm via api call?
  • Wildcard subdomain works on Docker CLI but not on Docker-Swarm with Docker-Compose
  • docker best way to run mysql
  • docker for windows mount a folder but can't open it after several hours
  • Cross compile net/http for distribution
  • Both machines do start up, but what I want to do is to access from “some_centos” host to that mysql docker machine by using mysql client to connect to it. Unfortunately I am failing. Please be aware that on Mac OS when you use vagrant docker provider it will create boot2docker iamge and then create docker. Not sure how to tackle the problem as e.g. I can ssh into “some_centos”, but can’t run mysql -h “docker-host” -uroot -p.

  • Docker run php script
  • Using network_mode='host' in docker-compose break run: host type networking can't be used with links
  • Wrong copy of folder in Dockerfile
  • Connecting to RDS Mysql from docker container with Wordpress
  • Error pulling image (latest) from centos, Authentication is required
  • How to download base docker image for creating hello world docker image?
  • One Solution collect form web for “Accessing vagrant provider docker from vagrant virtualbox”

    I have found a workaround for this. So it looks like on MAC OS X you need also do port forwarding on that virtual machine, but manually. So you need to run following:

    VBoxManage controlvm name_of_your_virtual_machine natpf1 "mysql,tcp,,3306,,3306"

    Then I was able to do the mysql. So I will need to add this a shell provisioner to my Vagrantfile.

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