yet-another-docker-plugin icon indicating copy to clipboard operation
yet-another-docker-plugin copied to clipboard

Allow using quoted strings in docker command

Open mikhirev opened this issue 7 years ago • 14 comments

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).

mikhirev avatar Jul 25 '17 16:07 mikhirev

Where do you want to run it? In dockerCloud this command will be overwritten in any case by launcher (or maybe entrypoint).

KostyaSha avatar Jul 25 '17 16:07 KostyaSha

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.

mikhirev avatar Jul 25 '17 16:07 mikhirev

Could you describe what at all do you want achieve and how freebsd is related?

KostyaSha avatar Jul 25 '17 17:07 KostyaSha

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".

mikhirev avatar Jul 25 '17 17:07 mikhirev

launchers overriding cmd/entrypoint with their own commands. nameserver should be in create options afair. And better use JNLPLauncher...

KostyaSha avatar Jul 25 '17 17:07 KostyaSha

--dns=IP_ADDRESS... | Sets the IP addresses added as nameserver lines to the container's/etc/resolv.conf file

KostyaSha avatar Jul 25 '17 17:07 KostyaSha

https://docs.docker.com/engine/userguide/networking/default_network/configure-dns/

KostyaSha avatar Jul 25 '17 17:07 KostyaSha

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

KostyaSha avatar Jul 25 '17 17:07 KostyaSha

Thank you, but --dns does not work in this case. I tried it before starting to invent ugly workarounds.

mikhirev avatar Jul 25 '17 18:07 mikhirev

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?

KostyaSha avatar Jul 25 '17 20:07 KostyaSha

Sorry, I'm not a Java coder, but some answers to very similar questions at SO suggest using regexes:

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();

mikhirev avatar Jul 25 '17 22:07 mikhirev

ok, will pick something. PS My apple laptop gpu is crapped again...

KostyaSha avatar Jul 25 '17 23:07 KostyaSha

https://github.com/KostyaSha/yet-another-docker-plugin/pull/178/files#diff-8f38882cbf864d4a172bd377b63443a8R318

KostyaSha avatar Jul 27 '17 01:07 KostyaSha

@mikhirev please try newest version if it wouldn't work i will add parser tests.

KostyaSha avatar Sep 06 '17 01:09 KostyaSha