Docker Swarm container orchestration to be built in to Docker 1.12

After spending some time over the past few days getting up to speed with Docker Compose, one of the major announcements at DockerCon this week so far is that the Compose functionality is to be integrated into the core Docker Engine (rather than being a separate feature as it has been up until now).

If you missed my most recent getting up to speed with Docker posts, here’s a quick recap:

docker-compose.yml for 1x MongoDB container plus 1x data volume container

I’m starting to dabble with docker-compose to link up some container goodness. If you’ve followed my other Docker related posts the past couple of days (here), then you might have noticed that I have something Raspberry Pi related cooking 🙂

Although I’ll have to redo these with a Pi compatible base images, to get MongoDB running in one container with a separate data volume container is actually pretty simple. Here’s what I ended up with. To start it up, ‘docker-compose up -d’ and you’re up and running (copy this to docker-compose.yml):

mongodata: 
 image: mongo:3.2
 volumes:
 - /data/db
 entrypoint: /bin/bash
mongo: 
 image: mongo:3.2
 volumes_from:
 - mongodata
 ports:
 - "27017:27017"

Spring Boot REST app in a Docker Container on the Raspberry Pi

Docker on the Raspberry Pi? Sure, with help from Hypriot who provide an iso image ready to go, getting docker up and running on the Pi is as simple as burning their image to an sd card and booting it up. Ok, so that part is simple.

Building an image to run on the Pi is not as straightforward as it sounds. Well, it’s no more complicated than building an image from a Dockerfile, but given that the Pi is ARM based and not x86, you have to build an image that is built/compiled with executables/libraries for ARM.

This makes complete sense when you think about it, you’re not going to get an image containing x86 executables and libraries to run on a Pi, but it’s rather sad that it isn’t possible to build an image for example from my Mac and and I can run on my Mac, or Linux, or on the Pi. Well, you can build the image on any architecture, but you can’t run an ARM compatible image on the Mac (or docker-machine/boot2docker).

Ok, so that in mind, there are a number of ARM compatible images on Docker Hub already – Hypriot also have base images ready to go. So to run Spring Boot in a container on the Pi, I need an ARM image with Java. Luckily, here’s one ready to go.

For a quick test, I took my simple Sprig Boot REST app I already have on GitHub, and threw together a Dockerfile using Alpine first to check it would run locally:

FROM java:openjdk-8-alpine

ADD SpringBootREST-0.0.1-SNAPSHOT.jar /opt/SpringBootREST-0.0.1-SNAPSHOT.jar

EXPOSE 8080

ENTRYPOINT ["java", "-jar", "/opt/SpringBootREST-0.0.1-SNAPSHOT.jar"]

This runs as expected in docker-machine on my Mac.

To push to the Pi, the only change is to replace the base image with an ARM compatible image with Java, so this looks like:

FROM hypriot/rpi-java

ADD SpringBootREST-0.0.1-SNAPSHOT.jar /opt/SpringBootREST-0.0.1-SNAPSHOT.jar

EXPOSE 8080

ENTRYPOINT ["java", "-jar", "/opt/SpringBootREST-0.0.1-SNAPSHOT.jar"]

To get it to my Pi, I set up a local Registry to push the image to, and then pulled it from the Pi. So tag the image to the registry:

docker tag spring-boot-rest-rpi registry-ip:5000/spring-boot-rest-rpi

…push to the registry:

docker push registry-ip:5000/spring-boot-rest-rpi

and then pull from the Pi:

docker pull registry-ip:5000/spring-boot-rest-rpi

And then fire it up!

docker run -it -p 8080:8080 registry-ip:5000/spring-boot-rest-rpi

Spring Boot in a Docker Container on the Pi!