57

I'am using docker and using the following command:

docker run -d -p 9090:80 -v $(pwd):/usr/share/nginx/html nginx:alpine

to point to my /dist folder where my app-files are compiled by angular.

I first go to /dist folder and then run the command from there. This was working fine and I was able to reach the app via port: 9090, but after docker update, I run in error:

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

I have been searching and checked the following posting docker : invalid reference format, but it seems to be different to my issue. Here is the info based on the command: docker version:

Client:
 Version:      17.09.0-ce
 API version:  1.32
 Go version:   go1.8.3
 Git commit:   afdb6d4
 Built:        Tue Sep 26 22:40:09 2017
 OS/Arch:      darwin/amd64

Server:
 Version:      17.09.0-ce
 API version:  1.32 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   afdb6d4
 Built:        Tue Sep 26 22:45:38 2017
 OS/Arch:      linux/amd64
 Experimental: false

Any idea please?

k.vincent
  • 3,743
  • 8
  • 37
  • 74
  • 2
    What does `echo docker run -d -p 9090:80 -v $(pwd):/usr/share/nginx/html nginx:alpine` output? – BMitch Nov 22 '17 at 13:13
  • 2
    Sry, following is the output: `docker run -d -p 9090:80 -v /Users/myUserName/projectFolder/ang5/main-app/dist/dist:/usr/share/nginx/html` – k.vincent Nov 22 '17 at 13:21
  • 1
    Is there a space anywhere in that argument to `-v`? – BMitch Nov 22 '17 at 13:24
  • 1
    No. At least I can't see any space when I double check. Except the space before and the space after: ` -v ` – k.vincent Nov 22 '17 at 13:28

7 Answers7

71

Docker is seeing something unexpected before the image name, making it think something in your command other than the nginx:alpine is your image name. This may be an invalid - before each of your options, often seen with a copy/paste from the web. It may also be a space in your path. If it's as simple as a space in your path, then quoting it will resolve that:

docker run -d -p 9090:80 -v "$(pwd):/usr/share/nginx/html" nginx:alpine

If the above two do not resolve your issue, first make sure the following works:

docker run nginx:alpine

And then add individual parameters back into your command until you find the one that breaks it. Pay special attention to the order of your args, parameters to run must be between the run and your image name. Args after the image name are passed as a command to run. Args before the run are options to the docker top level command.

BMitch
  • 231,797
  • 42
  • 475
  • 450
  • 2
    Yes, the quoting did the fix. Great. All of you seem to knew that it has to do with the path. In my case it contains dash `-` and a digit `5`. With quoting the issue could be fixed. Sry, I missed it when didn't post the real path I do have for my folder! My Bad. – k.vincent Nov 22 '17 at 13:46
  • 6
    Example of "seeing something unexpected": a space which is actually *not* a space, but a non-breakable space: https://stackoverflow.com/a/2774507/6309. Another one: a '-' which is not a '-': https://stackoverflow.com/a/170148/6309 – VonC Apr 13 '18 at 11:47
6

Your $(pwd) has characters that are not liked (e.g., spaces). Try using quotes around it:

docker run -d -p 9090:80 -v "$(pwd):/usr/share/nginx/html" nginx:alpine

Ognyan Dimitrov
  • 6,026
  • 1
  • 48
  • 70
omkar
  • 145
  • 1
  • 2
  • 6
2

For me this happened because I left the name blank. Use -t somename to set a name when building

m1212e
  • 303
  • 4
  • 8
1

Seems like you have an invalid name somewhere. Did you try to output pwd ?

Try to change the pwd with a static path.

Take a look at the documentation it might help you as well https://docs.docker.com/v1.10/engine/reference/commandline/run/#mount-volume-v-read-only

Mohamed Salem Lamiri
  • 5,767
  • 6
  • 34
  • 47
  • @k.vincent it seems like the folder name 'ang5' might be the problem, try to run it in a different folder or rename the folder if possible. – Mohamed Salem Lamiri Nov 22 '17 at 13:24
  • Could this be the cause: `Project - November`? cause the projectFolder has an empty space in it... exactly like this: `ISSUE - NOVEMBER`? – k.vincent Nov 22 '17 at 13:33
  • 1
    most likely it is a special character and that's why you should try to change your folder name if possible or just run it somewhere where you don't have numbers, spaces or anyspecial character in your path something like this : /Users/myUserName/projectNovember/dist/: ... otherwise you should also try to escape the path name "/Users/myUserName/projectNovember/dist/" – Mohamed Salem Lamiri Nov 22 '17 at 13:35
1

This answer is specific to Google Cloud's Compute Engine (VM Instance).

When specifying the image container to use in the VM settings, including the :latest tag explicitly at the end of the container input was causing the invalid reference format error.

So I had to put this: gcr.io/project/container

Not this: gcr.io/project/container:latest

contactmatt
  • 18,116
  • 40
  • 128
  • 186
  • `:latest` is valid. Are you sure there wasn't some other white space in there, or other characters? – BMitch Mar 29 '22 at 16:06
1

If you are running the docker command from within the Shell script then enabling the verbose mode will help in finding the issue.

set -x

set -v

I also came across this issue and while debugging found that image tag was ending with CR character and because of that I was getting "invalid reference format".

Rakesh Chauhan
  • 413
  • 4
  • 7
0

You could run the following command:

docker run -d -p 9090:80 -v $(pwd):/usr/share/nginx/html nginx:alpine

instead of $(pwd) use ${pwd} if your operating system is Windows.

PavanDevarakonda
  • 625
  • 5
  • 27