How to create a Liferay custom docker image
Written By
Sivakumar Perumal
How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!
While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.
Legacy Article
You are viewing an article from our legacy "FastTrack"
publication program, made available for informational purposes. Articles
in this program were published without a requirement for independent
editing or verification and are provided"as is" without
guarantee.
Before using any information from this article, independently verify its
suitability for your situation and project.
Issue
- How to create a Liferay custom docker image using any base image?
Environment
- Liferay DXP 7.0, 7.1, 7.2, 7.3, 7.4
- Elasticsearch
Resolution
- To create a custom docker image, a Dockerfile should be created. A Dockerfile is a text file that contains a list of commands that the Docker daemon calls while creating an image. The Dockerfile contains all the information that Docker needs to know to run the app — the base Docker image to run from, location of our project code or files, any dependencies, and what commands to run at start-up.
- Simply put, it's a great way to automate the way we create a custom Docker image. The best part is that the commands you write in a Dockerfile are almost identical to their equivalent Linux commands. This means you don't really have to learn new syntax to create your own Dockerfile.
- For Liferay custom docker image, user may use below Dockerfile
FROM liferay/portal:7.2.0-ga1
COPY $LIFERAY:liferay deploy /mnt/liferay/deploy
COPY $LIFERAY:liferay patching /mnt/liferay/patching
COPY $LIFERAY:liferay scripts /mnt/liferay/scripts
COPY $LIFERAY:liferay configs /home/liferay/configs
- For Elasticsearch
shiv@1G2BNF2:~/elasticsearch$ cat Dockerfile
FROM elasticsearch:6.5.0
RUN ./bin/elasticsearch-plugin install analysis-icu
RUN ./bin/elasticsearch-plugin install analysis-kuromoji
RUN ./bin/elasticsearch-plugin install analysis-smartcn
RUN ./bin/elasticsearch-plugin install analysis-stempel
shiv@1G2BNF2:~/elasticsearch$ docker build .
Sending build context to Docker daemon 2.048kB
Step 1/5 : FROM elasticsearch:6.5.0
6.5.0: Pulling from library/elasticsearch
aeb7866da422: Pull complete
81639a7b2dd2: Pull complete
e19ec3fb86be: Pull complete
da4a438e18a0: Pull complete
a67c58efe429: Pull complete
13fe2c49e9dd: Pull complete
162a1c0b34b0: Pull complete
64d1055a351e: Pull complete
Digest: sha256:81a75d058b2ca52be06915eed43343c4e289d5463265de8446fbd77f8e170327
Status: Downloaded newer image for elasticsearch:6.5.0
---> ff171d17e77c
Step 2/5 : RUN ./bin/elasticsearch-plugin install analysis-icu
---> Running in 0fbc3cd33cbd
-> Downloading analysis-icu from elastic
[=================================================] 100%??
-> Installed analysis-icu
Removing intermediate container 0fbc3cd33cbd
---> ef8929767919
Step 3/5 : RUN ./bin/elasticsearch-plugin install analysis-kuromoji
---> Running in 3db6c4a70d0f
-> Downloading analysis-kuromoji from elastic
[=================================================] 100%??
-> Installed analysis-kuromoji
Removing intermediate container 3db6c4a70d0f
---> c19b8615f72b
Step 4/5 : RUN ./bin/elasticsearch-plugin install analysis-smartcn
---> Running in b5a1b5be8283
-> Downloading analysis-smartcn from elastic
[=================================================] 100%??
-> Installed analysis-smartcn
Removing intermediate container b5a1b5be8283
---> e11b96cb54e8
Step 5/5 : RUN ./bin/elasticsearch-plugin install analysis-stempel
---> Running in 23176fb83dc9
-> Downloading analysis-stempel from elastic
[=================================================] 100%??
-> Installed analysis-stempel
Removing intermediate container 23176fb83dc9
---> afc74f854edc
Successfully built afc74f854edc
shiv@1G2BNF2:~/elasticsearch$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> afc74f854edc 19 minutes ago 795MB
shiv@1G2BNF2:~/elasticsearch$ docker tag afc74f854edc customimage/es:1.0
shiv@1G2BNF2:~/elasticsearch$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
customimage/es 1.0 afc74f854edc 21 minutes ago 795MB
- The basic syntax used to build an image using a Dockerfile is:
docker build [OPTIONS] PATH | URL | -
To build a docker image, you would therefore use:
docker build [location of your dockerfile]
If you are already in the directory where the Dockerfile is located, put a.instead of the location:
docker build .
By adding the -t flag, you can tag the new image with a name which will help you when dealing with multiple images:
docker build -t my_first_image .
Once the image is successfully built, you can verify whether it is on the list of local images with the command:
docker images
Additional Information
Did this article resolve your issue ?