LukaszH
LukaszH

Reputation: 161

How to check Java version of the Docker container?

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.

Upvotes: 7

Views: 46542

Answers (4)

取一个好的名字
取一个好的名字

Reputation: 1823

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

Upvotes: 3

herm
herm

Reputation: 16315

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.

Upvotes: 20

kuskmen
kuskmen

Reputation: 3775

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/

Upvotes: 8

atline
atline

Reputation: 31584

docker exec container_name java -version

Upvotes: 4

Related Questions