Issue
I need to build a Docker container (feeling as a N00b about it) that runs a Java application fronted by an nginx Web server. For reasons not subject to discussion I need to put them into one container.
I'd like to use Alpine for that. I found both images that contain Alpine with an installed nginx and Alpine with an installed JDK. I need to combine both.
What's my best course of action? Start with the nginx container and add a jdk or start with the jdk containing container and add nginx?
Or is there an option to combine 2 images (and would that be a good idea).
Insights are appreciated.
Solution
For creating a combined image, you could follow either of the suggested paths:
- Creating a merged
Dockerfilewith the setup steps for both images, and building your own custom image. - Creating a
Dockerfilepulling from image 1 (the more "complex" one), and adding the commands needed for image 2.
The second approach is preferred, since you start off a known-good image, not having to start from scrach. Plus, you may need only minimal changes. For this to work, both images should share a common base image, such as alpine for example.
Examining both Nginx and Java OpenJDK Dockerfiles, you could see that Nginx Dockerfile is fairly more complex, with many prerequisite packages and setup steps, so it would make a better fit for the base image. My suggestion is, start from the Nginx base image, and add Java on top.
If you're happy with the versions of JDK available in Alpile repositories, your combined Dockerfile may be as simple as:
FROM nginx:alpine
RUN apk add openjdk17
If you need a specific Java version, which isn't available in Alpine repositories, it's usually a matter of downloading the zipped Alpine Java distribution and unpacking it and setting JAVA_HOME accordingly. For example, see the OpenJDK 13 Alpine Dockerfile.
Answered By - valiano
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.