Create Your First Hybris Docker Image
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.
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).
For my case I have shared the folder c:/Users.
Copy the Hybris Commerce Suite zipped inside the shared directory.
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.
4. Publish Image
1. Go to Docker Hub and create a Docker Hub 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.
Software Craftsmanship, Stackextend author and Full Stack developer with 6+ years of experience in Java/Kotlin, Java EE, Angular and Hybris…
I’m Passionate about Microservice architectures, Hexagonal architecture, Event Driven architecture, Event Sourcing and Domain Driven design (DDD)…
Huge fan of Clean Code school, SOLID, GRASP principles, Design Patterns, TDD and BDD.
any installation of ant jdk maven and localproperties setting?
JDK : comes bundled with the
primetoninc/jdk:1.8
Ant : comes with Hybris too, you need just to use
./setantenv.sh
Maven : i don’t think you need Maven for this!
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 🙁
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
Make sure by calling
WORKDIR /src/hybris/bin/platform/
you are navigating to the right folder.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
points to attention to :
1. share a folder between your host machine (windows) and docker machine.
2. put hybris.zip and Dockerfile inside the shared folder.
3. hook into the docker machine, navigate to the shared folder and run the command
build -t mouadelfakir/hybris:5.7.0.0 .
4. the hybris.zip should have the following structure :
hybris
|__bin
| |__platform
| |__...
|__config
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.
From the log I see that the zip file is being unzipped and copied successfully (note that the zip file will be unzipped and copied to the docker image not inside your host machine “ubuntu”).
The only problem you have is with :
RUN . ./setantenv.sh && ant clean all
You can run the last successfully created docker image and see what’s going on!
From your log lines I see that the last created docker image is c5c5f4695a5d in step 10/12 so you can run it using :
docker run -it c5c5f4695a5d /bin/bash
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.
The hybris.zip file will be copied and unzipped inside the /src folder of the created docker image not inside your host machine (ubuntu) hence you will not be able to explore the /src unless you run the created image!
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
Unfortunately, Hybris is a closed product. you can download Hybris only if you are an SAP partner.
https://support.sap.com/en/my-support/software-downloads.html
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.
I need hybris 20.x zip file. Where will I get it