1

I am new to Docker and am trying to successfully run the image below to run a Perl script that opens a simple Perl Tk window.

The Image:

FROM debian:bullseye
RUN  apt-get update && \
     apt-get upgrade -y && \
     apt-get install -y cpanminus perl-tk x11-xserver-utils
COPY Tk_hello_world.pl /opt/
CMD  perl /opt/Tk_hello_world.pl

The Perl script Tk_hello_world.pl

use strict;
use Tk;
my $mw = MainWindow->new;
$mw->title("Hello World"); 
$mw->Button(-text => "Done", -command => sub { exit })->pack;
MainLoop;

The image builds successfully but when I try to run the container I get:

couldn't connect to display ":0" at /usr/lib/x86_64-linux-gnu/perl5/5.32/Tk/MainWindow.pm line 53.
MainWindow->new() at /opt/Tk_hello_world.pl line 3.
gatorreina
  • 864
  • 5
  • 14
  • See also [Run simple X11 app in docker container on Ubuntu 20.04](https://askubuntu.com/questions/1249043/run-simple-x11-app-in-docker-container-on-ubuntu-20-04/1250850) – Håkon Hægland Nov 22 '22 at 19:20
  • 1
    Assuming you're on a native-Linux host, you need to do a substantial number of steps to connect the container to the host display. I'd recommend running this outside a container if possible. – David Maze Nov 23 '22 at 11:21

0 Answers0