Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install package manager in java based docker image

I am developing an application using SpringBoot and Java with Docker.

I want to install Netcat in my application so that I can check if a specific container is up before my spring application starts.

I have tried

RUN apt-get update && apt-get -y install netcat && apt-get clean

But it says apt-get is not found.

I am not sure how can I install any package manager in my java based application.

Or is there any other I can get net-cat installed.

Below is my Dockerfile

FROM openjdk:8
RUN apt-get update && apt-get -y install netcat && apt-get clean
ADD target/student.jar student.jar
EXPOSE 2018
ENTRYPOINT ["java","-jar","student.jar"]
like image 585
Mehraj Malik Avatar asked Sep 08 '25 07:09

Mehraj Malik


1 Answers

apt-get is package manager for Debian-based Linux distros (including Ubuntu and others).

Try apk add instead.

Also, if you are using package managers in your Dockerfile, it is considered a good practice to explicitly specify Linux distro. In your case you can use openjdk:8-jdk-stretch variant or any other, where distro is specified.

like image 143
grapes Avatar answered Sep 10 '25 08:09

grapes