yet-another-docker-plugin
yet-another-docker-plugin copied to clipboard
Allow using quoted strings in docker command
I want to run a command like /bin/sh -c 'some script here'
, but the command line is splitted into array ["/bin/sh", "-c", "'some", "script", "here'"]
instead of ["/bin/sh", "-c", "some script here"]
. Please fix parsing command line to allow escaping spaces (shell-like syntax would be the best).
Where do you want to run it? In dockerCloud this command will be overwritten in any case by launcher (or maybe entrypoint).
I'm trying to use ancient docker-freebsd (fork of docker 1.7; yes, it's a crap) with SSH launcher. I'm not sure that I will be able to get java working in it, but the problem I'm trying to solve currently is that I cannot run a script. It is not overridden, but it is splitted as I described and unusable.
Could you describe what at all do you want achieve and how freebsd is related?
I need FreeBSD inside a container. There are several problems, in particular DNS does not work until /etc/resolv.conf is fixed. This must be done after running the container because docker will overwrite it otherwise. So I'm trying to run sh -c 'echo "nameserver 1.2.3.4" > /etc/resolv.conf && /usr/sbin/sshd -D'
. The command specified in CMD
doesn't run for some reason, so I use "Docker Command" in "Create Container Settings".
launchers overriding cmd/entrypoint with their own commands. nameserver should be in create options afair. And better use JNLPLauncher...
--dns=IP_ADDRESS... | Sets the IP addresses added as nameserver lines to the container's/etc/resolv.conf file
https://docs.docker.com/engine/userguide/networking/default_network/configure-dns/
https://github.com/KostyaSha/yet-another-docker-plugin/blob/master/yet-another-docker-plugin/src/main/resources/com/github/kostyasha/yad/commons/DockerCreateContainer/help-dnsString.html
Thank you, but --dns
does not work in this case. I tried it before starting to invent ugly workarounds.
about cmd, i just stuck with the same issue in docker shell step they i'm implementing.
Shell, Shell for when RUN, CMD, and ENTRYPOINT uses a shell
do you know how implement right parsing?
Sorry, I'm not a Java coder, but some answers to very similar questions at SO suggest using regexes:
- Split string on spaces in Java, except if between quotes
- Tokenizing a String but ignoring delimiters within quotes
I personally would prefer something like this, in C-like pseudocode:
char quot = '\0';
for (char *p = s; *p != '\0'; p++) {
switch (*p) {
case '\'':
case '"':
if (quot == '\0') {
quot = *p; // open quote
} else if (quot == *p) {
quot = '\0'; // close quote
} else {
append_to_token(*p); // quoted quote
}
break;
case '\\':
p++;
append_to_token(*p); // escaped character
break;
case ' ':
case '\t':
if (quot) {
append_to_token(*p); // quoted space
} else {
end_token();
while (*(p+1) == ' ' || *(p+1) == '\t') p++; // skip spaces
}
break;
default:
append_to_token(*p);
break;
}
}
end_token();
ok, will pick something. PS My apple laptop gpu is crapped again...
https://github.com/KostyaSha/yet-another-docker-plugin/pull/178/files#diff-8f38882cbf864d4a172bd377b63443a8R318
@mikhirev please try newest version if it wouldn't work i will add parser tests.