Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
This guide shows how to run Aspose.HTML for Java inside a Docker container using a Dockerfile.
Docker packages your application together with its runtime and dependencies into an isolated image. As a result, you can run HTML conversion and processing consistently on any machine where Docker is available (local workstation, CI, or production servers).
For predictable HTML-to-PDF/image rendering you typically need fonts inside the container.
Required package:
Note: On Alpine images the
ttf-mscorefonts-installerpackage may not be available in all repositories. If you hit this limitation, use the manual installation approach shown below, or consider a Debian/Ubuntu-based base image where font packages are usually more accessible.
A working Docker example is available in the Aspose GitHub repository:
Make sure Docker is installed on your machine. If needed, download it from the official website:
A Dockerfile describes your container environment and how to build the image. Place it in the root of your project (or adjust paths accordingly).
Below is a minimal example that copies a prebuilt application JAR and runs it.
1FROM eclipse-temurin:21-jdk-alpine
2
3ENV SAMPLE_APP_JAR=Aspose.HTML-for-Java.WebService-on-Docker.jar
4ENV ASPOSE_PRODUCT_DIR=aspose-html-for-java
5ENV ASPOSE_SAMPLE_APP_DIR=sample-web-service
6
7# 1. Create work directories
8ENV WORK_DIR_HOME=/home/${ASPOSE_PRODUCT_DIR}
9RUN mkdir -p ${WORK_DIR_HOME}
10
11# 2. Set up app directory and copy the JAR
12ENV SERVICE_HOME=${WORK_DIR_HOME}/${ASPOSE_SAMPLE_APP_DIR}
13RUN mkdir -p ${SERVICE_HOME} && chmod -R 775 ${SERVICE_HOME}
14COPY build/libs/${SAMPLE_APP_JAR} ${SERVICE_HOME}/
15ENV APP_PATH=${SERVICE_HOME}/${SAMPLE_APP_JAR}
16
17# 3. Set up assets directory (optional)
18# Adjust paths to your project layout and build context.
19ENV ASSETS=${SERVICE_HOME}/assets
20RUN mkdir -p ${ASSETS} && chmod -R 775 ${ASSETS}
21COPY ../../assets/ ${ASSETS}/
22
23# 4. Quick check (optional)
24RUN java -version
25
26# 5. Expose service port (used with docker run -p)
27EXPOSE 9999
28
29# 6. Run the application
30ENTRYPOINT ["java", "-jar", "/home/aspose-html-for-java/sample-web-service/Aspose.HTML-for-Java.WebService-on-Docker.jar"]If you convert HTML to PDF/images, install fonts so text renders consistently and layout matches expectations.
Below is an Alpine-based example that installs common font dependencies and shows one way to add Microsoft Core Fonts.
1FROM eclipse-temurin:21-jdk-alpine
2
3ENV SAMPLE_APP_JAR=Aspose.HTML-for-Java.WebService-on-Docker.jar
4ENV ASPOSE_PRODUCT_DIR=aspose-html-for-java
5ENV ASPOSE_SAMPLE_APP_DIR=sample-web-service
6
7ENV WORK_DIR_HOME=/home/${ASPOSE_PRODUCT_DIR}
8RUN mkdir -p ${WORK_DIR_HOME}
9
10ENV SERVICE_HOME=${WORK_DIR_HOME}/${ASPOSE_SAMPLE_APP_DIR}
11RUN mkdir -p ${SERVICE_HOME} && chmod -R 775 ${SERVICE_HOME}
12COPY build/libs/${SAMPLE_APP_JAR} ${SERVICE_HOME}/
13
14ENV ASSETS=${SERVICE_HOME}/assets
15RUN mkdir -p ${ASSETS} && chmod -R 775 ${ASSETS}
16COPY ../../assets/ ${ASSETS}/
17
18# Install font tools and common fonts
19RUN apk add --no-cache \
20 fontconfig \
21 freetype \
22 ttf-dejavu \
23 ttf-droid \
24 ttf-freefont \
25 ttf-liberation \
26 ttf-opensans \
27 curl \
28 cabextract \
29 xz \
30 unzip \
31 msttcorefonts-installer || true
32
33# Optional: manual Microsoft Core Fonts install (Arial example)
34RUN mkdir -p /usr/share/fonts/truetype/msttcore && \
35 cd /usr/share/fonts/truetype/msttcore && \
36 curl -LO http://downloads.sourceforge.net/corefonts/arial32.exe && \
37 cabextract -F '*.ttf' arial32.exe && \
38 rm -f arial32.exe && \
39 fc-cache -f -v
40
41# Verify fonts (optional)
42RUN java -version && fc-list | grep -i arial || true
43
44EXPOSE 9999
45ENTRYPOINT ["java", "-jar", "/home/aspose-html-for-java/sample-web-service/Aspose.HTML-for-Java.WebService-on-Docker.jar"]Tips
/usr/share/fonts) and run fc-cache -f -v.Before building the image, make sure your application JAR exists (for example, run your build to produce build/libs/*.jar).
Open a terminal in the folder with your Dockerfile and run:
1docker build -t my-image .Replace my-image with any image name you prefer.
Run the container and map ports from your host to the container:
1docker run -p 8080:9999 --rm my-image8080 — port on your host machine9999 — port exposed by the application inside the container--rm — automatically removes the container after it stopsTo list active containers:
1docker psYou should see your container in the list, including port mappings.
Running Aspose.HTML for Java in Docker gives you a consistent and reproducible environment for HTML conversion and processing across local development, CI pipelines, and production deployments.
If you see differences in layout or missing glyphs, start by verifying that the container contains all required fonts and that the font cache is rebuilt (fc-cache -f -v).
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.