<p>I'm trying to use <code>sonarsource/sonar-scanner-cli</code> as a kubernetes container, so I do this in a yaml:</p>
<pre><code>- name: &quot;sonarqube-scan-{{ .Values.git.commitID }}&quot;
  image: &quot;{{ .Values.harbor.host }}/{{ .Values.harbor.cache }}/sonarsource/sonar-scanner-cli&quot;
  env:
    # Sonarqube's URL
    - name: SONAR_HOST_URL
      valueFrom:
        secretKeyRef:
          name: sonarqube
          key: sonar-url
    # Auth token of sonarqube's bot
    - name: SONAR_LOGIN
      valueFrom:
        secretKeyRef:
          name: sonar-bot
          key: sonar-token
  volumeMounts:
    - mountPath: /usr/src
      name: initrepo
</code></pre>
<p>Now, I want to do some pre-setup before the <code>sonarsource/sonar-scanner-cl</code> regular run and parse the docker container's run output for some other works. If this is a shell script, I do like:</p>
<pre><code>$before.sh
$sonar-scanner-cl.sh | after.sh
</code></pre>
<p>I guess I can build a new docker image which is <code>FROM sonarsource/sonar-scanner-cl</code>, and put processes in <code>before.sh</code> and <code>after.sh</code> in its run script, but I don't know how to call the original <code>sonarsource/sonar-scanner-cl</code> run commands. What are the actual commands?</p>
<p>Or, alternatively, does kubernetes have a way to do this?</p>

Romulus Urakagi Ts'ai
<p>Here's how one can modify container commands without building another image.</p>
<ol>
<li>Pull the image</li>
</ol>
<pre class="lang-sh prettyprint-override"><code>docker pull sonarsource/sonar-scanner-cli
</code></pre>
<ol start="2">
<li>Inspect it</li>
</ol>
<pre class="lang-sh prettyprint-override"><code>docker inspect sonarsource/sonar-scanner-cli
</code></pre>
<p>You should get something like this:</p>
<pre class="lang-json prettyprint-override"><code>            &quot;Cmd&quot;: [
                &quot;/bin/sh&quot;,
                &quot;-c&quot;,
                &quot;#(nop) &quot;,
                &quot;CMD [\&quot;sonar-scanner\&quot;]&quot; &lt;- arguments
            ],
            &quot;WorkingDir&quot;: &quot;/usr/src&quot;,
            &quot;Entrypoint&quot;: [ &lt;- executable
                &quot;/usr/bin/entrypoint.sh&quot;
            ],

</code></pre>
<p><code>Entrypoint</code> is <em>what</em> will be executed and <code>CMD [...]</code> (not <code>Cmd</code>) are the arguments for the executable. In a human-friendly format that equals to:</p>
<pre class="lang-sh prettyprint-override"><code>#      entrypoint          args
/usr/bin/entrypoint.sh sonar-scanner
</code></pre>
<p>Now in this case we have a script that is being executed so there are two options.</p>
<h3>Option 1: Modify the entrypoint script and mount it at launch</h3>
<ol>
<li>Run this to save the script on your machine:</li>
</ol>
<pre class="lang-sh prettyprint-override"><code>docker run --rm --entrypoint=&quot;&quot; sonarsource/sonar-scanner-cli /bin/cat /usr/bin/entrypoint.sh &gt; entrypoint.sh
</code></pre>
<ol start="2">
<li>Modify <code>entrypoint.sh</code> as you like, then put its contents into a configMap.</li>
<li>Mount the file from the configMap instead of /usr/bin/entrypoint.sh (don't forget to set mode to <code>0755</code>)</li>
</ol>
<h3>Option 2: Change entrypoint and arguments in resource definition</h3>
<p>Note that this may not work with some images (ones with no shell inside).</p>
<pre class="lang-yaml prettyprint-override"><code>- name: &quot;sonarqube-scan-{{ .Values.git.commitID }}&quot;
  image: &quot;{{ .Values.harbor.host }}/{{ .Values.harbor.cache }}/sonarsource/sonar-scanner-cli&quot;
  command: # this is entrypoint in k8s API
    - /bin/sh
    - -c
  args:  # this goes instead of CMD
    - &quot;before.sh &amp;&amp; /usr/bin/entrypoint.sh sonar-scanner &amp;&amp; after.sh&quot;
                 # | original command and args          | 

</code></pre>
