How to build docker image

Viewed 26

I'am trying to build a docker image from my java-jar. Unfortunatly, this seems to be much harder without intellij (where you just have the option: create Image). So I installed an extra docker-app npm. In this docker-app I put the jar from which I want to build the image. screenshot of my filesystem:

enter image description here

Also I made Dockerfile using touch. I have tried to put many differents things in the Dockerfile, but I never manage to create an image, without my container exiting after launch. My current Dockerfile holds:

FROM openjdk:17-alpine
COPY autotimesheets-0.0.1-SNAPSHOT.jar \autotimesheets.jar
RUN npm install
EXPOSE 3000
CMD [""npm", "start""]

The problem is with RUN npm install. When I don't use it, the container exits immediatly after start. If I use it, the build fails. Error code:

C:\Users\HI10\docker-app>docker build .
[+] Building 2.0s (8/8) FINISHED
 => [internal] load build definition from Dockerfile                                                               0.0s
 => => transferring dockerfile: 175B                                                                               0.0s
 => [internal] load .dockerignore                                                                                  0.0s
 => => transferring context: 2B                                                                                    0.0s
 => [internal] load metadata for docker.io/library/openjdk:17-alpine                                               1.7s
 => [auth] library/openjdk:pull token for registry-1.docker.io                                                     0.0s
 => [internal] load build context                                                                                  0.0s
 => => transferring context: 57B                                                                                   0.0s
 => [1/3] FROM docker.io/library/openjdk:17-alpine@sha256:4b6abae565492dbe9e7a894137c966a7485154238902f2f25e9dbd9  0.0s
 => CACHED [2/3] COPY autotimesheets-0.0.1-SNAPSHOT.jar autotimesheets.jar                                         0.0s
 => ERROR [3/3] RUN npm install                                                                                    0.3s
------
 > [3/3] RUN npm install:
#7 0.254 /bin/sh: npm: not found
------
executor failed running [/bin/sh -c npm install]: exit code: 127

I tried to adjust this RUN command with a lot of things, following tons of online documents and earlier questions. Also I tried to reinstall etc.. I don't seem to get it done. Can anyone please explain me how I should build the image from this jar? I use eclipse for IDE, if there is a way to do it with eclipse, It is as good as an answer. Here below, the lists of stack topics I visited today, but I cannot find an answer:

enter image description here

All ideas & tips are welcome.

1 Answers

As mentioned in the comment npm is for javascript.

Try running it with java instead.

And with RUN you start something when you build your docker image, you want to use CMD or ENTRYPOINT.

FROM openjdk:17-alpine
COPY autotimesheets-0.0.1-SNAPSHOT.jar app.jar

ENTRYPOINT ["java", "-jar", "app.jar"]
Related