running DockerFile of spring app is not working on windows - spring-boot

This is my Dockerfile
FROM openjdk:8-jdk-alpine
ARG JAR_FILES=target/*.jar
COPY ${JAR_FILES} app.jar
EXPOSE 9099
ENTRYPOINT ["java","-jar","/app.jar"]
when running the commande docker build . inside the directoery of the project i got this error :

Could be due to insufficient space (refer : https://forums.docker.com/t/error-read-only-file-system-write-var-lib-docker-buildkit-metadata-v2-db/103637)
Might be Dockerfile name issue (Dockerfile not dockerfile)

Related

Docker volume - windows host and linux container

I have this very simple Dockerfile :
FROM node:current-alpine3.14 AS baseImage
WORKDIR /app
COPY package* .
RUN npm install
COPY . .
CMD ["npm", "run", "watch"]
Then I run :
docker build . -t myImage
And then docker run -p 8080:3000 -v /c/myFolder:/app myImage
So basically I want a "shared" between the app folder in the container and the C:\myFolder on my host.
But it doesn't work :
For instance, if I update C:\myFolder\index.js, the changes doesnt occur in the container.
And here is what docker inspect myContainer returns under the Mounts section.
Is it something to do with escaping / path format? Or am I missing something fundamental in working with volume ? or WORKDIR ?
Mounts :
The Mounts seems to consider "Program Files/Git/app" the destination / container folder but it should simply be "/app"
Binds:
the command
docker run -p 8080:3000 -v /c/myFolder:/app myImage
was run with gitbash for windows
Running the exact same command with CMD solved my issue.
it looks like GitBash was converting the /app destination folder into \Program Files\Git\app

How to execute gradle build before the Docker build on Heroku?

I want to deploy a dockerized Spring-Boot application built with gradle on the Heroku platform when a commit is pushed on github.
I deployed successfully the docker image with CLI, by building the image locally and then deploying it
I deployed successfully "on github push" with the "heroku-18" stack. After each commit, Heroku detects that my project is a gradle one, build it and deploys it with no problem. This method doesn't trigger Docker.
Now, I want to switch to the "container" stack, for Heroku to build my Dockerfile and deploys my app after each commit. The Dockerfile is correctly detected, but because the JAR is not generated, the Dockerfile step fails.
How can I trigger the generation of the JAR on Heroku side for the Dockerfile to be able to copy this JAR to the container ?
Heroku logs
=== Fetching app code
=== Building web (Dockerfile)
Sending build context to Docker daemon 50.69kBStep 1/11 : FROM openjdk:11-jre-slim
11-jre-slim: Pulling from library/openjdk
...
Step 4/11 : ADD build/libs/myapp-1.0-SNAPSHOT.jar /app/myapp.jar
ADD failed: stat /var/lib/docker/tmp/docker-builder545575378/build/libs/myapp-1.0-SNAPSHOT.jar: no such file or directory
heroku.yml
build:
docker:
web: Dockerfile
Dockerfile
FROM openjdk:11-jre-slim
VOLUME /var/log/my-app
ARG JAR_FILE
ADD build/libs/my-app-1.0-SNAPSHOT.jar /app/my-app.jar
RUN chgrp -R 0 /app
RUN chmod -R g+rwX /app
RUN chgrp -R 0 /var/log/my-app
RUN chmod -R g+rwX /var/log/my-app
CMD [ "-jar", "/app/my-app.jar" ]
ENTRYPOINT ["java"]
EXPOSE 8080
Probably you can't do that outside your Dockerfile.
But you can use Docker multi-stage builds like this:
FROM adoptopenjdk/openjdk14-openj9:alpine as build
COPY . /opt/app/src
WORKDIR /opt/app/src
RUN ./gradlew clean bootJar
FROM adoptopenjdk/openjdk14-openj9:alpine-jre
COPY --from=build opt/app/app.jar /opt/app/app.jar
CMD ["java", "-server", "-XX:MaxRAM=256m", "-jar", "/opt/app/app.jar"]

COPY target/test-0.0.1-SNAPSHOT.jar /test.jar COPY failed cannot find file Docker

I'm trying Docker for the first time in a Spring Boot project and I'm trying to make the command docker build -t javademo:v1.3 . work. I don't know where the jar file is, in the Dockerfile I've specified this:
FROM openjdk:8-windowsservercore
LABEL maintainer="Marina"
COPY target/test-0.0.1-SNAPSHOT.jar /test.jar
EXPOSE 8080:8080
CMD ["java", "-jar", "test.jar"]
Because my project name is "test". The problem is that I can't find the test.jar, even if I Maven-build the project. How is this supposed to work? What am I missing?

Error in running Spring-Boot Application on Docker

I tried to run my simple Spring Web application jar on docker but I always get the following error. ubuntu & openjdk images exist and their state is UP. I could not run my jar file on docker? How can I get rid of this error?
ubuntu#ip-172-31-16-5:~/jar$ **docker run -d -p 8080:8080 spring-docker tail -f /dev/null**
c8eb92e5315adbaccfd894ed9e74b8e0d0eed88a81eaa07037cf8ada133c81fd
docker: **Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"java\": executable file not found in $PATH": unknown.**
Related DockerFile:
FROM ubuntu
FROM openjdk
VOLUME /tmp
ADD /spring-boot-web-0.0.1-SNAPSHOT.jar myapp.jar
RUN sh -c 'touch /myapp.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/myapp.jar"]
Check with below sequence which works for me.
Build image using below command.
docker build -t demo-img .
DockerFile
FROM openjdk:8-jdk-alpine
VOLUME /tmp
COPY demo-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
then run like below.
docker run --name demo-container -d -p 8080:8080 demo-img
Make sure you are running all these command from the directory in which DockerFile and jar is present.

passing command line parameters to spring boot services inside docker container

I have got a set of spring boot apps that I would like to package as docker containers.
I am using the following Dockerfile to create the container for one of the services:
FROM java:8
VOLUME /tmp
ADD myservice.jar app.jar
RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
Inside, the services access some environment properties like for instance:
#Value("${my.test.param:default}")
String testParam;
.
.
.
logger.info("param value is = "+testParam);
Now, I would like to be able to override this setting via docker run command line like this
docker run -p 8080:8080 -e my.test.param=changed mygroup/myservice:0.0.1
Unfortunately, this doesn't seem to work. I keep seeing the default value for the parameter my.test.param.
I searched for ways to automatically add all -e parameters at the end of the ENTRYPOINT line, but didn't find any. Is there some general solution for this?

Resources