This guide shows how to run GroupDocs.Total for Node.js via Java inside a Docker container using a minimal example.
Limitations
Linux containers are recommended and fully supported.
Ensure adequate fonts are installed in the container for accurate text layout.
For Metered licensing, outbound internet access is required to report consumption. File-license mode works fully offline.
Dependencies
We are going to build the Docker image in two stages to minimize the final image size. In the first stage we build the application, and in the second stage we run it.
The key dependencies for the build stage are Node.js, JDK (Java Development Kit), and build tools. The final runtime stage requires only Node.js and JRE (Java Runtime).
Basic Example
This is a practical example showing how to convert a document in a Docker container using the sample code. The final Docker image can be run as an application by passing the source file, the output file name, and an optional license file. See the Temporary License page for more details.
Let’s look at the most essential parts of the application:
import{Converter,License}from'@groupdocs/groupdocs.total';importjavafrom'java';constPdfConvertOptions=java.import('com.groupdocs.conversion.options.convert.PdfConvertOptions');// Get the input file, output path, and license paths from the command line arguments
const[inputPath,outputPath,licensePathArg]=process.argv.slice(2);// Get the license path from the command line arguments or the environment variable
constlicensePath=licensePathArg||process.env.GROUPDOCS_LICENSE_PATH;if(licensePath){License.setLicense(licensePath);}constconverter=newConverter(inputPath);converter.convert(outputPath,newPdfConvertOptions());converter.close();process.exit(0);
{"name":"GroupDocs.Total for Node.js via Java Example","version":"1.0.0","type":"module","private":true,"main":"convert-file.js","license":"MIT","scripts":{"start":"node convert-file.js"},"engines":{"node":">=20"},"dependencies":{"@groupdocs/groupdocs.total":"^26.8.0"}}
# Build stage β compiles native module and installs dependenciesFROM node:20-bullseye AS buildRUN apt-get update && apt-get install -y \
openjdk-17-jdk-headless \
build-essential python3# Clean up cacheRUN rm -rf /var/lib/apt/lists/*# Set JAVA_HOME and update PATHENVJAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64ENVPATH=$JAVA_HOME/bin:$PATH# Set working directoryWORKDIR /app# Copy package filesCOPY package*.json ./# Install dependenciesRUN npm install --omit=dev# Copy the rest of the appCOPY . .# Final stage β slim runtime imageFROM node:20-bullseye-slim AS final# Install Java runtimeRUN apt-get update && apt-get install -y \
openjdk-17-jre-headless # Clean up cacheRUN rm -rf /var/lib/apt/lists/*# Set JAVA_HOME and update PATHENVJAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64ENVPATH=$JAVA_HOME/bin:$PATH# Set working directoryWORKDIR /app# Copy built application and node_modules from the build stageCOPY --from=build /app .# Set the entry point and default commandENTRYPOINT["node","/app/convert-file.js"]