Home>

I am thinking of porting a locally created Kivy app to Docker.
Describes the development environment.

(Host PC)

  • Ubuntu: 18.04
  • Python: 3.6.9
  • docker: 19.03.6 *nvidia-docker is not installed
  • NVIDIA-SMI: 440.100
  • CUDA: 10.2

(Docker container)

  • Ubuntu: 20.04
  • Python: 3.6.9

I googled it and tried it, but I couldn't resolve the error and stopped.

What I tried

Referenced site

I started the container by executing the following command.

docker run --privileged --net host -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp.X11-unix -it -v /(path of created kivy program)/:/home/ (Image ID)


After starting the container, move to the home directory in the container and execute the kivy program.main.pyRan.
Then the following error appears.

[email protected]:/home# python3.6 main.py
[WARNING] [Config] Older configuration version detected (0 instead of 21)
[WARNING] [Config] Upgrading configuration in progress.
[INFO] [Logger] Record log in /root/.kivy/logs/kivy_20-07-16_0.txt
[INFO] [Kivy] v1.11.1
[INFO] [Kivy] Installed at "/usr/local/lib/python3.6/site-packages/kivy/__init__.py"
[INFO] [Python] v3.6.9 (default, Jul 15 2020, 09:01:41)
[GCC 9.3.0]
[INFO] [Python] Interpreter at "/usr/local/bin/python3.6"
[INFO] [Factory] 184 symbols loaded
[INFO] [ImageLoaderFFPy] Using ffpyplayer 4.3.1
[INFO] [Image] Providers: img_tex, img_dds, img_sdl2, img_ffpyplayer, img_gif (img_pil ignored)[INFO] [Text] Provider: sdl2
[INFO] [Window] Provider: sdl2(['window_egl_rpi'] ignored)
libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
X Error of failed request: GLXBadContext
  Major opcode of failed request: 154 (GLX)
  Minor opcode of failed request: 6 (X_GLXIsDirect)
  Serial number of failed request: 92
  Current serial number in output stream: 91

I investigated this error and found that when I included the NVIDIA Driver
"LibGL.so.1 sometimes refers to the ambiguous libGL provided by both mesa and nvidia."
Is writtensiteThere was, so I confirmed it by executing the following command on the host PC.

[email protected]# ldconfig -p | grep -i gl.so
    libwayland-egl.so.1 (libc6,x86-64) =>/usr/lib/x86_64-linux-gnu/libwayland-egl.so.1
    libcogl.so.20 (libc6,x86-64) =>/usr/lib/x86_64-linux-gnu/libcogl.so.20
    libGL.so.1 (libc6,x86-64) =>/usr/lib/x86_64-linux-gnu/libGL.so.1
    libGL.so.1 (libc6) =>/usr/lib/i386-linux-gnu/libGL.so.1
    libEGL.so.1 (libc6,x86-64) =>/usr/lib/x86_64-linux-gnu/libEGL.so.1


CertainlylibGL.so.1There were two, so I deleted one and checked again.

rm /usr/lib/i386-linux-gnu/libGL.so.1
[email protected]# ldconfig -p | grep -i gl.so
    libwayland-egl.so.1 (libc6,x86-64) =>/usr/lib/x86_64-linux-gnu/libwayland-egl.so.1
    libcogl.so.20 (libc6,x86-64) =>/usr/lib/x86_64-linux-gnu/libcogl.so.20
    libGL.so.1 (libc6,x86-64) =>/usr/lib/x86_64-linux-gnu/libGL.so.1
    libGL.so.1 (libc6) =>/usr/lib/i386-linux-gnu/libGL.so.1
    libEGL.so.1 (libc6,x86-64) =>/usr/lib/x86_64-linux-gnu/libEGL.so.1

It hasn't changed. .. ..

I've looked into the other Kivy run-time errors, but I haven't found a valid solution.
I would appreciate if you could teach me if you know a solution.

Supplement 1 (2020/07/16)

I confirmed that it was written on some sites that "Ready to open xterm!"
In the containerapt install -y xtermAfter installation withxtermWhen you run
I was able to open the xterm terminal.
But Kivy cannot be executed.

Added (2020/07/17)

It seems that docker 19.03 or later has native support for GPU.
Perhaps i am trying to use the GPU?nvidia-container-toolkitInstalled.
The error contents changed when I ran the following command after rebooting.

[email protected]# docker run --gpus 1 --privileged --net host -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp.X11-unix -it -v /(Kivy program storage location )/:/home/ (Image ID)
[email protected]:/home# export NVIDIA_DRIVER_CAPABILITIES=graphics
[email protected]:/home# python3.6 main.py
[WARNING] [Config] Older configuration version detected (0 instead of 21)
[WARNING] [Config] Upgrading configuration in progress.
[INFO] [Logger] Record log in /root/.kivy/logs/kivy_20-07-17_0.txt
[INFO] [Kivy] v1.11.1
[INFO] [Kivy] Installed at "/usr/local/lib/python3.6/site-packages/kivy/__init__.py"
[INFO] [Python] v3.6.9 (default, Jul 16 2020, 08:54:06)
[GCC 9.3.0]
[INFO] [Python] Interpreter at "/usr/local/bin/python3.6"
[INFO] [Factory] 184 symbols loaded
[INFO] [ImageLoaderFFPy] Using ffpyplayer 4.3.1
[INFO] [Image] Providers: img_tex, img_dds, img_sdl2, img_ffpyplayer, img_gif (img_pil ignored)
[INFO] [Text] Provider: sdl2
[INFO] [Window] Provider: sdl2(['window_egl_rpi'] ignored)
No protocol specified
[INFO] [Window] Provider: x11(['window_egl_rpi','window_sdl2'] ignored)
No protocol specified
Couldn't connect to X server


The following error when I check whether Xterm can be executed

[email protected]:/home# xterm
No protocol specified
Warning: This program is an suid-root program or is being run by the root user.
The full text of the error or warning message cannot be safely formatted
in this environment.You may get a more descriptive message by running the
program as a non-root user or by removing the suid bit on the executable.
xterm: Xt error: Can't open display: %s


It couldn't be executed. ..

  • Answer # 1

    As a result of trying various things, I solved myself.
    Moved Kivy with nvidia-container-toolkit

    First on my PCnvidia-container-toolkitWas not included, so I installed it. It seems that docker 19.03 or later supports GPU by default. To use the GPUnvidia-container-toolkitIs necessary. What's happening with NVIDIA Docker now? (19.11 version)

    Then give xhost permission. The execution command isxhost +..

    Execute the following command when launching docker. Specify which GPU to use, share network with host, share display port.

    docker run --gpus all --net host -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp.X11-unix -it -v /(host PC directory path)/:/home/ (Image ID)

    Environment variableNVIDIA_DRIVER_CAPABILITIESMakes the value of graphics. The values ​​that can be set are summarized on this page. To set it in the containerexport NVIDIA_DRIVER_CAPABILITIES=graphicsRun. Even if it is set by ENV of Dockerfile, it is OK.

    In container/home/Go to and run the Kivy program and it will start up safely.

    It seems that it will be clogged again in the future if it is rumored that it does not support NVIDIA Docker on Windows, or it will happen on Docker before 19.03, but it has been solved for the time being.