Create a Docker Image to Run GroupDocs.Viewer for Node.js via Java

This comprehensive article walks you through the process of setting up your environment by providing detailed, step-by-step instructions on how to create a docker image to run GroupDocs.Viewer for node.js via java. It covers everything you need to get started, including a script that will install node.js to run GroupDocs.Viewer for node.js via java, ensuring that all necessary dependencies are properly configured within your Docker container. To help you validate your setup, the article also includes a sample Node.js script designed to confirm that GroupDocs.Viewer is functioning as expected within the container. Furthermore, you’ll receive clear guidance on how to run the Docker image directly from your terminal or command prompt and how to execute the included sample code, providing a practical demonstration of how to utilize GroupDocs.Viewer for Node.js via Java in a Dockerized environment.

Below, you’ll find the essential steps required to complete this setup from start to finish:

Steps to Install GroupDocs.Viewer for Node.js via Java

  1. Create a new directory on your system to hold your project files
  2. Inside this directory, create a file named Dockerfile and add the necessary instructions to define the Docker image
  3. Write your Node.js application code and save it in a file named gdviewer.js
  4. Move both the Dockerfile and gdviewer.js into the project directory you created earlier
  5. Place the input DOCX file that you want to render into the same directory
  6. Open a terminal or command prompt, navigate to the project directory, and run the following command to build the Docker image
  7. docker build -t gd-viewer-image .
  8. After the image has been built successfully, use the following command to start the container and perform the rendering process of DOCX to HTML
  9. docker run -it gd-viewer-image

The instructions provided above demonstrate how to use GroupDocs.Viewer for Node.js via Java. To get started, you’ll first need to create the required files and store them in a specific folder on your system. Once that’s done, open a terminal or command prompt within that folder. The above steps will guide you through building a Docker image using a set of commands, followed by running the container with another command. The sample code found in gdviewer.js is designed to render a DOCX (Word) document into HTML. Once the example is executed, the generated HTML files will be stored in the same folder.

Script to Install Node.js to run GroupDocs.Viewer for Node.js via Java

Dockerfile

gdviewer.js

This Docker setup starts by using the OpenJDK 8 image as its base. It then installs a series of necessary components, including Node.js, Python 2.x, the PIP package manager, the Node-Java Bridge, and the build tools required for node-gyp. Additionally, it installs GroupDocs.Viewer for Node.js using the npm package manager.

To run code inside the container, you can use the following command: docker run -it -v /PathToSharedFolderOnHostComputer:/SharedFolder gd-viewer-image /bin/bash

This command mounts a shared folder between your host machine and the Docker container, making it easy to transfer data in and out of the container environment.

When you run the Docker image, it creates a container and shows a command prompt. At this prompt, type node gdviewer.js to render the Word document to web pages. Because the container doesn’t have any document viewers, you need to move the HTML files to the shared folder called SharedFolder inside the container. In this manner, the HTML files will be saved to the PathToSharedFolderOnHostComputer folder on your computer, allowing you to open and view them using a web browser.

 English