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 [email protected]

# 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.

 

0 0 votes
Article Rating
Subscribe
Notify of
guest

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

15 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
caner
caner
6 years ago

any installation of ant jdk maven and localproperties setting?

caner
caner
Reply to  Mouad EL Fakir
6 years ago

You put also hybris/config localproperties and localextensions?

i want to put my hybris project (which is same as electronic store but changed a little)into a docker image. I should put root folder of hybris as hybris.zip you mentioned? this will also put autogenerated and other config classes 🙁

caner
caner
Reply to  Mouad EL Fakir
6 years ago

it says

/bin/sh: ./setantenv.sh: No such file or directory
The command ‘/bin/sh -c . ./setantenv.sh && ant clean all’ returned a non-zero code: 1

caner
caner
Reply to  Mouad EL Fakir
6 years ago

Step 6/12 : WORKDIR /src/hybris/bin/platform/
—> Using cache
—> 9ac4685b3d0a
Step 7/12 : RUN find ./ -type f -iname “*.sh” -exec chmod +x {} \;
—> Using cache
—> 091a5ed5ccd1
Step 8/12 : EXPOSE 9001
—> Using cache
—> a4f68a686856
Step 9/12 : EXPOSE 9002
—> Using cache
—> 5eacf875daa6
Step 10/12 : EXPOSE 8000
—> Using cache
—> c5c5f4695a5d
Step 11/12 : RUN . ./setantenv.sh && ant clean all
—> Running in 78fedf4e3db8
/bin/sh: ./setantenv.sh: No such file or directory
The command ‘/bin/sh -c . ./setantenv.sh && ant clean all’ returned a non-zero code: 1

caner
caner
Reply to  Mouad EL Fakir
6 years ago

i am on ubuntu. no need to share.hybris.zip has that structure but it cant zip. even it cant copy to src. even it cant create src folder. if i create , it cant copy.

caner
caner
Reply to  Mouad EL Fakir
6 years ago

but i follow the folder while the code is working. It does not create src folder or it does not copy or it does not unzip. Log says othervise yes but i saw.

Vishal
Vishal
Reply to  caner
6 years ago

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
6 years ago

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.

Sijo
Sijo
2 years ago

I need hybris 20.x zip file. Where will I get it

15
0
Would love your thoughts, please comment.x
()
x