142
votes

I'm following this tutorial: https://medium.com/towards-data-science/number-plate-detection-with-supervisely-and-tensorflow-part-1-e84c74d4382c

and they use docker. When I tried to run docker (inside the run.sh script):

docker run \
    -p 8888:8888 
    -v `pwd`/../src:/src \
    -v `pwd`/../data:/data -w /src supervisely_anpr \
    --rm \
    -it \
    bash

I got the error:

docker: invalid reference format.

I spent 2 hours and I can't really understand what's wrong. Any idea really appreciated.

12
see if the following helps you stackoverflow.com/a/45281200/1398418Oleg
Try this docker run -p 8888:8888 -v "`pwd`/../src":/src -v "`pwd`/../data":/data -w /src --rm -it supervisely_anpr bashTarun Lalwani
Like @TarunLalwani and @Oleg mentioned you'll need to move the --rm and -it in-between run and the image name. That won't explain the error message, though. Did you check whether the image name characters don't have any special encoding or upper case? Copy&Paste from your snippet works for me, while docker run --rm foo! bash prints the same error like yours.gesellix
considering posting an answer to this so is easier to find for the next guylloiacono
Always double-quote dollar expansions unless you really want to split the string into words. Here, use "$(pwd)" (modern form of "`pwd`"). Your command becomes docker run -p 8888:8888 -v "$(pwd)"/../src:/src -v "$(pwd)"/../data:/data -w /src supervisely_anpr --rm -it bash.Martin Jambon

12 Answers

140
votes

In powershell you should use ${pwd} instead of $(pwd)

52
votes

The first argument after the "run" that is not a flag or parameter to a flag is parsed as an image name. When that parsing fails, it tells you the reference format, aka image name (but could be an image id, pinned image, or other syntax) is invalid. In your command:

 docker run -p 8888:8888 -v `pwd`/../src:/src -v `pwd`/../data:/data -w /src supervisely_anpr --rm -it bash

The image name "supervisely_anpr" is valid, so you need to look earlier in the command. In this case, the error is most likely from pwd outputting a path with a space in it. Everything after the space is no longer a parameter to -v and docker tries to parse it as the image name. The fix is to quote the volume parameters when you cannot guarantee it is free of spaces or other special characters.

When you do that, you'll encounter the next error, "executable not found". Everything after the image name is parsed as the command to run inside the container. In your case, it will try to run the command --rm -it bash which will almost certainly fail since --rm will no exist as a binary inside your image. You need to reorder the parameters to resolve that:

 docker run --rm -it -p 8888:8888 -v "`pwd`/../src:/src" -v "`pwd`/../data:/data" -w /src supervisely_anpr  bash

I've got some more details on these two errors and causes in my slides here: https://sudo-bmitch.github.io/presentations/dc2018/faq-stackoverflow-lightning.html#29

28
votes

I had the same issue when I copy-pasted the command. Instead, when I typed-in the entire command, it worked!

Good Luck...

9
votes

I had a similar problem. Issue I was having was $(pwd) has a space in there which was throwing docker run off.

Change the directory name to not have spaces in there, and it should work if this is the problem

6
votes

I ran into this issue when I didn't have an environment variable set.

docker push ${repo}${image_name}:${tag}

repo and image_name were defined but tag wasn't.

This resulted in docker push repo/image_name:.

Which threw the docker: invalid reference format.

5
votes

I was executing the whole command in one line, as it was mentioned as such

$ docker run --name testproject-agent \
-e TP_API_KEY="REPLACE_WITH_YOUR_KEY" \
-e TP_AGENT_ALIAS="My First Agent" \
testproject/agent:latest

But its supposed to be a multiline command, and I copied the command line by line and pressed enter after every line and bam! it worked.

Sometimes when you copy off of the web, the new-line character gets omitted, hence my suggestion to try manually introducing the new line.

4
votes

For others come here:
If you happen to put your docker command in a file, say run.sh, check your line separator. In Linux, it should be LR, otherwise you would get the same error.

1
votes

This also happens when you use development docker compose like the below, in production. You don't want to be building images in production as that breaks the ideology of containers. We should be deploying images:

  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"

Change that to use the built image:

  web:
    command: /bin/bash run.sh
    image: registry.voxcloud.co.za:9000/dyndns_api_web:0.1
    ports:
      - "8000:8000"
1
votes

Found that using docker-compose config reported what the problem was.

In my case, an override compose file with an entry that was overriding nothing.

1
votes

I was having some problem on Linux. That was because of directory names contained spaces. I fixed it by using "$(pwd)/path/to/go" instead of $(pwd)/path/to/go

0
votes

I was getting the same issue while using $(pwd) through powershell, I replaced it with ${pwd} and it worked for me.

Following are the details for the same:

PS C:\Users\Systems\git\mastery\dockerfile> docker container run -d --name nginx -p 8080:80 -v $(pwd):/usr/share/nginx/html nginx
docker: invalid reference format.
See 'docker run --help'.

PS C:\Users\Systems\git\mastery\dockerfile> docker container run -d --name nginx -p 8080:80 -v ${pwd}:/usr/share/nginx/html nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
Digest: sha256:25975292693bcc062becc20a1608936927f9950a42fb4474088f6292dacd4ec9
Status: Downloaded newer image for nginx:latest
f6ff08ed3b73095e85474bd2f248a7cae6b5bcdb53e12e4824d235df3cd268aa
0
votes

I removed () and worked for me like this docker run -d -v $pwd/envoy.yaml:/etc/envoy/envoy.yaml:ro -p 8080:8080 -p 9901:9901 I am using windows 10