Running GUI application in Docker container
- Docker installed in OS.
For solving this issue I am showing two methods, the first is manually and the second is Automation, btw I prefer automation 😁.
- Pull one image(eg-centos).
docker pull centos
- Start docker container normally.
docker run --net=host -it --name c1 centos
- Install one GUI application for eg, I am installing firefox.
- After the installation let’s start firefox.
- Oops, 😅 it gave an error, now let understand the error, it needs one env variable for x11 Display, so we need to define $DISPLAY.
- Now launch one more container with env $DISPLAY, and install firefox.
docker run -it --net=host --env="DISPLAY" centos
- Great 😅 it works.
- To remove the warnings, maybe firefox tabs will crash, for solving the issue install some more packages.
yum install PackageKit-gtk3-module libcanberra-gtk2 -y
- Or one more thing u can do at the time of launching container u can mount x11 server volume.
- Create one Dockerfile.
- Build an image from this Dockerfile.
docker build -t IMAGE_NAME(eg-centosgui) .
- Launch Docker container from this image.
docker run --net=host --env="DISPLAY" --name CONTAINER_NAME centosgui
- That’s Great it works 😃, As you can see the warning which comes previously, it resolved.