Simple Docker image for a Node + Java environment.
As I continue to build on my Raspberry Pi Infrastructure, I need to create a Docker image that contains both Java and Node. Unfortunately, no such thing exist as an official image and I don’t like using images created by others due to security concern. So, I will have to do it myself and you can do it too.
The first step to create a docker image is to have a
Dockerfile . The content of the file tells docker what to do. Here is what it looks like:
RUN apt update && apt install -y openjdk-8-jdk
Dockerfile tells docker that our image should be based on
arm32v7/node:10.19.0 . On top of that, we use
apt to install JDK 8. There is nothing fancy except that you’d need to find the right architecture for your base. Although Raspberry Pi has a 64 bit CPU, the OS (Raspbian) is a 32 bit ARM OS.
To build and push this docker image to my private repo, I need to use a handful of commands. To reduce the amount of repeated typing and errors, I use a
Makefile to help me:
-docker rmi $(REPOSITORY):$(TAG)
-docker rmi $(REGISTRY)/$(REPOSITORY):$(TAG)
docker build . -t $(REPOSITORY):$(TAG)
docker tag $(REPOSITORY):$(TAG) $(REGISTRY)/$(REPOSITORY):$(TAG)
docker push $(REGISTRY)/$(REPOSITORY):$(TAG)
Notice that each line under the
default: label must begin with a TAB.
Running the above
Makefile would create the image and publish it to your private repo
If you are building this image on your Mac and your private repository is non-TLS, you will need to create a file
~/.docker/daemon.json with the following content:
That is it. Now, in your
Jenkinsfile , you can use the image in your
We have demonstrated how to create a Docker image for a Node + Java environment for Raspberry Pi. The Docker image is pushed to your private repository and can be pulled into your Jenkins build when needed.
Happy Programming. Enjoy!