Docker:
Docker is an open source platform for building, deploying, and managing containerized applications. It provides platform as a service (PaaS) that use OS-level virtualization to deliver software in packages called containers.
While developers can create containers without Docker, Docker makes it easier, simpler, and safer to build, deploy, and manage containers. It’s essentially a toolkit that enables developers to build, deploy, run, update, and stop containers using simple commands and work-saving automation.
When working with docker containers we mostly use CLI, but today we will create a Docker Image in which we will use GUI application:-
Now, as we have already seen previously how to install docker so let's get started:
Downloading Docker Image:
docker pull centos
Using this command by default the latest version of that image will be pulled If we don't specify the version.
Creating Dockerfile:
A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession.
FROM centos
RUN yum install firefox -y
CMD ["/usr/bin/firefox"]
Build the Dockerfile:
docker build -t <image_name> <file_path>
Launch docker Container using GUI image:
Now, we launch docker container using our image by running command:
docker run -it --env="DISPLAY" --net=host <image_name>
We will have to make sure to keep the environment variable to be DISPLAY as it is a GUI application.
As we can see firefox opens up which will be running from the docker container:
Our task of launching GUI applications in Docker Container is complete.