{"id":6700,"date":"2017-09-15T01:22:21","date_gmt":"2017-09-15T05:22:21","guid":{"rendered":"https:\/\/qxf2.com\/blog\/?p=6700"},"modified":"2024-10-16T16:21:46","modified_gmt":"2024-10-16T20:21:46","slug":"view-docker-container-display-using-vnc-viewer","status":"publish","type":"post","link":"https:\/\/qxf2.com\/blog\/view-docker-container-display-using-vnc-viewer\/","title":{"rendered":"View a Docker container&#8217;s display using VNC Viewer"},"content":{"rendered":"<p>It is useful to be able to view your Selenium tests running within a Docker container. This can help you to debug issues better and have more confidence in your tests. We found the ability to look at the tests especially useful when performing some complex actions like drawing, dragging, dropping, etc. To view the Docker container&#8217;s display, we setup up good old <a href=\"https:\/\/www.realvnc.com\/en\/\">VNC<\/a> in the container and used <a href=\"https:\/\/www.realvnc.com\/en\/connect\/download\/viewer\/\">VNC viewer<\/a> to see the display of Docker container. This blog will help you in case you too want to setup VNC Server and VNC Viewer and view the Container display.<br \/>\n<strong>NOTE:<\/strong> If you are totally new to Docker, please consider reading our <a href=\"https:\/\/qxf2.com\/blog\/preparing-a-docker-image-for-running-selenium-tests\/\">previous post<\/a> first.<\/p>\n<hr \/>\n<h3>Steps to setup with VNC and view container display:<\/h3>\n<p>For our demo, we will use the <a href=\"https:\/\/hub.docker.com\/r\/qxf2rohand\/qxf2_pom_essentials\/\">Qxf2-pom-essential <\/a> docker base image and <a href=\"https:\/\/github.com\/qxf2\/qxf2-page-object-model\">Qxf2 public page object model<\/a> which we have discussed as part of our <a href=\"https:\/\/qxf2.com\/blog\/preparing-a-docker-image-for-running-selenium-tests\/\">previous post<\/a>. Below are the steps involved to get set up with VNC.<\/p>\n<ol>\n<li>Setup and enable VNC server on the Container<\/li>\n<li>Setup VNC viewer on your local system<\/li>\n<li>Connect to VNC server using IP and Port Address<\/li>\n<\/ol>\n<hr \/>\n<h3>Step 1: Setup and enable VNC server<\/h3>\n<p>To setup and enable VNC server, we need to<br \/>\na) Install VNC server<br \/>\nb) Expose port to connect and share display data with VNC Viewer<br \/>\nc) Enable VNC server along with the password and display arguments details.<\/p>\n<p>For this post, we are going to use a Docker file and a shell script file. This will help us to clone our <a href=\"https:\/\/github.com\/qxf2\/qxf2-page-object-model\">Qxf2 public page object model<\/a> into the container using git, install VNC server, expose port, enable VNC and run the test.<\/p>\n<p><strong>NOTE: <\/strong> For the demo, we will use git to get our open source code inside the container. Ideally, we would prefer to use Docker volume feature to get the code inside the container. Avoid git in case you are using a private repository due to security reasons.<\/p>\n<p>The Dockerfile below will run Qxf2 POM tests and view the test running across Chrome\/Firefox using VNC viewer. For more details about how to use our <a href=\"https:\/\/hub.docker.com\/r\/qxf2rohand\/qxf2_pom_essentials\/\">Qxf2-pom-essential <\/a> image for running Selenium tests refer to the blog post <a href=\"https:\/\/qxf2.com\/blog\/preparing-a-docker-image-for-running-selenium-tests\/\">here<\/a>. <\/p>\n<p>Pay special attention to the lines that:<br \/>\na)  installs VNC (using apt-get)<\/p>\n<pre lang=\"python\">\r\nRUN pip install --upgrade pip \\\r\n        && apt-get update \\\r\n\t&& apt-get install -y git x11vnc \r\n<\/pre>\n<p>b) open up port 5920<\/p>\n<pre lang=\"python\">\r\n#Expose port 5920 to view display using VNC Viewer\r\nEXPOSE 5920\r\n<\/pre>\n<p>Our entire Dockerfile looks like this:<\/p>\n<pre lang=\"python\">#Content of the entire Dockerfile\r\n#Dockerfile built to run Qxf2 POM tests and view the test running across chrome\/firefox using VNC viewer\r\nFROM qxf2rohand\/qxf2_pom_essentials\r\nMAINTAINER Qxf2 Services\r\n\r\n#Upgrade pip, install Git & VNC \t\r\nRUN pip install --upgrade pip \\\r\n        && apt-get update \\\r\n\t&& apt-get install -y git x11vnc \r\n\r\n# Add entrypoint.sh and other available files to image\r\nADD . \/usr\/qxf2_pom\r\n\r\n#Change directory and clone Qxf2 Public POM repo\r\nRUN cd \/usr\/qxf2_pom \\\r\n\t&& git clone https:\/\/github.com\/qxf2\/qxf2-page-object-model.git \r\n\r\n#Set envirnmental variable for display\t\r\nENV DISPLAY :20\r\n\r\n#Set working directory\r\nWORKDIR \/usr\/qxf2_pom\/qxf2-page-object-model\r\n\r\n#Install requirements using requirements.txt \r\nRUN pip install -r requirements.txt \r\n\r\n#Provide read, write and execute permissions for entrypoint.sh and also take care of '\\r' error which raised when someone uses notepad or note++ for editing in Windows.\r\nRUN chmod 755 \/usr\/qxf2_pom\/entrypoint.sh \\\r\n\t&& sed -i 's\/\\r$\/\/' \/usr\/qxf2_pom\/entrypoint.sh\r\n\r\n#Expose port 5920 to view display using VNC Viewer\r\nEXPOSE 5920\r\n\r\n#Execute entrypoint.sh at start of container\r\nENTRYPOINT [\"\/usr\/qxf2_pom\/entrypoint.sh\"] \r\n<\/pre>\n<p>The shell script file i.e. entrypoint.sh file below will help to configure and run the VNC server along with starting the xvfb, pulling the code from git and then running the test.<\/p>\n<pre lang=\"python\">#!\/bin\/bash\r\n# entrypoint.sh file for starting the xvfb with better screen resolution, configuring and running the vnc server, pulling the code from git and then running the test.\r\nexport DISPLAY=:20\r\nXvfb :20 -screen 0 1366x768x16 &\r\nx11vnc -passwd TestVNC -display :20 -N -forever &\r\ncd \/usr\/qxf2_pom\/qxf2-page-object-model\/\r\ngit pull\r\npytest -B chrome -s -v > pytest_report.log\r\nwait\r\n<\/pre>\n<p>To create an image using above dockerfile, you need to save both files at same directory and use the following command:<\/p>\n<pre lang=\"python\">docker build -t new-image-name Path\/to\/Dockerfile\r\n<\/pre>\n<hr \/>\n<h3>Step 2.  Setup VNC viewer on your local machine<\/h3>\n<p>VNC server sends\/transmit display data information over a specified port. To catch and read that data, we need to get setup with VNC viewer which acts as a client. VNC viewer is available for multiple platforms, you can download it for your platform from <a href=\"https:\/\/www.realvnc.com\/en\/connect\/download\/viewer\/\">RealVNC<\/a> and install it.<\/p>\n<hr \/>\n<h3>Step 3. Connect to the VNC server using IP and Port Address<\/h3>\n<p>To connect VNC viewer to VNC server, you need to know the IP address and port address.<\/p>\n<p><strong>Get IP Address:<\/strong> You need to use the following command to get IP Address.<\/p>\n<pre lang=\"python\">docker-machine ip<\/pre>\n<p><strong>NOTE: <\/strong> <code> docker-machine ip <\/code> command won&#8217;t work on Linux. Use host name i.e. &#8216;localhost&#8217; instead of IP address. <\/p>\n<p><strong>Get PORT address:<\/strong> Port address will depend on &#8216;docker run&#8217; command. In step 1, we built an image which includes VNC server and our Qxf2 public pom code. When we create Docker container using the following command, it will enable display along with Xvfb, VNC server and run the test across chrome.<\/p>\n<pre lang=\"python\">docker run -it -p 5920:5920 image-name-which-provided-in-step-1<\/pre>\n<p>Above command connects\/maps local host port 5920 to container port 5920 and to view the running tests on display, you need to connect with VNC server quickly because once test run gets finished it will show you only black screen.<\/p>\n<p>Now, we know both IP and port address. Next, we need to connect with VNC viewer using both IP and port address. To connect with VNC Viewer, you need to follow following steps.<\/p>\n<ol>\n<li> Open VNC Viewer: Look at VNC Viewer IDE in following Fig. 1. <figure id=\"attachment_6733\" aria-describedby=\"caption-attachment-6733\" style=\"width: 900px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/VNC-Viewer-IDE.png\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/VNC-Viewer-IDE.png\" alt=\"\" width=\"900\" height=\"640\" class=\"size-full wp-image-6733\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/VNC-Viewer-IDE.png 900w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/VNC-Viewer-IDE-300x213.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/VNC-Viewer-IDE-768x546.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/a><figcaption id=\"caption-attachment-6733\" class=\"wp-caption-text\">Fig. 1 VNC Viewer IDE<\/figcaption><\/figure><\/li>\n<li> To connect with VNC Server, enter IP Address\/hostname and port address in search bar. IP Address\/hostname and port address must be separated using &#8216;:&#8217;. For example:<br \/>\nFor windows: docker-machine ip: port number <code> XXX.XXX.XX.XXX:5920<\/code><br \/>\nFor Linux: local host ip\/ hostname: port number <code>localhost:5920<\/code><br \/>\n<figure id=\"attachment_6741\" aria-describedby=\"caption-attachment-6741\" style=\"width: 900px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/Enter-ip-and-port-number.png\" data-rel=\"lightbox-image-1\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/Enter-ip-and-port-number.png\" alt=\"\" width=\"900\" height=\"640\" class=\"size-full wp-image-6741\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/Enter-ip-and-port-number.png 900w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/Enter-ip-and-port-number-300x213.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/Enter-ip-and-port-number-768x546.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/a><figcaption id=\"caption-attachment-6741\" class=\"wp-caption-text\">Fig. 2 Enter IP address and Port number to connect with VNC server<\/figcaption><\/figure><\/li>\n<li> After entering IP and Port number, you will come across following encryption window shown in fig 3. <figure id=\"attachment_6742\" aria-describedby=\"caption-attachment-6742\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/encryption_window.png\" data-rel=\"lightbox-image-2\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/encryption_window.png\" alt=\"\" width=\"500\" height=\"360\" class=\"size-full wp-image-6742\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/encryption_window.png 500w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/encryption_window-300x216.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-6742\" class=\"wp-caption-text\">Fig. 3 Encryption Window<\/figcaption><\/figure><br \/>\nClick on &#8216;Continue&#8217; button on window to move ahead.<\/li>\n<li> Click on &#8216;Continue&#8217; button, you will visit following window shown in fig 4.<figure id=\"attachment_6750\" aria-describedby=\"caption-attachment-6750\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/enter_password-1.png\" data-rel=\"lightbox-image-3\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/enter_password-1.png\" alt=\"\" width=\"500\" height=\"361\" class=\"size-full wp-image-6750\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/enter_password-1.png 500w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/enter_password-1-300x217.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-6750\" class=\"wp-caption-text\">Fig. 4 Enter Password to connect and view display<\/figcaption><\/figure><br \/>\nEnter password here to connect with VNC server and view docker container display. For above dockerfile, the password to connect VNC server is &#8216;TestVNC&#8217;. You can change the password by editing entrypoint.sh file before building the image.<\/li>\n<li> Once you get connected with VNC server successfully, you can the view the docker container dispaly your tests running on chrome as shown in fig 5. <figure id=\"attachment_6744\" aria-describedby=\"caption-attachment-6744\" style=\"width: 1097px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/vnc-display.png\" data-rel=\"lightbox-image-4\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/vnc-display.png\" alt=\"\" width=\"1097\" height=\"728\" class=\"size-full wp-image-6744\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/vnc-display.png 1097w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/vnc-display-300x199.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/vnc-display-768x510.png 768w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2017\/08\/vnc-display-1024x680.png 1024w\" sizes=\"auto, (max-width: 1097px) 100vw, 1097px\" \/><\/a><figcaption id=\"caption-attachment-6744\" class=\"wp-caption-text\">Fig. 5 Docker Container Display<\/figcaption><\/figure><\/li>\n<\/ol>\n<hr \/>\n<p>Hope you enjoyed this post. To know more about the different ways to get your code inside the container, please stay tuned. We will post it soon.<\/p>\n<p><strong>If you are a startup finding it hard to hire technical QA engineers, learn more <a href=\"https:\/\/qxf2.com\/blog\/about-qxf2\/\">about Qxf2 Services<\/a>.<\/strong><\/p>\n<hr>\n<h3>QA services for startups and early-stage products by Qxf2 Services<\/h3>\n<p>This article is courtesy of Qxf2&#8217;s commitment to sharing what we learn. We are among the rare breed of testers who continually learn, evolve and share our learning with the larger testing community. Expert testers who are technical as well are worth their weight in gold. They elevate any software team that works with them. In addition to top-notch technical testers, Qxf2 provides many <a href=\"https:\/\/qxf2.com\/?utm_source=docker-vnc&#038;utm_medium=click&#038;utm_campaign=From%20blog\">excellent software testing services geared towards startups<\/a> that are usually not found in the market. Like front-loaded QA, fractional QA, specialized roles, catch-up services for startups that have taken on too much testing debt, etc. If you are a startup looking for QA, we encourage you to visit our website and get in touch.<\/p>\n<hr>\n<script>(function() {\n\twindow.mc4wp = window.mc4wp || {\n\t\tlisteners: [],\n\t\tforms: {\n\t\t\ton: function(evt, cb) {\n\t\t\t\twindow.mc4wp.listeners.push(\n\t\t\t\t\t{\n\t\t\t\t\t\tevent   : evt,\n\t\t\t\t\t\tcallback: cb\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n})();\n<\/script><!-- Mailchimp for WordPress v4.10.1 - https:\/\/wordpress.org\/plugins\/mailchimp-for-wp\/ --><form id=\"mc4wp-form-1\" class=\"mc4wp-form mc4wp-form-6165 mc4wp-form-theme mc4wp-form-theme-blue\" method=\"post\" data-id=\"6165\" data-name=\"Newsletter\" ><div class=\"mc4wp-form-fields\"><div style=\"border:3px; border-style:dashed;border-color:#56d1e1;padding:1.2em;\">\r\n  <h1 style=\"text-align: center; padding-top: 20px; padding-bottom: 20px; color: #592b1b;\">Subscribe to our weekly Newsletter<\/h1>\r\n  <input style=\"margin: auto;\" type=\"email\" name=\"EMAIL\" placeholder=\"Your email address\" required \/>\r\n  <br>\r\n  <p style=\"text-align: center;\">\r\n    <input style=\"background-color: #890c06 !important; border-color: #890c06;\" type=\"submit\" value=\"Sign up\" \/>\r\n    \r\n  <\/p>\r\n  <p style=\"text-align: center;\">\r\n    <a href=\"http:\/\/mailchi.mp\/c9c7b81ddf13\/the-informed-testers-newsletter-20-oct-2017\"><small>View a sample<\/small><\/a>\r\n  <\/p>\r\n  <br>\r\n<\/div><\/div><label style=\"display: none !important;\">Leave this field empty if you're human: <input type=\"text\" name=\"_mc4wp_honeypot\" value=\"\" tabindex=\"-1\" autocomplete=\"off\" \/><\/label><input type=\"hidden\" name=\"_mc4wp_timestamp\" value=\"1775461524\" \/><input type=\"hidden\" name=\"_mc4wp_form_id\" value=\"6165\" \/><input type=\"hidden\" name=\"_mc4wp_form_element_id\" value=\"mc4wp-form-1\" \/><div class=\"mc4wp-response\"><\/div><\/form><!-- \/ Mailchimp for WordPress Plugin -->\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>It is useful to be able to view your Selenium tests running within a Docker container. This can help you to debug issues better and have more confidence in your tests. We found the ability to look at the tests especially useful when performing some complex actions like drawing, dragging, dropping, etc. To view the Docker container&#8217;s display, we setup [&hellip;]<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[140,107,30,144],"tags":[145],"class_list":["post-6700","post","type-post","status-publish","format-standard","hentry","category-docker","category-pytest","category-selenium","category-vnc-viewer","tag-vnc-viewer"],"_links":{"self":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/6700","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/comments?post=6700"}],"version-history":[{"count":30,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/6700\/revisions"}],"predecessor-version":[{"id":22914,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/6700\/revisions\/22914"}],"wp:attachment":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/media?parent=6700"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/categories?post=6700"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/tags?post=6700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}