How to fix docker error invalid reference format error?



In this blog post we will look on ways to fix the docker error invalid reference format error. If you look at the error carefully then it says invalide reference format which mean the image name which you are trying to use in your Dockerfile or docker command is not acceptable.

Basically a reference in docker is a pointer to image, so whenever you use image name inside your Dockerfile or docker command it get parsed and the image name should follow certain rules as described in below in the table of content -

Table of Content

  1. docker image should not contain uppercase character
  2. Long docker command
  3. ${pwd} AND $(pwd) path


1.docker image should not contain uppercase character

The most important rule for docker image is the image name should always use lowercase character and without any spaces.

Here is an example where I am trying to build an image with one uppercase character ex - jhooq-docker-Demo

1docker build -t jhooq-docker-Demo .

Here is the error while building the docker the image with one uppercase character -

1invalid argument "jhooq-docker-Demo" for "-t, --tag" flag: invalid reference format: repository name must be lowercase
2See 'docker build --help'.

flag: invalid reference format: repository name must be lowercase

Similarly if you are using docker run command with uppercase character in the image name then you will again end with the same error -

1docker run -p 80:80 jhooq-docker-Demo 

The above docker run command will spitout following error -

1docker: invalid reference format: repository name must be lowercase.
2See 'docker run --help'.

docker: invalid reference format: repository name must be lowercase



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 .

Here are the correct commands -

  1. Docker build
1docker build -t jhooq-docker-demo .
  1. Docker run
1docker run -p 80:80 jhooq-docker-demo


2. Long docker command

If you have longer docker command which you need to split into multiple lines then you should carefully use the following rules based on the shell(sh/bash, powershell, cmd) you are using -

  1. sh/bash : For sh/bash-like shell, multiline escape char is \
  2. powershell : For powershell, use `
  3. cmd : For cmd, it is probably ^

This is how your docker command docker build -t jhooq-docker-Demo . will look like in different shell -

  1. sh/bash
1docker build \ 
2-t \ 
3jhooq-docker-Demo 
  1. powershell
1docker build `
2-t `
3jhooq-docker-Demo 
  1. cmd
1docker build ^
2-t ^
3jhooq-docker-Demo 


3. ${pwd} AND $(pwd) path

If by any chance your docker command uses ${pwd} then you need to carefully use the ${pwd} and $(pwd) based on the type of shell(powershell, sh/bash).

  1. powershell - You must use ${pwd} inside your docker command
1docker run -p 8888:8888 -v `${pwd}` /../src:/src jhooq-docker-demo 
  1. sh/bash - You must use $(pwd) inside your docker command
1docker run -p 8888:8888 -v `$(pwd)` /../src:/src jhooq-docker-demo 

I hope the above approaches will help you to fix your issue with docker invalid reference format error.



References
  1. Docker forum - Docker: invalid reference format

Posts in this Series