RUN GUI APPLICATION IN DOCKER CONTAINER
- Docker is an open platform for developing, shipping, and running applications.
- Docker enables you to separate your applications from your infrastructure so you can deliver software quickly.
- With Docker, you can manage your infrastructure in the same ways you manage your applications.
- A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.
- Container images become containers at runtime and in the case of Docker containers — images become containers when they run on Docker Engine.
Let’s start -
First we have to install the Docker in RHEL-8.4
After complete installation of docker -
1.Start Docker Service and check the docker is started or not
▪️ Start service using systemctl inside docker container -
systemctl start docker
▪️ Check the docker service (start or not) -
systemctl status docker
2. Pull the CentOS image
By default, docker pull pulls images from Docker Hub. It is also possible to manually specify the path of a registry to pull from.
docker pull centos
3. Make a Directory in BaseOS and go into that directory
The mkdir() function creates a new, empty directory whose name is defined by path.
mkdir dir_name
eg. mkdir dockergui
cd dir_name
eg. cd dockergui
4. Create Dockerfile
Docker can build images automatically by reading the instructions from a 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.
vim Dockerfile
▪️ Write following code in Dockerfile
FROM centos
RUN yum install firefox -y
cmd firefox
5. Build Dockerfile
The docker build command builds an image from a Dockerfile.
The PATH
is a directory on your local filesystem.
docker build -t container_img .
e.g docker build -t firefoxgui .
- -t : Tag option helps us to tag the image with proper name
- container_img : Here the container image is “firefoxgui”.
- Dot operator(.) : Indicates the Dockerfile is present in the current folder.
6. Launch GUI application
docker run -it — name guifirefox — env=”DISPLAY” — net=host firefoxgui:latest
- env=”DISPLAY” : The command env displays all environment variables and their values from the HostOs.
- — net =host : The
--net=host
option is used to make the programs inside the Docker container look like they are running on the host itself, from the perspective of the network.
Now, successfully GUI application(Firefox) run in docker container !!!