Home > Software engineering >  Why 'invalid reference format' when trying to run GUI in docker container?
Why 'invalid reference format' when trying to run GUI in docker container?

Time:11-05

I am new to docker and am experimenting with trying to get firefox GUI up and running. The Dockerfile I have is:

FROM ubuntu:21.10 
RUN apt-get update 
RUN apt-get install -y firefox
RUN groupadd -g GID <USERNAME>
RUN useradd -d /home/<USERNAME> -s /bin/bash  \
-m <USERNAME> -u UID -g GID 
USER <USERNAME>
ENV HOME /home/<USERNAME>
CMD /usr/bin/firefox

...where UID is userID and GID is groupID

I then build with:

   $> docker build -t gui .

The image build completes successfully. Then I do:

   $> docker run -v /tmp/.X11-unix:/tmp/.X11-unix \
    -h $HOSTNAME -v $HOME/.Xauthority:/home/$USER/.Xauthority \
    -e DISPLAY=$DISPLAY gui

At this point I get the error: "docker: invalid reference format: repository name must be lowercase."

It's almost as if docker is trying to interpret the X server directory binding and display variable setting as a repository name.

What I am doing wrong? Thanks in advance...

CodePudding user response:

In fact the error you get tells you that docker cannot understand the reference i.e. the name of the image you are trying to run. As well explained by David Maze. He has proposed to debug it thanks to an echo command.

If you follow his advice, for example in your command if $HOSTNAME is not defined you will see the command with variable expanded and be able to see that it will lead to the observed error if launched. To fix it you can quote your variable (always a good advice to prevent errors) and check that each variable is defined. In your case a missing $HOSTNAME is my best guess.

docker run -v /tmp/.X11-unix:/tmp/.X11-unix -h -v /Users/xxx/.Xauthority:/home/xxx/.Xauthority -e DISPLAY=/mydisplay gui
# docker: invalid reference format: repository name must be lowercase.

CodePudding user response:

You're not quoting your environment variable expansions, so if $HOSTNAME is empty or $HOME contains a space you can get errors like this. Try putting the word echo in front of the command and seeing how the shell expands it. – David Maze 45 mins ago

  • Related