Hi there! Today we are going to see how we can launch GUI based application inside the docker container.
What is Docker?
Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as one package. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that the machine might have that could differ from the machine used for writing and testing the code.
Let's Start
To launch GUI based apps in docker container we need to follow series of few simple steps :
- We need to mount the x11 UNIX domain socket of the base OS to the container
- We need to pass the display using the environment variable
- Attach the sound card to the container
We can do these using options that can be passed to the docker run
command :
To mount the X11 socket
- -v /tmp/.X11-unix:/tmp/.X11-unix
To pass the display
- -e DISPLAY=unix$DISPLAY
To the sound card
- --device /dev/snd
Now we can combine all these and do it with a single command and launch the container. And that container now will have the capability to run the GUI apps.
To show you I have made a docker image with firefox install in it and now you can see how it works below:
As you can see the firefox has been launched from the container. You can also verify this by seeing the firefox app which says Mozilla Firefox (on 1c0405fe15ad) where 1c0405fe15ad is the ID of the container we launched.
That's it for this one. Hope it helped you in some way. See you next time ...!!