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
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'.
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'.
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 -
- Docker build
1docker build -t jhooq-docker-demo .
- 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 -
- sh/bash : For sh/bash-like shell, multiline escape char is \
- powershell : For powershell, use `
- cmd : For cmd, it is probably ^
This is how your docker command docker build -t jhooq-docker-Demo .
will look like in different shell -
- sh/bash
1docker build \
2-t \
3jhooq-docker-Demo
- powershell
1docker build `
2-t `
3jhooq-docker-Demo
- 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).
- powershell - You must use
${pwd}
inside your docker command
1docker run -p 8888:8888 -v `${pwd}` /../src:/src jhooq-docker-demo
- 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
- Docker forum - Docker: invalid reference format
Posts in this Series
- (docker run -d) Why Does a Docker Container Stop Automatically?
- Attach and detach from Docker's process?
- How I Change Name of My Docker Repository and Rename Images?
- How to set-up Cron Jobs in Docker Containers?
- 4 Ways to copy file from localhost to docker container
- Multiple commands execution in Docker Compose?
- How to push Docker Images to AWS ECR(Elastic Container registry)?
- How to Copy Docker images from one host to another host?
- What is persistent storage in docker and how to manage it
- Docker Installation on MacOS, Linux and Windows
- Docker - ADD, Update, Export Environment variable
- How to fix-Docker docker failed to compute cache key not found
- How to fix docker driver failed programming external connectivity on endpoint webserver?
- How to fix docker error executable file not found in $PATH?
- How to expose port on live containers?
- How to expose multiple ports with Docker?
- How to restart single docker container within multiple docker container?
- How to edit file within Docker container or edit a file after I shell into a Docker container?
- How to fix Error starting docker service Unit not found?
- How to remove old, unused images of Docker?
- How to fix docker error invalid reference format error?
- How to fix requested access to the resource is denied?
- How to fix Docker error cannot delete docker container conflict unable to remove repository reference?
- How to fix docker error no space left on device?
- How to connect localhost from docker container?
- Docker COPY vs Docker ADD?
- 6 Ways to fix - Got permission denied while trying to connect to the Docker daemon socket?
- 6 Ways to fix – Docker COPY failed: stat no source files were specified