<p>I have a situation I don't quite understand. It seems like my code is executed in the wrong image - even though the log states that it has loaded my image.</p>
<h2>Expected output vs actual</h2>
<p>When I run <code>docker run -it jstevnsvig/jenkins-build-slave-php:v8.2 /bin/sh -c &quot;dpkg-query -l | cat&quot;</code> I get the expected output.<br />
When I run a Jenkins freestyle job with the appropriate tag, with a single script step executing <code>dpkg-query -l | cat</code> I get what I assume is the output from running in the jnlp image (<code>jenkins/inbound-agent:3077.vd69cf116da_6f-3-jdk11</code>)
How do I get it to run on the correct image?</p>
<p><a href="https://i.stack.imgur.com/O42RS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O42RS.png" alt="docker vs k8s" /></a></p>
<h2>Jenkins Kubernetes cloud Pod template Configuration</h2>
<p><a href="https://i.stack.imgur.com/e6T2n.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e6T2n.png" alt="Jenkins configuration" /></a></p>
<h2>Jenkins job console</h2>
<pre class="lang-yaml prettyprint-override"><code>Started by user JoSSte
Running as SYSTEM
Agent php8-2dfd8 is provisioned from template php8
---
apiVersion: &quot;v1&quot;
kind: &quot;Pod&quot;
metadata:
  labels:
    jenkins: &quot;slave&quot;
    jenkins/label-digest: &quot;cb0616020c016c081bd72366740b4151da57f6a3&quot;
    jenkins/label: &quot;php8&quot;
  name: &quot;php8-2dfd8&quot;
  namespace: &quot;devops-tools&quot;
spec:
  containers:
  - args:
    - &quot;9999999&quot;
    command:
    - &quot;sleep&quot;
    image: &quot;jstevnsvig/jenkins-build-slave-php:v8.2&quot;
    imagePullPolicy: &quot;IfNotPresent&quot;
    name: &quot;php8t&quot;
    resources: {}
    tty: false
    volumeMounts:
    - mountPath: &quot;/home/jenkins/agent&quot;
      name: &quot;workspace-volume&quot;
      readOnly: false
    workingDir: &quot;/home/jenkins/agent&quot;
  - env:
    - name: &quot;JENKINS_PROTOCOLS&quot;
      value: &quot;JNLP4-connect&quot;
    - name: &quot;JENKINS_SECRET&quot;
      value: &quot;********&quot;
    - name: &quot;JENKINS_AGENT_NAME&quot;
      value: &quot;php8-2dfd8&quot;
    - name: &quot;JENKINS_DIRECT_CONNECTION&quot;
      value: &quot;jenkins-service:50000&quot;
    - name: &quot;JENKINS_INSTANCE_IDENTITY&quot;
      value: &quot;...&quot;
    - name: &quot;JENKINS_NAME&quot;
      value: &quot;php8-2dfd8&quot;
    - name: &quot;JENKINS_AGENT_WORKDIR&quot;
      value: &quot;/home/jenkins/agent&quot;
    image: &quot;jenkins/inbound-agent:3077.vd69cf116da_6f-3-jdk11&quot;
    name: &quot;jnlp&quot;
    resources:
      requests:
        memory: &quot;256Mi&quot;
        cpu: &quot;100m&quot;
    volumeMounts:
    - mountPath: &quot;/home/jenkins/agent&quot;
      name: &quot;workspace-volume&quot;
      readOnly: false
  hostNetwork: false
  nodeSelector:
    kubernetes.io/os: &quot;linux&quot;
  restartPolicy: &quot;Never&quot;
  volumes:
  - emptyDir:
      medium: &quot;&quot;
    name: &quot;workspace-volume&quot;
</code></pre>
<p>I have tried changing the label of the container template to <code>jnlp</code> but then it doesn't connect properly (my image is built on the jenkins/agent image)</p>

JoSSte
<p>As documented <a href="https://plugins.jenkins.io/kubernetes/#plugin-content-using-the-pipeline-step" rel="nofollow noreferrer">here</a>, by default, commands in Jenkins agents will run in the <code>jnlp</code> container. If you want to have them run in another container, that you have defined in the <code>podTemplate</code>, you use the <code>container {..}</code> block (section <a href="https://plugins.jenkins.io/kubernetes/#plugin-content-multiple-containers-support" rel="nofollow noreferrer">here</a>)</p>
<pre><code>podTemplate(containers: [
    containerTemplate(name: 'maven', image: 'maven:3.8.1-jdk-8', command: 'sleep', args: '99d'),
    containerTemplate(name: 'golang', image: 'golang:1.16.5', command: 'sleep', args: '99d')
  ]) {

    node(POD_LABEL) {
        stage('Get a Maven project') {
            git 'https://github.com/jenkinsci/kubernetes-plugin.git'
            container('maven') {
                stage('Build a Maven project') {
                    sh 'mvn -B -ntp clean install'
                }
            }
        }
...
</code></pre>
