Running GUI application in Docker container
2 min readMar 23, 2021
Prerequisites
- 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 😁.
First Method(Manual)
- 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.
NOTE
- 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.
--volume="$HOME/.Xauthority:/root/.Xauthority:rw"
Automation Method
- 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.