Using Aspose.HTML for Java In Docker
Overview
This guide walks through the process of running Aspose.HTML for Java in a Docker container using a provided Dockerfile
for Linux. 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:
- xorg-x11-server-Xvfb - Xvfb or X virtual framebuffer is a display server implementing the X11 display server protocol. In contrast to other display servers, Xvfb performs all graphical operations in virtual memory without showing any screen output. For more information see: https://en.wikipedia.org/wiki/Xvfb.
- ttf-mscorefonts-installer - Microsoft True Type Core Fonts package
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
Dockerfile
defines the environment and the steps to set up your application. Make sure you have theDockerfile
in 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 25# 4. Copy and install xorg-x11-server-Xvfb package 26COPY xorg-x11-server-Xvfb-1.20.11-15.el8.x86_64.rpm /tmp/xorg-x11-server-Xvfb-1.20.11-15.el8.x86_64.rpm 27RUN yum -y localinstall /tmp/xorg-x11-server-Xvfb-1.20.11-15.el8.x86_64.rpm 28RUN ls 29 30RUN yum -y --skip-broken install rpm 31RUN ls 32 33# 5. Set ENTRYPOINT to run the application with Xvfb 34ENTRYPOINT xvfb-run --server-args="-screen 0 1024x768x24" java -jar app.jar -Djava.awt.headless=false $APP_PATH
- A
Install Microsoft True Type Core Fonts:
- Add the following lines to your
Dockerfile
to install fonts:1RUN yum -y --skip-broken install -y ttf-mscorefonts-installer fontconfig 2RUN fc-list 3RUN ls
- Add the following lines to your
Copy and Install xorg-x11-server-Xvfb Package:
- Add the following lines to your
Dockerfile
to copy and install thexorg-x11-server-Xvfb
package:1COPY xorg-x11-server-Xvfb-1.20.11-15.el8.x86_64.rpm /tmp/xorg-x11-server-Xvfb-1.20.11-15.el8.x86_64.rpm 2RUN yum -y localinstall /tmp/xorg-x11-server-Xvfb-1.20.11-15.el8.x86_64.rpm 3RUN ls
- Add the following lines to your
Set ENTRYPOINT to Run the Application with Xvfb:
- Add the following line to your
Dockerfile
to set the ENTRYPOINT:1ENTRYPOINT xvfb-run --server-args="-screen 0 1024x768x24" java -jar app.jar -Djava.awt.headless=false $APP_PATH
- Add the following line to your
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-image
with a name of your choice for the image.
- Open your terminal and navigate to the directory containing your
Run the Docker Container:
- Once the image is built, you can run it using the following command:
1docker run -e DISPLAY=:0 -p8080:9999 -p2222:22 --rm my-image
- Replace
host_port
with the port on your host machine you want to map. - Replace
container_port
with the port inside the container that your application is using. - Replace
my-image
with the name of your built image.
- Once the image is built, you can run it using the following command:
Verify the Container is Running:
- You can check if your container is running by executing:
1docker ps
- This command will list all running containers along with their details.
- You can check if your container is running by executing:
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.