Drumbeg
Drumbeg

Reputation: 1934

Allowing a host application to access a Java SDK installed in a Docker container

I want to install an application that requires a Java SDK to be installed, but I don't want to install Java on my computer. Instead I would like to install Java to a Docker container and allow apps on my host machine to use it.

Is this possible?

Upvotes: 0

Views: 223

Answers (1)

David Maze
David Maze

Reputation: 158705

Docker doesn’t really work that way. It’s best for packaged complete applications that you can access via a network connection; in the Java case, a JRE plus an app server plus an installed application would make a reasonable complete image.

It’s possible to share files between the host and a container, but mostly that direction is “push things into a container”. In your example you could use the docker run -v option to push your source directory into the container, but you’d have to actually run the JDK commands (javac, mvn, ...) from inside the container. You can use docker exec to do this, but it’s an unnatural workflow IMHO, and it requires you to have administrator-level privileges to do even routine things.

I’d put the JDK and the application in the same place: either bundle both into a single Docker image, or install the JDK on your host.

Upvotes: 1

Related Questions