Reputation: 1936
I am receiving the "is not a valid repository/tag: invalid reference format" error when building an image on a jenkins agent.
This error is generally known to occur when docker versions < 17.05 attempt to build a modern multi-stage dockerfile.
The agent is running on a Kubernetes cluster (server and nodes running 1.9.2-gke.1) and was provisioned by the below Jenkinsfile.
Is it because I am binding /var/run/docker.sock
from the client to the server that this is executing on the 17.03 version of docker?
The JenkinsFile:
#!/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} ."
}
}
}
}
}
Check the version of docker:
# 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
The dockerfile in question:
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"]
Upvotes: 14
Views: 61081
Reputation: 1223
I got the same issue when using GKE. My solution is:
Result: Now I can use multi-stage build for Jenkins slaves running on GKE.
Upvotes: 1
Reputation: 263499
Docker builds are run on the server, and multi stage builds were introduced in 17.06. You'll need to run the build on a newer server version to support that syntax.
Upvotes: 28