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

This article provides step-by-step instructions on how to create a docker image to run GroupDocs.Conversion for node.js via java. It includes script to install node.js to run GroupDocs.Conversion for node.js via java and offers sample code to verify the installation. Additionally, you will find guidance on running the Docker image via the terminal and executing the sample code, illustrating the utilization of GroupDocs.Conversion for Node.js via Java. Here are the essential steps to be followed:

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

  1. Create a directory on your system
  2. Write the instructions to create a Docker image in a file named Dockerfile
  3. Write the Node.js code in a file named gdapp.js
  4. Copy both files into the recently created directory
  5. Put the input DOCX file into the same directory
  6. Access the terminal/command window within the previously mentioned directory and execute the following command to generate a Docker image
  7. docker build -t gd-conversion-image .
  8. Run the following command to run the container to convert input DOCX to PDF
  9. docker run -it gd-conversion-image

The steps outlined above explain how to use GroupDocs.Conversion for node.js via java. To begin, you’ll need to create the necessary files and save them in a designated folder. Afterward, open a terminal/command window within the same directory. In the subsequent steps, you will execute commands to build a Docker image and run it using a second command. The code example in gdapp.js converts a Word document to PDF. You can find the output PDF file in the same directory after executing the following code example.

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

Dockerfile

gdapp.js

This Docker script begins with the OpenJDK 8 image as its foundation, and then proceeds to install Node.js, Python 2.x, the PIP command, Node-Java Bridge, essential build tools for node-gyp, and GroupDocs.Conversion for Node.js via the npm command. If you wish to execute code within the container, you can use the following command: ‘docker run -it -v /PathToSharedFolderOnHostComputer:/SharedFolder gd-conversion-image /bin/bash’. This command allows for the sharing of a folder between the host computer and the Docker container, facilitating data exchange.

When you execute the Docker image, it generates a container and displays a command prompt. In this prompt, execute the command ’node gdapp.js,’ which performs the conversion of the DOCX file to PDF. Since the container lacks document viewing tools, you can transfer the resulting PDF file to the shared folder named ‘SharedFolder’ within the container. This action will make the file accessible in the ‘PathToSharedFolderOnHostComputer’ directory on your host computer, where it can be viewed using a PDF viewer.

 English