【发布时间】:2018-02-16 18:36:16
【问题描述】:
我有一个(我想)使用 Java 来启动和停止 Docker 容器的应用程序。执行此操作的方法似乎是使用 docker-machine create,当我从命令行进行测试时效果很好。
但是,当使用 Java 中的 Commons-Exec 运行时,我得到了错误:
(aa4567c1-058f-46ae-9e97-56fb8b45211c) Creating SSH key...
Error creating machine: Error in driver during machine creation: /usr/local/bin/VBoxManage modifyvm aa4567c1-058f-46ae-9e97-56fb8b45211c --firmware bios --bioslogofadein off --bioslogofadeout off --bioslogodisplaytime 0 --biosbootmenu disabled --ostype Linux26_64 --cpus 1 --memory 1024 --acpi on --ioapic on --rtcuseutc on --natdnshostresolver1 off --natdnsproxy1 on --cpuhotplug off --pae on --hpet on --hwvirtex on --nestedpaging on --largepages on --vtxvpid on --accelerate3d off --boot1 dvd failed:
VBoxManage: error: Could not find a registered machine with UUID {aa4567c1-058f-46ae-9e97-56fb8b45211c}
VBoxManage: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBoxWrap, interface IVirtualBox, callee nsISupports
VBoxManage: error: Context: "FindMachine(Bstr(a->argv[0]).raw(), machine.asOutParam())" at line 500 of file VBoxManageModifyVM.cpp
我在用于启动机器的初始化脚本中设置了我的 VBOX_USER_HOME 变量:
export WORKERID=$1
export VBOX_USER_HOME=/Users/me/Library/VirtualBox
# create the machine
docker-machine create $WORKERID && \ # create the worker using docker-machine
eval $(docker-machine env $WORKERID) && \ # load the env of the newly created machine
docker run -d myimage
我正在通过 Commons Exec CommandLine 类从 Java 执行此操作:
CommandLine cmdline = new CommandLine("/bin/sh");
cmdline.addArgument(initializeWorkerScript.getAbsolutePath());
cmdline.addArgument("test");
Executor executor = new DefaultExecutor();
如果有另一个库可以与 Java 中的 docker-machine 接口,我很乐意使用它,或者如果这是问题所在,可以更换 Commons Exec(尽管我不明白为什么)。基本要求是我有办法让 docker-machine 使用 Java 创建一台机器,然后才能使用 docker-machine 停止该机器。
【问题讨论】:
标签: java bash docker-machine apache-commons-exec