问题
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