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

Stop <command> from converting CMD to "exec form" (JSON array) #149

Closed
alan-czajkowski opened this issue Apr 28, 2015 · 1 comment
Closed
Labels
Milestone

Comments

@alan-czajkowski
Copy link
Contributor

The following does not work:

<configuration>
  <images>
    <image>
      ...
      <build>
        ...
        <env>
          <ENV_VAR>some_value</ENV_VAR>
        </env>
        ...
        <command>echo $ENV_VAR</command>
      </build>
    </image>
  </images>
</configuration>

because <command> is converted to a JSON array (exec form), and according the documentation http://docs.docker.com/reference/builder/#cmd

Unlike the shell form, the exec form does not invoke a command shell. This means that normal shell processing does not happen. For example, CMD [ "echo", "$HOME" ] will not do variable substitution on $HOME.

the documentation mentions this work-around:

If you want shell processing then either use the shell form or execute a shell directly, for example: CMD [ "sh", "-c", "echo", "$HOME" ].

but this is not correct, the documentation is wrong, in order for environment variable interpolation to work in exec form, in the CMD, it must be structured like this: CMD [ "sh", "-c", "echo $HOME" ]

but this cannot be achieved through the plugin because <command>sh -c echo $ENV_VAR</command> results in CMD [ "sh", "-c", "echo", "$ENV_VAR" ] which is broken whereas we want CMD [ "sh", "-c", "echo $ENV_VAR" ] which is the desired result

The conversion of <command> to a JSON array (exec form) should be disabled.

@alan-czajkowski alan-czajkowski changed the title Stop <command> from converting CMD to "exec form" Stop <command> from converting CMD to "exec form" (JSON array) Apr 28, 2015
@rhuss rhuss added this to the 0.12.0 milestone May 18, 2015
@rhuss
Copy link
Collaborator

rhuss commented Jun 14, 2015

With #130 being implemented you should be able to use the following in 0.12.0:

<configuration>
  <images>
    <image>
      ...
      <build>
        ...
        <env>
          <ENV_VAR>some_value</ENV_VAR>
        </env>
        ...
        <cmd>
           <shell>echo $ENV_VAR</shell>
        </cmd>
      </build>
    </image>
  </images>
</configuration>

0.12.0 will be out next week.

@rhuss rhuss added the fixed label Jun 14, 2015
@rhuss rhuss closed this as completed Jun 14, 2015
leusonmario pushed a commit to leusonmario/docker-maven-plugin that referenced this issue Aug 18, 2018
don't set empty CMD when not configured
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants