Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run.cmd - support explicit exec form #253

Open
mgurov opened this issue Aug 9, 2015 · 3 comments
Open

run.cmd - support explicit exec form #253

mgurov opened this issue Aug 9, 2015 · 3 comments

Comments

@mgurov
Copy link
Contributor

mgurov commented Aug 9, 2015

At the moment it is not possible to run a more complicated command on a container start, e.g. docker run -it --rm busybox /bin/sh -c "while true; do echo Hello world; sleep 1; done" as the cmd is split by spaces at ContainerCreateConfig.command, and the following configuration:

              <image>
                  <name>busybox</name>
                  <run>
                      <cmd>/bin/sh -c "while true; do echo Hello world; sleep 1; done"</cmd>
                      <wait>
                          <log>Hello world</log>
                      </wait>
                  </run>
              </image>

produces container startup error true;: line 1: syntax error: unterminated quoted string.

It would be nice to have an ability to specify the exec form of the command explicitly, e.g.

              <image>
                  <name>busybox</name>
                  <run>
                      <cmd>
                          <params>
                              <param>/bin/sh</param>
                              <param>-c</param>
                              <param>while true; do echo Hello world; sleep 1; done</param>
                          </params>
                      </cmd>
                      <wait>
                          <log>Hello world</log>
                      </wait>
                  </run>
              </image>

in line with recent changes to ENTRYPOINT/CMD

@rhuss
Copy link
Collaborator

rhuss commented Aug 10, 2015

You are right, the command specified for <run> should support the same capabilities like in <build> i.e. specifying the shell and exec forms explicitely.

We will include this in one of the next section, if you like to speed this up you could help us with a PR: Starting point is the RunConfiguration where the command should be switched over to Arguments, similar as in BuildImageConfiguration for entryPoint and cmd. It is used here.

mgurov added a commit to mgurov/docker-maven-plugin that referenced this issue Aug 13, 2015
mgurov added a commit to mgurov/docker-maven-plugin that referenced this issue Aug 15, 2015
mgurov added a commit to mgurov/docker-maven-plugin that referenced this issue Aug 15, 2015
…md or entry

point. Falling back onto the simple string splitting
mgurov added a commit to mgurov/docker-maven-plugin that referenced this issue Aug 15, 2015
mgurov added a commit to mgurov/docker-maven-plugin that referenced this issue Aug 15, 2015
@mgurov
Copy link
Contributor Author

mgurov commented Aug 15, 2015

I have created a branch with a draft implementation. Specifying arguments explicitly works like a charm:

                <env>
                  <BLAH>FOOE</BLAH>
                </env>
                <cmd>
                  <exec>
                    <arg>sh</arg>
                    <arg>-c</arg>
                    <arg>echo $BLAH</arg>
                  </exec>
                </cmd>

but switching the <shell> from array to simple string in API json didn't work as I expected. I kept getting System error: exec:...stat...no such file or directory. Fell back on splitting by spaces. The following configuration will produce cmd json ["the", "shell", "way"]

            <image>
              <name>debian:jessie</name>
              <run>
                <entrypoint>
                  <shell>/bin/echo</shell>
                </entrypoint>
                <cmd><shell>the shell way</shell></cmd>
                <log>
                  <prefix>keep splitting by the spaces</prefix>
                </log>
              </run>
            </image>

I suggest decreasing the configuration clutter by allowing the "Inlined collection" notation for the explicit arguments:

              <run>
                <entrypoint>
                  <arg>echo</arg>
                </entrypoint>
                <cmd>
                  <arg>inlined args</arg>
                  <arg>mean less clutter</arg>
                </cmd>
              </run>

and default property for the Arguments bean to be the shell form:

              <run>
                <entrypoint>echo</entrypoint>
                <cmd>default string for simple commands</cmd>
              </run>

I plan to ponder bit more on why doesn't plain string cmd/entrypoint work against the docker API, will then polish the branch (validation/tests) and create a pull request in a week time at worst.

mgurov added a commit to mgurov/docker-maven-plugin that referenced this issue Aug 23, 2015
@mgurov
Copy link
Contributor Author

mgurov commented Aug 23, 2015

Pull request sent: #269

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants