Create Your First Hybris Docker Image

Hybris Logo

In this article, I will show how to create a Docker image of the SAP Hybris, how to run it and how to publish it to Docker Hub.

Docker and Hybris

1. Create Image

1.1. Prepare Docker Env

Share a directory between your local machine and Docker host machine (if your are using Docker Toolbox for Windows).

Docker machine create shared folder

For my case I have shared the folder c:/Users.

Copy the Hybris Commerce Suite zipped inside the shared directory.

Hybris commerce suite zip docker shared folder

I’m using the version 5.7.0.0 of Hybris, but you can use any version of Hybris you want.

1.2. Create Dockerfile

Dockerfile is a sample text file that contains a series of command lines to be run in order to create a Docker image.

Inside the shared directory, create a file called Dockerfile and put this script in it.

# Create image from primetoninc/jdk:1.8
FROM primetoninc/jdk:1.8

# Author signature
MAINTAINER mouad.elfakir@gmail.com

# Copy hybris.zip inside the Container
COPY hybris.zip /src/hybris.zip

# Navigate to /src directory
WORKDIR /src

# Unzip hybris.zip
RUN unzip hybris.zip

# navigate to the platform directory
WORKDIR /src/hybris/bin/platform/

# Add exec permission to .sh files
RUN find ./ -type f -iname "*.sh" -exec chmod +x {} \;

# Expose http port
EXPOSE 9001

# Expose https port
EXPOSE 9002

# Expose Debug port
EXPOSE 8000

# Run ant clean all (also ant initialize if it's needed)
RUN . ./setantenv.sh && ant clean all

# Run Hybris server
CMD ["./hybrisserver.sh"]

2. Build Image

To build the image, open Docker Quickstart Terminal, navigate to the shared folder and run Docker build command.

# Navigate to the shared folder
cd /c/Users/10053174/hybris-image

# Build the image from Dockerfile
docker build -t mouadelfakir/hybris:5.7.0.0 .

mouadelfakir is my Docker Hub account ID, hybris is the name of the image and 5.7.0.0 is the image version.

3. Run Image

To run Hybris image in normal mode use this command line.

docker run -it -p 9001:9001 -p 9002:9002 mouadelfakir/hybris:5.7.0.0

To run Hybris image in debug mode use this command line.

docker run -it -p 9001:9001 -p 9002:9002 -p 8000:8000 mouadelfakir/hybris:5.7.0.0 ./hybrisserver.sh debug

If everything goes well, you should be able to access HAC from your browser.

Open hac of Hybris running inside Docker container

4. Publish Image

1. Go to Docker Hub and create a Docker Hub account.

Docker hub create account
2. List all Docker images, using docker ls command.

docker image ls

REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
mouadelfakir/hybris   5.7.0.0             ea165872b62a        32 minutes ago      5.6GB

3. Tag your Docker image with a name, using docker tag command.

docker tag ea165872b62a mouadelfakir/hybris:5.7.0.0

4. Login to Docker Hub, using your account ID and password.

docker login --username=mouadelfakir

5. Push the image to Docker Hub, using docker push command.

docker push mouadelfakir/hybris:5.7.0.0

Change mouadelfakir with your Docker hub account ID, in all previous command lines.

Find the Dockerfile of this example on GitHub.

5. ToDo

Some small improvements still needs to Make :

  • Optimize the Dockerfile to prevent creating lots of layers.
  • Bind hybris/bin/custom folder to an external directory using -v flag.
  • Use an Apache Solr image to run Solr on another container and attach it to our image using Docker link.
  • Use a MySQL image to run MySQL on another container and attach it to our image using Docker link.
  • For security seek add and run the image using a non root user using USER command.

 

14
Leave a Reply

avatar
2 Comment threads
12 Thread replies
3 Followers
 
Most reacted comment
Hottest comment thread
4 Comment authors
RockVishalMouad EL Fakircaner Recent comment authors

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
newest oldest most voted
Notify of
caner
Guest
caner

any installation of ant jdk maven and localproperties setting?

Vishal
Guest
Vishal

hi,
I am new to hybris & docker. Can you help me downloading hybris version which you mentioned as hybris.zip.
I have already installed docker on mac and using kitematic to look for containers. the only file missing is hybris.zip and i do not have any clue from where to download and run store front accelerator on my local system.

I am oracle commerce developer (ATG) trying to learn hybris. it would be of great help if you can guide me.

Thanks

Rock
Guest

Hi
I am trying this for windows 10, and when i am trying to unzip the hyrbis.zip then it is saying unzip is unrecognized commands
# Unzip hybris.zip
RUN unzip hybris.zip
I have winrar and zip extractor.