3

I have created the simpliest (minimal working example) Dockerfile to run graphical application on my Ubuntu 16.04 LTS host system with 19.10 insider container:

mkdir ~/docker-xclock

cat > ~/docker-xclock/Dockerfile << EOF
FROM ubuntu:19.10
RUN apt-get update
RUN apt-get install -y x11-apps
CMD xclock
EOF

Then created container with

docker build -t ubuntu:xclock ~/docker-xclock

When I try to run this container it shows the error about display:

$ docker run ubuntu:xclock 
Error: Can't open display: 

What is wrong?

2
3

We need to inform container about running X11 server on host with special syntax [1]:

docker run -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --user="$(id --user):$(id --group)" ubuntu:xclock

xclock on docker

where [2]:

-e, --env=[]
Set environment variables
-u, --user=""
Sets the username or UID used and optionally the groupname or GID for the specified command.
-v|--volume[=[[HOST-DIR:]CONTAINER-DIR[:OPTIONS]]]
Create a bind mount. If you specify, -v /HOST-DIR:/CONTAINER-DIR, Docker bind mounts /HOST-DIR in the host to /CONTAINER-DIR in the Docker container. If 'HOST-DIR' is omitted, Docker automatically creates the new volume on the host. The OPTIONS are a comma delimited list and can be:


Reference:

  1. https://forums.docker.com/t/x11-forwarding-with-v-on-docker-run-not-working/17708/4
  2. man docker-run

Complete reproducible solution:

mkdir ~/docker-xclock

cat > ~/docker-xclock/Dockerfile << EOF
FROM ubuntu:20.04
RUN apt-get update
RUN apt-get install -y x11-apps
CMD xclock
EOF

docker build -t ubuntu:xclock ~/docker-xclock

docker run -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --user="$(id --user):$(id --group)" ubuntu:xclock
2
  • Exits with error message docker: Error response from daemon: manifest for ubuntu:xclock not found: manifest unknown: manifest unknown – loxosceles Jan 28 at 17:46
  • It is 2021, so 19.10 is EOL. I updated answer above to use 20.04 LTS. Thanks! – N0rbert Jan 28 at 19:31
0

Create Dockerfile in the folder docker-xclock.

mkdir ~/docker-xclock

cat > ~/docker-xclock/Dockerfile << EOF
FROM ubuntu:19.04
ENV https_proxy="xxx"
ENV http_proxy="xxx"
ENV no_proxy="xxx"
RUN apt-get update
RUN apt-get install -y x11-apps
CMD xclock
EOF

docker build -t ubuntu:xclock ~/docker-xclock

docker run -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --user="$(id --user):$(id --group)" ubuntu:xclock

NB: ubuntu:xclock put at the end of the command. Using X11 for GUI interaction .

0

if you're still getting error like:

No protocol specified
Error: Can't open display: :0

make sure you run

$ xhost local:docker

*-from https://github.com/jessfraz/dockerfiles/issues/6#issuecomment-266230114

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.