RUNNING GUI CONTAINER ON THE DOCKER

PROBLEM STATEMENT:

  1. Launch a container on docker in GUI mode.
  2. Run any GUI software on the 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.

OVERVIEW OF DOCKER :

Docker is an open platform for developing, shipping, and running applications. Docker enables us to separate our applications from our infrastructure so we can deliver software quickly.

With Docker, we can manage our infrastructure in the same ways we manage our applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, we can significantly reduce the delay between writing code and running it in production.

ARCHITECTURE OF DOCKER :

Docker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and distributing our Docker containers. The Docker client and daemon can run on the same system, or we can connect a Docker client to a remote Docker daemon.

The Docker client and daemon communicate using a REST API, over UNIX sockets or a network interface. Another Docker client is Docker Compose, that lets us work with applications consisting of a set of containers.

DOCKER ARCHITECTURE

THE DOCKER DAEMON :

The Docker daemon (dockerd) listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes. A daemon can also communicate with other daemons to manage Docker services.

PRACTICAL PART:

So , Here we can see that in my VM. docker is not installed and I am using rpm command for checking docker installed or not.

#rpm -q docker-ce

we have to install docker using YUM command.if yum is not installed in our os .we have one playbook yum_install.yml using ansible we can install it in our os .

Now, we have to install docker using YUM command.

#yum install docker-ce --nobest

By using docker version command we have to check the version of our docker which is installed in our VM.

#docker --version

This command displays system wide information regarding the Docker installation. Information displayed includes the kernel version, number of containers and images.

#docker info

The docker ps command only shows running containers by default. Docker images have intermediate layers that increase reusability, decrease disk usage, and speed up docker build by allowing each step to be cached.

#docker ps
#docker images

if we don’t have any images their is command to pull images in docker

#docker pull imagename:version#docker pull httpd:latest 

Here we have to create a seperate workspace for dockerfile and we have to write a code in our dockerfile.

By using cat command we can read a dockerfile .

Now we have to be build our image.

#docker build -t firefox .

Sometime dns is not able to resolve network problem in the containers. To avoid this follow the below given steps.

# firewall-cmd --zone=public --add-masquerade --permanent
# firewall-cmd --zone=public --add-port=80/tcp
# firewall-cmd --zone=public --add-port=443/tcp

After setting port no, we have to reload firewall in our system

# firewall-cmd --reload

Now try to start our docker and launch run build command. hope so ,It will work.

Now, we run our image.

#docker run -it --env="DISPLAY" --net="host" firefox

where --env used to Set environment variables and --net used to Connect a container to a network.

Here we have again go to dockerfile and rewrite the code for juypter notebook.

Now we have to be build our image.

#docker build -t jupyter .

now we run our jupyter image

#docker run -it --env=”DISPLAY” --net=host jupyter jupyter notebook --allow-root

where --allow-root used when running root is not available so to bypass.

Here, we can see that one link is given. So, We have to be copy that link and paste in our firefox. we can see that our jupyter notebook is open and its working fine.

Let us create new notebook with python3

Here we run one cell with print statement and finally cell run successfully.

Hope so it is informative…

Keep Learning📖📚 Keep Sharing …

Thank You for Reading !

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store