This guide will show how to use GroupDocs.Merger for Python via .NET in Docker container.
Dependencies
When using the GroupDocs Python SDK in a Linux environment, make sure the following packages are installed, as they are required for proper library operation:
libicu — ICU library (must not exceed version 70)
libssl1.1 — OpenSSL library required by .NET Core 3.1
Basic Example
This is the most basic example that shows how to run GroupDocs Python APIs in Docker. The example demonstrates how to merge tow DOCX files using GroupDocs.Merger in Docker container.
Note
You can download this sample application from here.
Project Structure
The sample application has the following folder structure:
📂 basic-example/
├── 📂 output/ # Output directory for converted files
├── 📄 .dockerignore # Files to exclude from Docker build context
├── 📄 appendix.docx # Sample input document to merge
├── 📄 beginning.docx # Sample input document to merge
├── 📄 Dockerfile # Docker container definition
├── 📄 GroupDocs.Total.lic # License file (optional)
├── 📄 merge_docx_files.py # Main application code
├── 📄 README.md # Build and run instructions
└── 📄 requirements.txt # Application dependencies
We’re using a Python 3.11 slim image and installing required .NET dependencies libicu and libssl1.1 manually.
Here are the most essential parts:
# Use Python 3.11 slim base image which is smaller than the default base imageFROM python:3.11-slim# Install prerequisites from a reliable sourceENVSNAPSHOT_DATE=20220328T000000Z
RUNecho"deb [trusted=yes] http://snapshot.debian.org/archive/debian/${SNAPSHOT_DATE} bullseye main"\
> /etc/apt/sources.list.d/debian-archive.list &&\
apt-get -o Acquire::Check-Valid-Until=false update &&\
apt-get install -y --no-install-recommends \
libicu67 \
libssl1.1 &&\
apt-get clean &&\
rm -rf /var/lib/apt/lists/*# Set workdir WORKDIR /app# Install Python dependenciesCOPY requirements.txt ./RUN pip install -r requirements.txt# Copy the rest of the appCOPY . .# Run the appCMD["python","merge_docx_files.py"]
importosfromgroupdocs.mergerimportLicense,Mergerdefmerge_docx_files():# Get license file absolute pathlicense_path=os.path.abspath("./GroupDocs.Total.lic")ifos.path.exists(license_path):# Create License and set the pathlicense=License()license.set_license(license_path)# Ensure output directory existsos.makedirs("./output",exist_ok=True)# Initialize the mergerwithMerger("./beginning.docx")asmerger:# Append appendix.docx to beginning.docxmerger.join("./appendix.docx")# Save the merged documentmerger.save("./output/merged.docx")if__name__=="__main__":merge_docx_files()
In case you experience any other exeptions when running the application please contact us using the GroupDocs Free Support Forum and we’ll be happy to help.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.