我的一个项目遇到了这个 Docker 错误:
invalid reference format: repository name must be lowercase
此通用消息的各种原因是什么?
经过一番努力,我已经想通了,所以我将回答我自己的问题,以便在此处记录它,因为在进行网络搜索时解决方案不会立即出现,而且因为此错误消息没有描述Docker 遇到的直接问题。
我的一个项目遇到了这个 Docker 错误:
invalid reference format: repository name must be lowercase
此通用消息的各种原因是什么?
经过一番努力,我已经想通了,所以我将回答我自己的问题,以便在此处记录它,因为在进行网络搜索时解决方案不会立即出现,而且因为此错误消息没有描述Docker 遇到的直接问题。
A "reference" in docker is a pointer to an image. It may be an image name, an image ID, include a registry server in the name, use a sha256 tag to pin the image, and anything else that can be used to point to the image you want to run.
The invalid reference format
error message means docker cannot convert the string you've provided to an image. This may be an invalid name, or it may be from a parsing error earlier in the docker run
command line if that's how you run the image.
If the name itself is invalid, the repository name must be lowercase
means you use upper case characters in your registry or repository name, e.g. YourImageName:latest
should be yourimagename:latest
.
With the docker run
command line, this is often the result in not quoting parameters with spaces, missing the value for an argument, and mistaking the order of the command line. The command line is ordered as:
docker ${args_to_docker} run ${args_to_run} image_ref ${cmd_to_exec}
The most common error in passing args to the run is a volume mapping expanding a path name that includes a space in it, and not quoting the path or escaping the space. E.g.
docker run -v $(pwd):/data image_ref
Where if you're in the directory /home/user/Some Project Dir
, that would define an anonymous volume /home/user/Some
in your container, and try to run Project:latest
with the command Dir:/data image_ref
. And the fix is to quote the argument:
docker run -v "$(pwd):/data" image_ref
Other common places to miss quoting include environment variables:
docker run -e SOME_VAR=Value With Spaces image_ref
which docker would interpret as trying to run the image With:latest
and the command Spaces image_ref
. Again, the fix is to quote the environment parameter:
docker run -e "SOME_VAR=Value With Spaces" image_ref
With a compose file, if you expand a variable in the image name, that variable may not be expanding correctly. So if you have:
version: 2
services:
app:
image: ${your_image_name}
Then double check that your_image_name
is defined to an all lower case string.
在我的情况下是 mysql docker 参数之前的 -e
docker run --name mysql-standalone -e MYSQL_ROOT_PASSWORD=hello -e MYSQL_DATABASE=hello -e MYSQL_USER=hello -e MYSQL_PASSWORD=hello -d mysql:5.6
还要检查是否缺少空格
就我而言,问题在于参数安排。最初我在环境参数之后有 --name
参数,然后是音量和 attach_dbs
参数,并在命令末尾有图像,如下所示。
docker run -p 1433:1433 -e sa_password=myComplexPwd -e ACCEPT_EULA=Y --name sql1 -v c:/temp/:c:/temp/ attach_dbs="[{'dbName':'TestDb','dbFiles':['c:tempTestDb.mdf','c:tempTestDb_log.ldf']}]" -d microsoft/mssql-server-windows-express
像下面这样重新排列参数后一切正常(基本上把 --name
参数后跟图像名称)。
docker run -d -p 1433:1433 -e sa_password=myComplexPwd -e ACCEPT_EULA=Y --name sql1 microsoft/mssql-server-windows-express -v C:/temp/:C:/temp/ attach_dbs="[{'dbName':'TestDb','dbFiles':['C:tempTestDb.mdf','C:tempTestDb_log.ldf']}]"
在 MacOS 上,当您使用 iCloud 驱动器时,您的 $PWD 将包含一个目录“Mobile Documents”。它似乎不喜欢这个空间!
作为一种解决方法,我将我的项目复制到本地驱动器,我的项目文件夹的路径中没有空间。
我没有看到一种方法可以绕过 changnig 到 iCloud 的默认路径,即 ~/Library/Mobile Documents/com~apple~CloudDocs
“移动文档”中路径中的空间似乎是 docker run 不喜欢的。
有时你会错过 -e 标志,而特定的多个环境变量内联
例如不好: docker run --name somecontainername -e ENV_VAR1=somevalue1 ENV_VAR2=somevalue2 -d -v "mypath:containerpath" <imagename e.g. postgres>
好: docker run --name somecontainername -e ENV_VAR1=somevalue1 -e ENV_VAR2=somevalue2 -d -v "mypath:containerpath" <imagename e.g. postgres>
A reference
in Docker is what points to an image. This could be in a remote registry or the local registry. Let me describe the error message first and then show the solutions for this.
invalid reference format
This means that the reference we have used is not a valid format. This means, the reference (pointer) we have used to identify an image is invalid. Generally, this is followed by a description as follows. This will make the error much clearer.
invalid reference format: repository name must be lowercase
This means the reference we are using should not have uppercase letters. Try running docker run Ubuntu
(wrong) vs docker run ubuntu
(correct). Docker does not allow any uppercase characters as an image reference. Simple troubleshooting steps.
1) Dockerfile contains a capital letters as images.
FROM Ubuntu (wrong)
FROM ubuntu (correct)
2) Image name defined in the docker-compose.yml had uppercase letters
3) If you are using Jenkins or GoCD for deploying your docker container, please check the run command, whether the image name includes a capital letter.
Please read this document written specifically for this error.
在 docker-compose.yml 中用 image: ${DOCKER_REGISTRY}notificationsapi
或 image:notificationsapi
替换 image: ${docker_registry}notificationsapi
确实解决了这个问题
有错误的文件
version: '3.4'
services:
notifications.api:
image: ${DOCKER_REGISTRY}notificationsapi
build:
context: .
dockerfile: ../Notifications.Api/Dockerfile
没有错误的文件
version: '3.4'
services:
notifications.api:
image: ${docker_registry}notificationsapi
build:
context: .
dockerfile: ../Notifications.Api/Dockerfile
所以我认为错误是由于它有非小写字母
让我强调一下 Docker 甚至不允许混合字符。
好:
docker build -t myfirstechoimage:0.1 .
不好:
docker build -t myFirstEchoImage:0.1 .