Launching graphical application inside the docker container
Launching Docker

Launching graphical application inside the docker container

Hello guys, In this article I am going to discuss how to launch the graphical application inside the docker.

So, for this I am going to use Mozilla Firefox as a web browser that will be launched inside the fedora docker container. So, to this there are some prerequisites that have to be fulfilled to successfully run a docker container.

Prerequisites:

  • Docker installed in your system (for sake I used Linux as host system you can refer to Docker documentation for how to use docker in your platform)
  • Internet Connection
  • sudo privileges

So, without nodding let's start and jump to practical as I also hate theory.

No alt text provided for this image
GIF: Tenor (nodding off)

First open the terminal, create a directory let's say docker-gui (in my case) and enter into the directory by typing.

$ mkdir docker-gui && cd docker-gui/ && pwd        
No alt text provided for this image

as you can see in my terminal window

Then create a file named 'Dockerfile' inside the directory using any text editor you like I have used vim for that.

No alt text provided for this image

Now, append the following lines into the file and save it.

No alt text provided for this image
Content inside the Dockerfile

Disclaimer: You can skip the line written after '#' it's all just comments but don't forget to match case

Code Explantion:

The first line, i.e.

From fedora: latest        

is telling the docker to pull latest fedora image from the docker repository then the line,

RUN dnf update -y && dnf install firefox -y        

is used to tell the docker to run the commands inside the docker container by image in our case

dnf update -y

command is used to update the repository metadata and update all the installed packages to the latest version available in the repository. while

dnf install firefox -y

command is issued to install firefox package and all it's dependencies and co-dependencies to run firefox browser inside the docker container.

Remember: To append '-y' at the end of each command while installing packages. otherwise docker will throw error when the container will start building and installing packages as '-y' denotes that you have already permitted all requires changes while executing the 'dnf' command

Now, the part

RUN echo "memory 4g" >> /etc/sysctl.conf
RUN echo "limit memblock unlimited" >> /etc/sysctl.conf        

is used to remove the default memory limit configured by docker for each container just in case our application gets crashed while running due to low system resources inside the docker container.

So now, let's move further with Docker part.

Once, the file has been created pull the latest fedora docker image by typing below command in the terminal:

$ sudo docker pull fedora:latest        

As you can also see in my terminal window:

No alt text provided for this image
pulling the latest fedora docker image from docker hub (repository)

Now after entering the command if terminal prompts for password type the password and hit enter.

Docker will start pulling the latest fedora docker image from repository into your system. If you get the similar output like below then it means docker have pulled the fedora image into your local system

No alt text provided for this image
fedora docker image pulled from docker hub

So, now that we have got the docker image cached in our system for use we can start building the container simply by typing the command and name you want to give to your docker container...

$ sudo docker build -t my-gui-app .        

as shown in the terminal window:

No alt text provided for this image
command to build the docker container

after typing hit enter, and wait for few seconds or minutes maybe the command will start generating container from the image pulled by docker. you might see the output like below...

No alt text provided for this image
Docker building the container from the fedora image.

Now, after this output once the command stops generating output you will see that the container is now successfully running.

But SK!!! Where is the GUI?

No alt text provided for this image

Hold on... guys I know that you might ask this question and that's totally fair too as I promised GUI inside container but whole time I we sticked with the terminal window fuzzing with fonts.

But there's a saying "patience is a key to success", so here we are...

only far from just one command.

So, as we know that the container has built and running in background so in order enter into the container to interact with it, In terminal enter the following command.

$ sudo docker run -it --env="DISPLAY" --net=host my-gui-app        

as you can also see in my terminal,

No alt text provided for this image
command to run container with access to host display and host network card

Here, docker run command is issued to run the container along with the option '-i' and '-t' which are used to denote that we want to run the container in interactive mode as well as in terminal session while --env=DISPLAY is used to provide access to the host display outside the container while --net=host is used to share the host network for internet connectivity.

after this you will be entered into the container...

as you can see in my terminal username changed from sk to root (user inside container)

No alt text provided for this image
inside the docker container

now as we know that we have already installed the firefox browser inside the docker so check that it is running or not you can try running firefox by entering

firefox

command, as you can see in my terminal I was able to successfully run the browser or graphical application better to say.

No alt text provided for this image

But I didn't stopped here to check everything is working fine or not I again installed a graphical file manager Nautilus inside the docker container by running

$ dnf install nautilus -y        

command, and from the screenshot below you can also see that everything with the file manager is working absolutely fine.

No alt text provided for this image
nautilus running inside the docker

So that's it for now, we will meet again in another article.

Till then you can go through my recent articles here

Thanks,

- SK -
























要查看或添加评论,请登录

SAKSHAM TRIVEDI的更多文章

  • DNF5... It's time to rethink the package management.

    DNF5... It's time to rethink the package management.

    Hello Folks, It's been a while since I have written any article. Well here I am now.

  • File BackuP & Sync...

    File BackuP & Sync...

    Introduction In today's fast-paced world, seamless file sharing and synchronization are essential for efficient…

  • Simplifying SSH Connection: A Guide To Build Your Own Proxy Network

    Simplifying SSH Connection: A Guide To Build Your Own Proxy Network

    Establishing a secure SSH connection between Machine A and Machine F can be challenging, especially when intermediate…

  • Unleashing the Power of Linux: A Browser-Based Linux Experience

    Unleashing the Power of Linux: A Browser-Based Linux Experience

    To access Fedora Linux's graphical system in a browser using Apache Guacamole, you will need to set up Guacamole on a…

  • Gmail from Old Dog Terminal

    Gmail from Old Dog Terminal

    Mutt is used to send and receive email from your terminal, even if you're using hosted service such as Gmail. A…

  • Let's WhatsApp using Bash

    Let's WhatsApp using Bash

    S: AuthorAuthorIntroduction In today's fast-paced world, automation plays a crucial role in streamlining various tasks.…

    5 条评论
  • Ping... a message arrrived

    Ping... a message arrrived

    In this short tutorial, Here I am going to demonstrate chatting using ping command. For this first of all you need a…

    1 条评论
  • Containerized SSH Server

    Containerized SSH Server

    In this article I am going to demonstrate how to containerize SSH server so without any further explanation let's…

  • Mutiple Linux shells on a same system

    Mutiple Linux shells on a same system

    Recently I came across the question is there any possibility that multiple shells can be installed on the same system…

  • Jupyter Lab as a container

    Jupyter Lab as a container

    This article is focused on containerizing Jupyter Notebook inside the docker container with a fully-fledged develop…

社区洞察

其他会员也浏览了