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' m.vm.network "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 docker.name = 'mysql-server-container' #We want to keep it running. docker.remains_running = true end
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.
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.