Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockerfile is not a valid repository/tag: invalid reference format

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"]
like image 318
Peter Kneale Avatar asked Feb 18 '18 02:02

Peter Kneale


People also ask

How to fix docker invalid reference format?

How to fix - docker: invalid reference format: repository name must be lowercase? The simplest way to fix the issue by change the image to jhooq-docker-demo so that there is no uppercase character in the image name .

How do I tag in Docker?

Docker tags are just an alias for an image ID. The tag's name must be an ASCII character string and may include lowercase and uppercase letters, digits, underscores, periods, and dashes. In addition, the tag names must not begin with a period or a dash, and they can only contain 128 characters.


2 Answers

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.

like image 50
BMitch Avatar answered Oct 12 '22 00:10

BMitch


I got the same issue when using GKE. My solution is:

  • Add new node pool uses Ubuntu image.
  • Then upgrade Docker on these nodes.
  • And only spawn new Jenkins slaves on this node pool (using taint & tolerations).

Result: Now I can use multi-stage build for Jenkins slaves running on GKE.

like image 42
Viet Tran Avatar answered Oct 12 '22 02:10

Viet Tran