1

The use case is such that I need both JDK and Mongo images in a single container, the java process starts up the Mongo daemon process.

Devesh Lohumi
  • 362
  • 2
  • 15
  • It's unusual to actually need to two separate processes in a single container like that; standard practice is to run your application and database in two separate containers, maybe orchestrated with Docker Compose. More broadly, no, it's not possible to combine two images. – David Maze Mar 11 '22 at 10:57

2 Answers2

2

You are not needed to use two base images. just use one of the base image jdk/mongo and then using binaries install mongo/jdk on top of the chosen base image.

P Ekambaram
  • 15,499
  • 7
  • 34
  • 59
2

Here's the minimum Dockerfile that bake JRE 11 to the mongo image.

FROM mongo:latest

# Replace the version if desired
RUN apt-get update -y && apt-get install openjdk-11-jre-headless -y

# Install your app and stuffs here...

# Override for your own command
CMD ["java","-version"]

Build the image docker build -t mongodb-java .

Test the image docker run -t --rm mongodb-java will output the JRE version.

Test the image docker run -t --rm mongodb-java mongo --version will output the MongoDB version.

You can then follow Kaniko steps to build the image.

gohm'c
  • 13,492
  • 1
  • 9
  • 16