0

我正在尝试使用 Vagrant 和 Docker 在 Windows 上创建一个虚拟化开发环境(很多人也是如此)。我遇到的问题是我无法从 Windows 笔记本电脑上运行的 MySQL Workbench 连接到 Boot2Docker 中 Docker 容器中的 MySQL DB。这就是我如何可视化连接:

MySQL 工作台 -> 3306 -> Boot2Docker -> 3306 -> Docker -> MySql

但是我无法从 MySQLWorkbench 连接到数据库。我尝试使用 Boot2Docker 框“.vagrant\machines\dockerhost\virtualbox\id”的私钥通过 ssh 连接到 3306 上的 Boot2Docker 主机 10.0.2.15 和 tcp

我做错了什么/我误解了什么。

我的流浪文件:ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'

DOCKER_HOST_NAME = "dockerhost"
DOCKER_HOST_VAGRANTFILE = "./host/Vagrantfile"

Vagrant.configure("2") do |config|

  config.vm.network "forwarded_port", guest: 3306, host: 3306

  config.vm.define "mysql" do |v|
    v.vm.provider "docker" do |d|
      d.image = "mysql"
      d.env = {
        :MYSQL_ROOT_PASSWORD => "root",
        :MYSQL_DATABASE     => "dockertest",
        :MYSQL_USER         => "dockertest",
        :MYSQL_PASSWORD     => "docker"
      }
      d.ports =["3306:3306"]
      d.remains_running = "true"
      d.vagrant_machine = "#{DOCKER_HOST_NAME}"
      d.vagrant_vagrantfile = "#{DOCKER_HOST_VAGRANTFILE}"
    end
  end
end

我的主机/Vagrantfile(描述我的 Boot2docker 主机)是:

FORWARD_DOCKER_PORTS='true'
Vagrant.configure(2) do |config|


  config.vm.provision "docker"

  # The following line terminates all ssh connections. Therefore
  # Vagrant will be forced to reconnect.
  # That's a workaround to have the docker command in the PATH

  #Clear any existing ssh connections
  ####NOTE: ps aux seems to give variable results depending on run -> process number can be ####first #or second causing provision to fail!!!
  config.vm.provision "clear-ssh", type: "shell", inline:
        "ps aux | grep 'sshd:' | awk '{print $1}'  | xargs kill"
#        "ps aux | grep 'sshd:' | awk '{print $2}' | xargs kill"


  config.vm.define "dockerhost"
  config.vm.box = "dduportal/boot2docker"
  config.vm.network "forwarded_port",guest: 8080, host: 8080


  config.vm.provider "virtualbox" do |vb|
          vb.name = "dockerhost"

  end

end
4

1 回答 1

1

解决了。因为我怀疑端口没有在主机和 docker 主机之间转发。解决方案是移动端口转发配置行:

config.vm.network "forwarded_port", guest: 3306, host: 3306

进入 docker 主机 Vagrant 文件。然后,Windows 主机上的 MySQL Workbench 可以连接到 localhost:3306。

于 2016-06-10T21:15:09.983 回答