7

I'm using containers built from external images provided by a coworker. The whole application is a testing instance of a production environment. I need to know which version of Java is running inside a container. I assume that is something like:

docker container_name java -version

But this is not a proper command. I will be grateful for your help and advice how to check it.

0

4 Answers 4

20

What you can do:

Check the dockerfile of your coworker to see which base image he is relying on. The base image tag usually describes the version.

Another approach is to docker exec containerId java -version.

8

You need to execute your command sort of "remotely" imagine you have another subsystem on your host OS.

To do this you can do

docker exec container_name java -version - from the documentation of docker

docker exec - run a command in a running container.

Or you can simply execute bash if your container is Linux and execute more commands if you like

docker exec -it container_name bash

again from the documentation:

--tty , -t - Allocate a pseudo-TTY

--interactive , -i Keep STDIN open even if not attached

Resources: https://docs.docker.com/engine/reference/commandline/exec/

4
docker exec container_name java -version
3

show java version

[root@localhost docker-java]# docker images
REPOSITORY                        TAG                 IMAGE ID            CREATED             SIZE
openjdk                           8                   09df0563bdfc        10 days ago         488MB 
python                            latest              0a3a95c81a2b        10 days ago         932MB

[root@localhost docker-java]# docker run -it --rm openjdk:8 bash
root@a51edd412d60:/# java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)
root@a51edd412d60:/# exit
exit

show python version

[root@localhost docker-java]# docker run -it --rm python:latest bash
 root@1e645b65683b:/# python -V
 Python 3.8.0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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