AEM in docker
Hello Everyone,
In this post we will see how we can run our aem server from docker. Before that why we really need docker, whenever we have a new team member, they will struggle for project setup. Now imagine we have a set up file we can share with any new member who is joining our team. They simply can start their work without wasting time on set up or we can directly start giving KT, so using docker we can achieve this we can create a docker image and we can share the image with team members.
What is docker image ?
A Docker image is a lightweight, standalone, and executable package that contains everything needed to run an application, including the application code, libraries, dependencies. Everything in one image.
How to create docker image ?
1st get docker installed on your machine/system docker toolbox is deprecated so use docker desktop software.
You might face some challenges while installing and starting docker.
Install docker desktop
Enable hyper-v
Step-By-Step:
Enabling Hyper-V for Use on Windows 11 (microsoft.com)
After docker is installed correctly create a Dockerfile.
what is dockerfile?
Umm some instructions for creating docker image. It's a simple text file which will have command to build a docker image. Dockerfile name can be anything.
Now where to create a dockerfile, I am setting up docker image for author and publish environment.
Let's set up for aem author instance first. Below is my project structure, I have kept my aem jar, license and dockerfile in the same directory where my project is created.
FROM adoptopenjdk/openjdk11:alpine-slim
# Set environment variables
ENV CQ_RUNMODE "author"
ENV CQ_JVM_OPTS "-Xmx2048m"
# Set the working directory
WORKDIR /usr/src/app
# Copy AEM quickstart and license file to the container
COPY cq-quickstart-6.5.0.jar ./
COPY license.properties ./
# Set up volume to share crx-quickstart directory with other containers
VOLUME /usr/src/app/crx-quickstart
# Copy the UI content and apps packages to the container
COPY ui.content/target/sampleproject.ui.content-0.0.1-SNAPSHOT.zip ./crx-quickstart/install/sampleproject.ui.content.zip
COPY ui.apps/target/sampleproject.ui.apps-0.0.1-SNAPSHOT.zip ./crx-quickstart/install/sampleproject.ui.apps.zip
# Expose AEM author in port 4504
EXPOSE 4504
# Copy license file to the container
COPY license.properties ./crx-quickstart/license.properties
# Start AEM in author mode
ENTRYPOINT ["java", "-jar", "/usr/src/app/cq-quickstart-6.5.0.jar", "-Dsling.run.modes=author", "-p", "4504"]
FROM adoptopenjdk/openjdk11:alpine-slim
# Set environment variables
ENV CQ_RUNMODE "publish"
ENV CQ_JVM_OPTS "-Xmx2048m"
# Set the working directory
WORKDIR /usr/src/app
# Copy AEM quickstart and license file to the container
COPY cq-quickstart-6.5.0.jar ./
COPY license.properties ./
# Set up volume to share crx-quickstart directory with other containers
VOLUME /usr/src/app/crx-quickstart
# Copy the UI content and apps packages to the container
COPY ui.content/target/sampleproject.ui.content-0.0.1-SNAPSHOT.zip ./crx-quickstart/install/sampleproject.ui.content.zip
COPY ui.apps/target/sampleproject.ui.apps-0.0.1-SNAPSHOT.zip ./crx-quickstart/install/sampleproject.ui.apps.zip
# Copy AEM configuration files to the container
COPY .m2/settings.xml /root/.m2/settings.xml
# Expose AEM publish port
EXPOSE 4503
# Copy license file to the container
COPY license.properties ./crx-quickstart/license.properties
# Start AEM in publish mode
ENTRYPOINT ["java", "-jar", "/usr/src/app/cq-quickstart-6.5.0.jar", "-Dsling.run.modes=publish", "-p", "4503"]
docker build -t sampleimage1
C:\user\code\sampleproject -->dockerfile path
sampleimage1 -->image name we are going to create
Now create a Volume : docker volume is the directory outside of container where data will be stored. volumes can be used to share data between containers or to store data that needs to persist between container restarts.
docker volume create sampleproject_volume1
after creating image and volume start the aem author instance using this image
docker run -p 4504:4504 aem-author or we can volume mount the packages we want to share withing container for doing that run the below command.
docker run -d --name sampleimage1_container -p 4504:4504 -v sampleproject_volume1:/usr/src/app/crx-quickstart/install sampleimage1
Command line for creating docker image use command
C:\Users\username>docker build -t aem-publish
C:\pathToFolder\aem-in-docker\aem-publisher
My dockerfile is located at
C:\pathToFolder\aem-in-docker\aem-publisher
Image name will be aem-publish
Check if image is created or not using docker images command
Once image is created we can run docker run command anywhere
C:\>docker run -p 4503:4503 aem-publish
it will look like below
in docker you images will look like below
One image can have multiple containers like whenever we stop running
image and again start that image it will create a new container for
starting the image.
In below screen shot we can see one image i.e. aem-author is having 4
container it is because I stopped aem instance 3 times and 4th
one is running here all 4 containers are running for single image that
is aem-author
Comments
Post a Comment