本文介绍了DigitalOcean:如何通过Java API在新创建的Droplet上运行Docker命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个新的Droplet,然后通过UserData bash脚本启动Docker命令。在创建液滴时,我通过Java API设置用户数据,并观察我创建的测试文件和日志。

I'm trying to create a new Droplet and then kick off a Docker command via a UserData bash script. I set the user data via the Java API when creating the droplet and observe that the test files and logs I made are created.

newDroplet.setUserData("#!/bin/bash\n" +
            "touch /test.txt;"+
            "docker login --username=myname--password=mypass > /loginlog;"+
            "docker pull mybuild > /pulllog;"+
            "docker run --log-opt max-size=1g --net host --name myserver -t -i mybuild > /runlog;");

loginlog和pulllog都显示成功的结果。但是文件runlog中没有任何内容。

loginlog and pulllog both show successful outcomes. However nothing exists in the file runlog.

我可以将ssh插入到液滴中,然后运行完全相同的docker命令,并按预期运行。为什么不能从userdata脚本运行?为什么没有产生输出?

I can ssh into the droplet and then run the exact same docker command and it runs as expected. Why can't it be run from a userdata script? Why is no output generated?

推荐答案

该问题最终成为docker运行命令中的-t标志。显然这不行,因为它不是一个终端或类似的东西。移除标志,运行正常。

The problem ended up being the -t flag in the docker run command. Apparently this doesn't work because it isn't a terminal or something like that. Remove the flag and it runs fine.

这篇关于DigitalOcean:如何通过Java API在新创建的Droplet上运行Docker命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 14:31