Understanding docker container run invalid reference format

Asked 2 years ago, Updated 2 years ago, 364 views

I built a Dokerfile, created an image, and ran a docker run.
The following error cannot be resolved:

 docker: invalid reference format.
See'docker run --help'.

When I looked into it, I looked at the article that caused the copy source and destination path to be written after -v
I tried the following pattern, but all of the above error messages appear.
If you know how to solve this problem, please let me know.

  • Win10 Pro
  • Powershell
  • Docker version 20.10.17, build 100c701

C:/PC-Work/dockerevenv

docker container run-it -- name sample-python-v${PWD}/ex01:/tmp/mydir/sample/python:latest
docker container run-it --name sample-python-v C:\PC-Work\dockereenv\ex01:/tmp/mydir/sample/python:latest
docker container run-it -- name sample-python-v "${PWD}/ex01/:/tmp/mydir"/sample/python:latest
docker container run-it -- name sample-python-v "C:\PC-Work\dockereenv\ex01:/tmp/mydir"/sample/python:latest

windows docker powershell

2022-10-23 16:01

1 Answers

Docker for Windows × volume option × path specification, depending on what is verified in , the string given to -v is

  • -v "C:\test":/test
  • -v "C:/test":/test
  • -vC:/test:/test

All of them will be successful.(I haven't tried it yet, so I don't know if this result is correct.)

However, this is the result of the verification at the command prompt (cmd.exe), and PowerShell shows a different behavior.for Shell generally interprets and makes changes to the arguments.You can see them by typing cmd/cecho followed by to see how they are interpreted

.

command prompt (cmd.exe)

C>cmd/cecho-v "C:\test":/test
-v "C:\test": /test
C>cmd/cecho-v "C:/test":/test
-v "C:/test": /test
C>cmd/cecho-v C:/test:/test
- vC: /test: /test

→In the range we tried here, the input string will be passed directly to the program.

PowerShell

PS>cmd/cecho-v "C:\test":/test
- vC:\test:/test
PS>cmd/cecho-v "C:/test":/test
- vC: /test: /test
PS>cmd/cecho-vC:/test:/test
- vC: /test: /test

" will be deleted and a blank space will be inserted.

To be interpreted and not rewritten by PowerShell, a PowerShell specification escape is required and the input is as follows:

PS>cmd/cecho-v`"C:\test`":/test
-v "C:\test": /test

→ Escape " with backquote.

PS>cmd/cecho-v`"C:/test":/test`
-v "C:/test": /test

→ Tie the string containing " with a single quote '.

Based on the above, would the following be an example of typing on a PowerShell?

docker container run-it --name sample-python-v`"C:\PC-Work\dockereenv\ex01`":/tmp/mydir/sample/python:latest

→Escape with a back quote while tying it with ".The path delimiter can be /\.

docker container run-it -- name sample-python-v' "C:\PC-Work\dockereenv\ex01": /tmp/mydir'/sample/python:latest

→ Escape the string with ' while tying it with ".The path delimiter can be /\.

docker container run-it -- name sample-python-v C:/PC-Work/dockereenv/ex01:/tmp/mydir/sample/python:latest

→ Use / as the path delimiter and do not quote.


2022-10-23 16:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.