X11 Error When Run as a Docker Container

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I'm trying to run an application from a Docker container which is supposed to open a GUI widow (a video stream in my case). The Docker container is run on a Raspberry Pi and I SSH into the Pi from my Mac and then I issue the Docker run command. I have one problem here:



When I run the whole thing as follows, it works flawlessly:



I run the command as:



docker run -it --net=host --device=/dev/vcsm --device=/dev/vchiq -e DISPLAY -v /tmp/.X11-unix joesan/motion_detector bash


From the bash, that opens up after issuing the Docker run command, I install xauth



root@cctv:/raspi_motion_detection/project# apt-get install xauth


I then add the Xauth cookie using Xauth add and then I then run my Python program which shows the GUI window with the video stream!



So far so good. But, every time I don't want to be doing these steps all over again. So I wrote a small script to do this as below:



HOST=cctv

DISPLAY_NUMBER=$(echo $DISPLAY | cut -d. -f1 | cut -d: -f2)
echo $DISPLAY_NUMBER

# Extract auth cookie
AUTH_COOKIE=$(xauth list | grep "^$(hostname)/unix:$DISPLAY_NUMBER " | awk 'print $3')

# Add the xauth cookie to xauth
xauth add $HOST/unix:$DISPLAY_NUMBER MIT-MAGIC-COOKIE-1 $AUTH_COOKIE

# Launch the container
docker run -it --net=host --device=/dev/vcsm --device=/dev/vchiq -e DISPLAY -v /tmp/.X11-unix joesan/motion_detector`


But this time it fails with the error:



X11 connection rejected because of wrong authentication.
Unable to init server: Could not connect: Connection refused


I then tried to run the above script as a sudo user and I get the following:



xauth: file /root/.Xauthority does not exist
xauth: (argv):1: bad "add" command line
X11 connection rejected because of wrong authentication.
Unable to init server: Could not connect: Connection refused


Is there anything that I'm missing?










share|improve this question









New contributor




sparkr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • The sequence seems mixed up between the two approaches. When you run the docker -it .. command, it launches the container, creates a bash shell inside the container, and places you there. I guess you execute the apt-get install and xauth commands inside the container. In the shell script, you seem to be running the xauth commands on the host, not inside the container.
    – Haxiel
    yesterday










  • How do I fix this? I mean how can I get the same effect of running xauth commands from inside the container? Should I do apt-get install xauth inside the container by writing it as a RUN command in my Docker file?
    – sparkr
    yesterday










  • Is there any help?
    – sparkr
    yesterday














up vote
0
down vote

favorite












I'm trying to run an application from a Docker container which is supposed to open a GUI widow (a video stream in my case). The Docker container is run on a Raspberry Pi and I SSH into the Pi from my Mac and then I issue the Docker run command. I have one problem here:



When I run the whole thing as follows, it works flawlessly:



I run the command as:



docker run -it --net=host --device=/dev/vcsm --device=/dev/vchiq -e DISPLAY -v /tmp/.X11-unix joesan/motion_detector bash


From the bash, that opens up after issuing the Docker run command, I install xauth



root@cctv:/raspi_motion_detection/project# apt-get install xauth


I then add the Xauth cookie using Xauth add and then I then run my Python program which shows the GUI window with the video stream!



So far so good. But, every time I don't want to be doing these steps all over again. So I wrote a small script to do this as below:



HOST=cctv

DISPLAY_NUMBER=$(echo $DISPLAY | cut -d. -f1 | cut -d: -f2)
echo $DISPLAY_NUMBER

# Extract auth cookie
AUTH_COOKIE=$(xauth list | grep "^$(hostname)/unix:$DISPLAY_NUMBER " | awk 'print $3')

# Add the xauth cookie to xauth
xauth add $HOST/unix:$DISPLAY_NUMBER MIT-MAGIC-COOKIE-1 $AUTH_COOKIE

# Launch the container
docker run -it --net=host --device=/dev/vcsm --device=/dev/vchiq -e DISPLAY -v /tmp/.X11-unix joesan/motion_detector`


But this time it fails with the error:



X11 connection rejected because of wrong authentication.
Unable to init server: Could not connect: Connection refused


I then tried to run the above script as a sudo user and I get the following:



xauth: file /root/.Xauthority does not exist
xauth: (argv):1: bad "add" command line
X11 connection rejected because of wrong authentication.
Unable to init server: Could not connect: Connection refused


Is there anything that I'm missing?










share|improve this question









New contributor




sparkr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • The sequence seems mixed up between the two approaches. When you run the docker -it .. command, it launches the container, creates a bash shell inside the container, and places you there. I guess you execute the apt-get install and xauth commands inside the container. In the shell script, you seem to be running the xauth commands on the host, not inside the container.
    – Haxiel
    yesterday










  • How do I fix this? I mean how can I get the same effect of running xauth commands from inside the container? Should I do apt-get install xauth inside the container by writing it as a RUN command in my Docker file?
    – sparkr
    yesterday










  • Is there any help?
    – sparkr
    yesterday












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm trying to run an application from a Docker container which is supposed to open a GUI widow (a video stream in my case). The Docker container is run on a Raspberry Pi and I SSH into the Pi from my Mac and then I issue the Docker run command. I have one problem here:



When I run the whole thing as follows, it works flawlessly:



I run the command as:



docker run -it --net=host --device=/dev/vcsm --device=/dev/vchiq -e DISPLAY -v /tmp/.X11-unix joesan/motion_detector bash


From the bash, that opens up after issuing the Docker run command, I install xauth



root@cctv:/raspi_motion_detection/project# apt-get install xauth


I then add the Xauth cookie using Xauth add and then I then run my Python program which shows the GUI window with the video stream!



So far so good. But, every time I don't want to be doing these steps all over again. So I wrote a small script to do this as below:



HOST=cctv

DISPLAY_NUMBER=$(echo $DISPLAY | cut -d. -f1 | cut -d: -f2)
echo $DISPLAY_NUMBER

# Extract auth cookie
AUTH_COOKIE=$(xauth list | grep "^$(hostname)/unix:$DISPLAY_NUMBER " | awk 'print $3')

# Add the xauth cookie to xauth
xauth add $HOST/unix:$DISPLAY_NUMBER MIT-MAGIC-COOKIE-1 $AUTH_COOKIE

# Launch the container
docker run -it --net=host --device=/dev/vcsm --device=/dev/vchiq -e DISPLAY -v /tmp/.X11-unix joesan/motion_detector`


But this time it fails with the error:



X11 connection rejected because of wrong authentication.
Unable to init server: Could not connect: Connection refused


I then tried to run the above script as a sudo user and I get the following:



xauth: file /root/.Xauthority does not exist
xauth: (argv):1: bad "add" command line
X11 connection rejected because of wrong authentication.
Unable to init server: Could not connect: Connection refused


Is there anything that I'm missing?










share|improve this question









New contributor




sparkr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I'm trying to run an application from a Docker container which is supposed to open a GUI widow (a video stream in my case). The Docker container is run on a Raspberry Pi and I SSH into the Pi from my Mac and then I issue the Docker run command. I have one problem here:



When I run the whole thing as follows, it works flawlessly:



I run the command as:



docker run -it --net=host --device=/dev/vcsm --device=/dev/vchiq -e DISPLAY -v /tmp/.X11-unix joesan/motion_detector bash


From the bash, that opens up after issuing the Docker run command, I install xauth



root@cctv:/raspi_motion_detection/project# apt-get install xauth


I then add the Xauth cookie using Xauth add and then I then run my Python program which shows the GUI window with the video stream!



So far so good. But, every time I don't want to be doing these steps all over again. So I wrote a small script to do this as below:



HOST=cctv

DISPLAY_NUMBER=$(echo $DISPLAY | cut -d. -f1 | cut -d: -f2)
echo $DISPLAY_NUMBER

# Extract auth cookie
AUTH_COOKIE=$(xauth list | grep "^$(hostname)/unix:$DISPLAY_NUMBER " | awk 'print $3')

# Add the xauth cookie to xauth
xauth add $HOST/unix:$DISPLAY_NUMBER MIT-MAGIC-COOKIE-1 $AUTH_COOKIE

# Launch the container
docker run -it --net=host --device=/dev/vcsm --device=/dev/vchiq -e DISPLAY -v /tmp/.X11-unix joesan/motion_detector`


But this time it fails with the error:



X11 connection rejected because of wrong authentication.
Unable to init server: Could not connect: Connection refused


I then tried to run the above script as a sudo user and I get the following:



xauth: file /root/.Xauthority does not exist
xauth: (argv):1: bad "add" command line
X11 connection rejected because of wrong authentication.
Unable to init server: Could not connect: Connection refused


Is there anything that I'm missing?







x11 docker






share|improve this question









New contributor




sparkr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




sparkr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday









Rui F Ribeiro

38.1k1475123




38.1k1475123






New contributor




sparkr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









sparkr

1063




1063




New contributor




sparkr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





sparkr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






sparkr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • The sequence seems mixed up between the two approaches. When you run the docker -it .. command, it launches the container, creates a bash shell inside the container, and places you there. I guess you execute the apt-get install and xauth commands inside the container. In the shell script, you seem to be running the xauth commands on the host, not inside the container.
    – Haxiel
    yesterday










  • How do I fix this? I mean how can I get the same effect of running xauth commands from inside the container? Should I do apt-get install xauth inside the container by writing it as a RUN command in my Docker file?
    – sparkr
    yesterday










  • Is there any help?
    – sparkr
    yesterday
















  • The sequence seems mixed up between the two approaches. When you run the docker -it .. command, it launches the container, creates a bash shell inside the container, and places you there. I guess you execute the apt-get install and xauth commands inside the container. In the shell script, you seem to be running the xauth commands on the host, not inside the container.
    – Haxiel
    yesterday










  • How do I fix this? I mean how can I get the same effect of running xauth commands from inside the container? Should I do apt-get install xauth inside the container by writing it as a RUN command in my Docker file?
    – sparkr
    yesterday










  • Is there any help?
    – sparkr
    yesterday















The sequence seems mixed up between the two approaches. When you run the docker -it .. command, it launches the container, creates a bash shell inside the container, and places you there. I guess you execute the apt-get install and xauth commands inside the container. In the shell script, you seem to be running the xauth commands on the host, not inside the container.
– Haxiel
yesterday




The sequence seems mixed up between the two approaches. When you run the docker -it .. command, it launches the container, creates a bash shell inside the container, and places you there. I guess you execute the apt-get install and xauth commands inside the container. In the shell script, you seem to be running the xauth commands on the host, not inside the container.
– Haxiel
yesterday












How do I fix this? I mean how can I get the same effect of running xauth commands from inside the container? Should I do apt-get install xauth inside the container by writing it as a RUN command in my Docker file?
– sparkr
yesterday




How do I fix this? I mean how can I get the same effect of running xauth commands from inside the container? Should I do apt-get install xauth inside the container by writing it as a RUN command in my Docker file?
– sparkr
yesterday












Is there any help?
– sparkr
yesterday




Is there any help?
– sparkr
yesterday










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










The apt-get install xauth command should only be required once, and so you can include it in your Dockerfile so that it gets executed when you build your image.



RUN apt-get install xauth


For the xauth add command, you seem to be depending upon the DISPLAY variable, which is passed on to the container on startup. In this case, it would be better to create a shell script which does all of the initialization that you need at startup, and then launches your Python program. For example:



#!/bin/bash

HOST=cctv
DISPLAY_NUMBER=$(echo $DISPLAY | cut -d. -f1 | cut -d: -f2)
AUTH_COOKIE=$(xauth list | grep "^$(hostname)/unix:$DISPLAY_NUMBER " | awk 'print $3')
xauth add $HOST/unix:$DISPLAY_NUMBER MIT-MAGIC-COOKIE-1 $AUTH_COOKIE
python /path/to/program.py


Then, you can copy over this script during the build phase and set it as your command or entrypoint.



COPY init-script.bash /opt/program
CMD ["/bin/bash","/opt/program/init-script.bash"]





share|improve this answer




















  • I almost ended up having a similar set up. I will test it and let you know if that worked!
    – sparkr
    15 hours ago










  • Ok! So now I get this error: xauth: unable to link authority file /root/.Xauthority, use /root/.Xauthority-n
    – sparkr
    14 hours ago










  • @sparkr : Sorry, I'm not too familiar with xauth itself. It has a -v flag for verbose output, so maybe you can use that to get more information?
    – Haxiel
    14 hours ago











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






sparkr is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f481532%2fx11-error-when-run-as-a-docker-container%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










The apt-get install xauth command should only be required once, and so you can include it in your Dockerfile so that it gets executed when you build your image.



RUN apt-get install xauth


For the xauth add command, you seem to be depending upon the DISPLAY variable, which is passed on to the container on startup. In this case, it would be better to create a shell script which does all of the initialization that you need at startup, and then launches your Python program. For example:



#!/bin/bash

HOST=cctv
DISPLAY_NUMBER=$(echo $DISPLAY | cut -d. -f1 | cut -d: -f2)
AUTH_COOKIE=$(xauth list | grep "^$(hostname)/unix:$DISPLAY_NUMBER " | awk 'print $3')
xauth add $HOST/unix:$DISPLAY_NUMBER MIT-MAGIC-COOKIE-1 $AUTH_COOKIE
python /path/to/program.py


Then, you can copy over this script during the build phase and set it as your command or entrypoint.



COPY init-script.bash /opt/program
CMD ["/bin/bash","/opt/program/init-script.bash"]





share|improve this answer




















  • I almost ended up having a similar set up. I will test it and let you know if that worked!
    – sparkr
    15 hours ago










  • Ok! So now I get this error: xauth: unable to link authority file /root/.Xauthority, use /root/.Xauthority-n
    – sparkr
    14 hours ago










  • @sparkr : Sorry, I'm not too familiar with xauth itself. It has a -v flag for verbose output, so maybe you can use that to get more information?
    – Haxiel
    14 hours ago















up vote
2
down vote



accepted










The apt-get install xauth command should only be required once, and so you can include it in your Dockerfile so that it gets executed when you build your image.



RUN apt-get install xauth


For the xauth add command, you seem to be depending upon the DISPLAY variable, which is passed on to the container on startup. In this case, it would be better to create a shell script which does all of the initialization that you need at startup, and then launches your Python program. For example:



#!/bin/bash

HOST=cctv
DISPLAY_NUMBER=$(echo $DISPLAY | cut -d. -f1 | cut -d: -f2)
AUTH_COOKIE=$(xauth list | grep "^$(hostname)/unix:$DISPLAY_NUMBER " | awk 'print $3')
xauth add $HOST/unix:$DISPLAY_NUMBER MIT-MAGIC-COOKIE-1 $AUTH_COOKIE
python /path/to/program.py


Then, you can copy over this script during the build phase and set it as your command or entrypoint.



COPY init-script.bash /opt/program
CMD ["/bin/bash","/opt/program/init-script.bash"]





share|improve this answer




















  • I almost ended up having a similar set up. I will test it and let you know if that worked!
    – sparkr
    15 hours ago










  • Ok! So now I get this error: xauth: unable to link authority file /root/.Xauthority, use /root/.Xauthority-n
    – sparkr
    14 hours ago










  • @sparkr : Sorry, I'm not too familiar with xauth itself. It has a -v flag for verbose output, so maybe you can use that to get more information?
    – Haxiel
    14 hours ago













up vote
2
down vote



accepted







up vote
2
down vote



accepted






The apt-get install xauth command should only be required once, and so you can include it in your Dockerfile so that it gets executed when you build your image.



RUN apt-get install xauth


For the xauth add command, you seem to be depending upon the DISPLAY variable, which is passed on to the container on startup. In this case, it would be better to create a shell script which does all of the initialization that you need at startup, and then launches your Python program. For example:



#!/bin/bash

HOST=cctv
DISPLAY_NUMBER=$(echo $DISPLAY | cut -d. -f1 | cut -d: -f2)
AUTH_COOKIE=$(xauth list | grep "^$(hostname)/unix:$DISPLAY_NUMBER " | awk 'print $3')
xauth add $HOST/unix:$DISPLAY_NUMBER MIT-MAGIC-COOKIE-1 $AUTH_COOKIE
python /path/to/program.py


Then, you can copy over this script during the build phase and set it as your command or entrypoint.



COPY init-script.bash /opt/program
CMD ["/bin/bash","/opt/program/init-script.bash"]





share|improve this answer












The apt-get install xauth command should only be required once, and so you can include it in your Dockerfile so that it gets executed when you build your image.



RUN apt-get install xauth


For the xauth add command, you seem to be depending upon the DISPLAY variable, which is passed on to the container on startup. In this case, it would be better to create a shell script which does all of the initialization that you need at startup, and then launches your Python program. For example:



#!/bin/bash

HOST=cctv
DISPLAY_NUMBER=$(echo $DISPLAY | cut -d. -f1 | cut -d: -f2)
AUTH_COOKIE=$(xauth list | grep "^$(hostname)/unix:$DISPLAY_NUMBER " | awk 'print $3')
xauth add $HOST/unix:$DISPLAY_NUMBER MIT-MAGIC-COOKIE-1 $AUTH_COOKIE
python /path/to/program.py


Then, you can copy over this script during the build phase and set it as your command or entrypoint.



COPY init-script.bash /opt/program
CMD ["/bin/bash","/opt/program/init-script.bash"]






share|improve this answer












share|improve this answer



share|improve this answer










answered 15 hours ago









Haxiel

26118




26118











  • I almost ended up having a similar set up. I will test it and let you know if that worked!
    – sparkr
    15 hours ago










  • Ok! So now I get this error: xauth: unable to link authority file /root/.Xauthority, use /root/.Xauthority-n
    – sparkr
    14 hours ago










  • @sparkr : Sorry, I'm not too familiar with xauth itself. It has a -v flag for verbose output, so maybe you can use that to get more information?
    – Haxiel
    14 hours ago

















  • I almost ended up having a similar set up. I will test it and let you know if that worked!
    – sparkr
    15 hours ago










  • Ok! So now I get this error: xauth: unable to link authority file /root/.Xauthority, use /root/.Xauthority-n
    – sparkr
    14 hours ago










  • @sparkr : Sorry, I'm not too familiar with xauth itself. It has a -v flag for verbose output, so maybe you can use that to get more information?
    – Haxiel
    14 hours ago
















I almost ended up having a similar set up. I will test it and let you know if that worked!
– sparkr
15 hours ago




I almost ended up having a similar set up. I will test it and let you know if that worked!
– sparkr
15 hours ago












Ok! So now I get this error: xauth: unable to link authority file /root/.Xauthority, use /root/.Xauthority-n
– sparkr
14 hours ago




Ok! So now I get this error: xauth: unable to link authority file /root/.Xauthority, use /root/.Xauthority-n
– sparkr
14 hours ago












@sparkr : Sorry, I'm not too familiar with xauth itself. It has a -v flag for verbose output, so maybe you can use that to get more information?
– Haxiel
14 hours ago





@sparkr : Sorry, I'm not too familiar with xauth itself. It has a -v flag for verbose output, so maybe you can use that to get more information?
– Haxiel
14 hours ago











sparkr is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















sparkr is a new contributor. Be nice, and check out our Code of Conduct.












sparkr is a new contributor. Be nice, and check out our Code of Conduct.











sparkr is a new contributor. Be nice, and check out our Code of Conduct.













 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f481532%2fx11-error-when-run-as-a-docker-container%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay