0

I'm following instructions from this site about building a spring-boot docker container. They are using CentOS.

In their dockerfile, they call the alternative command several times. I would like to understand the purpose of these statements.

note: run is a docker command. I am interested in the alternative command passed to run

RUN alternatives --install /usr/bin/java jar /usr/java/latest/bin/java 200000
RUN alternatives --install /usr/bin/javaws javaws /usr/java/latest/bin/javaws 200000
RUN alternatives --install /usr/bin/javac javac /usr/java/latest/bin/javac 200000

From what I can tell they are modifying symbolic links. Is that correct and, more importantly, why?

Thnx

Matt

5

You may have a need to keep multiple versions of an executable (like java) on your system. Perhaps most of your system will work with Java 8, but one application needs Java 7.

The alternatives program lets you switch from one version to another, quickly.

EDIT: For other reasons you may want to do this, see What is the difference between JAVA_HOME and update-alternatives? and Better way to add alternative using update-alternatives?

From man alternatives:

It is possible for several programs fulfilling the same or similar functions to be installed on a single system at the same time. For example, many systems have several text editors installed at once. This gives choice to the users of a system, allowing each to use a different editor, if desired, but makes it difficult for a program to make a good choice of editor to invoke if the user has not specified a particular preference.

The alternatives system aims to solve this problem. A generic name in the filesystem is shared by all files providing interchangeable functionality. The alternatives system and the system administrator together determine which actual file is referenced by this generic name.


  • So that makes sense if I was running the OS interactively, I guess. Why would that matter in a situation where the OS is running a docker file and only function is to run a spring-boot app? – tatmanblue Aug 11 '17 at 20:41
  • 1
    The deployment in question has no way to notice that you have pinky-promised to only ever use that host for that singular purpose. – DopeGhoti Aug 11 '17 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.