Taking images in Docker container

Seema Saharan
Analytics Vidhya
Published in
4 min readJun 1, 2020

Have you ever tried to click photos with your camera in the laptop, of course, you did, but here is a twist, we will click the photo in a Docker container, many of you may be wondering how you can do that? Well, let me get started with this interesting thing.

Firstly, here are some of the prerequisites you should have on your laptop:

  • Redhat Linux/ CentOS Linux
  • Docker
  • Python3
  • You should have the basic knowledge of the Docker and Linux command line.

And, some of the python libraries, that we will discuss later.

So, are you excited!! I hope you are. Let’s get started:

Here, for this tutorial, I will be using RHEL (Redhat Enterprise Linux), which is a Linux distribution. So, to use docker in RHEL system, we first have to install it by the following command:

✔ Step 1 :

Explanation:

  1. The first line is used to install Docker CE (Community Edition).
  2. And after that, we have to start the service to use a docker container.

✔Step 2:

Now moving on to the main part of this task, i.e. launching a docker container in RHEL.

Woah, that’s a big line, don’t be afraid, I will break down each keyword to you:

  • Firstly I have used the “docker run” command that is used to launch a new container.
  • Next, I have used options -i, -t, -p, -v,- -privileged, -e,- -name :

--interactive or -i

> To keep STDIN open even if not attached.

-t or --tty

> To allocate a pseudo-TTY.

--publish , -p

> Publish a container’s port(s) to the host.

  • “55555:22”: Map TCP port 22 in the container to port 55555on the Docker host.

--volume or -v

> Bind mount a volume.

  • “/dev/video0:/dev/video0”: This is the webcam name of your laptop so that you can access it. And, after the colon, this will be saved in the docker container.
  • “/root/Desktop/rhel7_5_extras:/extras”: This image is imported because it has the required tools available, in this case, Python3, and it will be saved in the docker container as extras.
  • “/root/Desktop/rhel7_extra_new_rpm:/new”: Again this image also contains some of the required tools to perform this task.
  • “/root/Desktop/python_lib:/python”: It contains the Python libraries that will be used further to be installed in the docker container.
  • “/run/media/root/RHEL-7.5\ Server.x86_64:/dvd”: This is the RHEL DVD which contains all the software.
  • “/tmp/.X11-unix:/tmp/.X11-unix:ro”: X server is a windowing system for bitmap displays, common on Linux operating systems. To simply understand this, you can use GUI in your docker container.

--privileged

> Give extended privileges to this container.

--env , -e

> Set environment variables.

  • “DISPLAY=$DISPLAY”: The magic word in the X window system is DISPLAY. A display consists (simplified) of:
  1. A keyboard
  2. A mouse
  3. and a screen.

A display is managed by a server program, known as an X server. The server serves displaying capabilities to other programs that connect to it. The remote server knows where it has to redirect the X network traffic via the definition of the DISPLAY environment variable which generally points to an X Display server located on your local computer.

--name

> Assign a name to the container.

  • “camera1”: It is the name given to the docker container.

At last, there is “centos:latest” which is the image I am using to deploy my docker container.

✔ Step 3:

The /etc/ssh/sshd_config file is the system-wide configuration file for OpenSSH which allows you to set options that modify the operation of the daemon. This file contains keyword-value pairs, one per line, with keywords being case insensitive.

To run graphical applications we have used, X11Forwarding yes.

✔ Step 4:

D-Bus is a software bus, inter-process communication, and remote procedure call mechanism that allows communication between multiple processes running concurrently on the same machine.

The /etc/machine-id file contains the unique machine ID of the local system that is set during installation or boot.

✔ Step 5:

To set the environmental flag to force Qt to show properly.

Qt is a free and open-source widget toolkit for creating graphical user interfaces as well as cross-platform applications that run on various software and hardware platforms such as Linux, Windows.

✔ Step 6:

It is used to create the repository so that we can install the required Softwares later.

✔ Step 7:

✔ Step 8:

✔ Step 9:

✔ Step 10:

To run GUI applications as the root.

✔ Step 11:

Finally, write a program to click the photo in your docker container.

✔ Step 12:

Line 1 is used to make the python file executable.

Line 2 is used to execute the code.

So, that is the end of the task, I hope you learned a lot in this.

Happy learning! 😊✌

--

--

Seema Saharan
Analytics Vidhya

SRE @Autodesk | Speaker @github Universe '21, @gitlab Commit '21 | Organizer @awsugjaipur | Red Hat Certified ×3, CKA