DigitalOcean: How to run Docker command on newly created Droplet via Java API

让人想犯罪 __ 提交于 2019-12-13 17:22:37

问题


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 and pulllog both show successful outcomes. However nothing exists in the file runlog.

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?


回答1:


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.



来源:https://stackoverflow.com/questions/40924883/digitalocean-how-to-run-docker-command-on-newly-created-droplet-via-java-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!