Skip to content

Latest commit

 

History

History
73 lines (50 loc) · 4.09 KB

2020-02-05-docker-open-liberty-raspberry-pi.adoc

File metadata and controls

73 lines (50 loc) · 4.09 KB
layout title categories author_picture author_github blog_description seo-title seo-description
post
Open Liberty in Docker on Raspberry Pi
blog
Open Liberty is small and lightweight so it was never a problem to fit it on the original Raspberry Pi back in 2012. I set off on a mission to see how easy it is to get a Raspberry Pi-compatible Docker image of Open Liberty.
Open Liberty in Docker on Raspberry Pi
Open Liberty is small and lightweight so it was never a problem to fit it on the original Raspberry Pi back in 2012. I set off on a mission to see how easy it is to get a Raspberry Pi-compatible Docker image of Open Liberty.

Open Liberty in Docker on a Raspberry Pi

Open Liberty is small and lightweight so it was never a problem to fit it on the original Raspberry Pi back in 2012. It is well known that they are useful pieces of technology with lots of potential so I set off on a mission to see how easy it is to get a Raspberry Pi-compatible Docker image of Open Liberty. I used a Raspberry Pi 3 for this demonstration.

The complication when moving to a Raspberry Pi is that it has an ARM CPU at its heart, meaning that machine code compiled for x86 or x86-64 CPUs (the standard CPUs you get in laptops/desktops today) won’t execute. Liberty is written in Java so it doesn’t have to worry about what the CPU architecture is: as long as there is a Java runtime it’s able to run (as the Java runtime itself interprets the Java code and executes it on the hardware). We do have official Open Liberty images on Docker Hub, but they are layered on top of the official IBM image, which is built on top of Ubuntu and doesn’t have a JVM that will run on ARM.

This means you can’t take our Open Liberty Docker image from Docker Hub, which is designed for an x86 architecture, and run it on the Pi without any configuration to the Docker images. We need to edit the Dockerfiles that define how to build the x86 Liberty Docker image and modify them to build an image for the ARM Raspberry Pi.

Creating the Open Liberty images

To start, clone the OpenLiberty/ci.docker repo and navigate to the required directory:

cd releases/latest/kernel

Edit the FROM target in the file, Dockerfile.ubi.adoptopenjdk11 to base the Open Liberty image on an OpenJDK image that is compatible with ARM. For example:

FROM arm32v7/adoptopenjdk:latest
...

You can now use this image as a base for your applications. Change the name of the file to Dockerfile and build the ARM Docker image by running the following command:

docker build -t openliberty/raspberrypi .

Take note of the name you have given to this image (e.g. openliberty/raspberrypi) so you can use it for future builds.

Run a sample application in the ARM image

Try out your image with a sample application. To begin:

git clone https://github.com/OpenLiberty/sample-getting-started cd sample-getting-started

Edit the FROM target in the Dockerfile so it uses your Open Liberty image as its base:

FROM openliberty/raspberrypi

LABEL maintainer="Graham Charters" vendor="IBM" github="https://github.com/WASdev/ci.maven"

COPY --chown=1001:0 src/main/liberty/config/ /config/
COPY --chown=1001:0 target/*.war /config/apps/

If Maven is not already installed on your Raspberry Pi, run the following command: sudo apt install maven

To build the application that is provided and deploy it to Open Liberty: mvn clean package liberty:run-server

When the server is ready, go to http://localhost:9080

You should see the sample application which uses a System Properties microservice to return the properties of the system you are running.

You have successfully built a Raspberry Pi-compatible Docker image of Open Liberty! Next, you can try building your own application image.