Using Aspose.HTML for Java In Docker – Run HTML Conversion & Processing Anywhere
Overview
This guide walks through the process of running Aspose.HTML for Java in a Docker container using a provided Dockerfile.
Docker simplifies application deployment by packaging the application and its dependencies
into a container that can run on any system with Docker installed.
Follow the steps below to build and run your Docker image.
Requirements
Required libraries for work:
- ttf-mscorefonts-installer - Microsoft True Type Core Fonts package.
Example in Docker
You can find a working Docker example for using Aspose.HTML for Java on our GitHub:
Step-by-Step Instructions
Install Docker:
- Ensure Docker is installed on your system. You can download it from the Docker website.
Prepare Your Dockerfile:
- A
Dockerfiledefines the environment and the steps to set up your application. Make sure you have theDockerfilein your project directory. This file should contain the necessary instructions to build your Docker image.
1FROM registry.access.redhat.com/ubi8/ubi:8.9-1028 2 3ENV FID_HOME=/opt/icgccbfid 4RUN mkdir -p $FID_HOME 5ENV MEDIA=/media/sf_redhat/ 6RUN mkdir -p $MEDIA 7RUN chmod -R 775 $MEDIA 8COPY ../../assets $MEDIA 9ENV SERVICE_HOME=$FID_HOME/test-redhat 10RUN mkdir -p $SERVICE_HOME 11RUN chmod -R 775 $SERVICE_HOME 12COPY target/testing-aspose-redhat-jdk-1.0.0.jar $SERVICE_HOME/app.jar 13ENV APP_PATH=${SERVICE_HOME}/app.jar 14 15RUN yum -y --skip-broken install wget 16RUN cd ~ 17RUN yum -y install java-1.8.0-openjdk 18RUN ls 19 20# 3. Install Microsoft True Type Core Fonts 21RUN yum -y --skip-broken install -y ttf-mscorefonts-installer fontconfig 22RUN fc-list 23RUN ls 24 25RUN yum -y --skip-broken install rpm 26RUN ls- A
Install Microsoft True Type Core Fonts:
Add the following lines to your
Dockerfileto install fonts:1RUN yum -y --skip-broken install -y ttf-mscorefonts-installer fontconfig 2RUN fc-list 3RUN ls
Build the Docker Image:
Open your terminal and navigate to the directory containing your
Dockerfile.Run the following command to build your Docker image:
1 docker build -t my-image .Replace
my-imagewith a name of your choice for the image.
Run the Docker Container:
Once the image is built, you can run it using the following command:
1docker run -p8080:9999 -p2222:22 --rm my-imageReplace
host_portwith the port on your host machine you want to map.Replace
container_portwith the port inside the container that your application is using.Replace
my-imagewith the name of your built image.
Verify the Container is Running:
You can check if your container is running by executing:
1docker psThis command will list all running containers along with their details.
Using Aspose.HTML for Java in Docker simplifies the development and deployment process by providing a consistent environment. Following the steps above, you can easily set up and run Aspose.HTML applications in Docker containers.