<p>I am receiving the "is not a valid repository/tag: invalid reference format" error when building an image on a jenkins agent.</p>

<ul>
<li><p>This error is generally known to occur when docker versions &lt; 17.05 attempt to build a modern multi-stage dockerfile.</p></li>
<li><p>The agent is running on a Kubernetes cluster (server and nodes running 1.9.2-gke.1) and was provisioned by the below Jenkinsfile.</p></li>
</ul>

<p>Is it because I am binding <code>/var/run/docker.sock</code> from the client to the server that this is executing on the 17.03 version of docker?</p>

<p><strong>The JenkinsFile:</strong></p>

<pre><code>#!/usr/bin/groovy

podTemplate(label: 'jenkins-pipeline', containers: [
    containerTemplate(name: 'jnlp', image: 'jenkinsci/jnlp-slave:latest', args: '${computer.jnlpmac} ${computer.name}'),
    containerTemplate(name: 'docker', image: 'docker:latest', command: 'cat', ttyEnabled: true),
    containerTemplate(name: 'helm', image: 'lachlanevenson/k8s-helm:latest', command: 'cat', ttyEnabled: true)
],
volumes:[ hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'), ]) {

    node ('jenkins-pipeline') {

        stage('build') {
            container('docker') {
                dir ('src') {
                    sh "docker version"
                    sh "docker build -t ${tag} ."
                }
            }
        }
    }
}
</code></pre>

<p><strong>Check the version of docker:</strong></p>

<pre><code># docker version
Client:
 Version:   18.02.0-ce
 API version:   1.27 (downgraded from 1.36)
 Go version:    go1.9.3
 Git commit:    fc4de44
 Built: Wed Feb  7 21:12:37 2018
 OS/Arch:   linux/amd64
 Experimental:  false
 Orchestrator:  swarm

Server:
 Engine:
  Version:  17.03.2-ce
  API version:  1.27 (minimum version 1.12)
  Go version:   go1.9.1
  Git commit:   f5ec1e2
  Built:    Thu Dec  7 20:13:20 2017
  OS/Arch:  linux/amd64
  Experimental: false
</code></pre>

<p><strong>The dockerfile in question:</strong></p>

<pre><code>FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 80

FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src
COPY XXXXXX.API.csproj ./
RUN dotnet restore
COPY . .
WORKDIR /src
RUN dotnet build -c Release -o /app

FROM build AS publish
RUN dotnet publish -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "XXXXXX.API.dll"]
</code></pre>

<p>Docker builds are run on the server, and <a href="https://blog.docker.com/2017/07/multi-stage-builds/" rel="noreferrer">multi stage builds were introduced in 17.06</a>. You'll need to run the build on a newer server version to support that syntax.</p>
