I have a microservice that is called account.query. When I try to up services by using docker compose up command, account.query is getting an error.
I have also a microservice that is called account.cmd, but it is not getting an error.
I have been trying to solve this problem for hours, but I could not.
Here is Docker file my account.query microservice.
FROM adoptopenjdk:11.0.4_11-jre-hotspot
EXPOSE 5003
RUN mkdir -p /usr/app
WORKDIR /usr/app
COPY build/libs/account.query-0.0.1-SNAPSHOT.jar /usr/app/
ENV JAVA_OPTS="-Xmx32m"
CMD exec java $JAVA_OPTS -jar account.query-0.0.1-SNAPSHOT.jar
Here is Docker logs for the service.
Here is my github repository.
https://github.com/dogaanismail/bank-solution
I would be very happy if someone could help.
Related
as far as I know I only got this answer for my query, but unfortunately I do not have docker-compose.yml I am just trying with plain Dockerfile below is my dockerFile.
FROM openjdk:8-jre-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} ebiPorjectJava.jar
ENTRYPOINT ["java","-jar","/ebiProjectJava.jar"]
but build is getting successful, by below command.
docker build -t ebiproject .
but when I am trying to run the docker it says unable to access jar file
docker run -p 3000:3000 ebiproejct
but it says unable to access jar
I am running docker on windows and I have spring boot application to run
I updated with below one:
FROM openjdk:8-jre-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} /ebiProjectJava.jar
ENTRYPOINT ["java","-jar","/ebiProjectJava.jar"]
but now I am getting corrupted error:
ARG JAR_FILE
expects you to pass the path of the jar_file as docker run argument
Otherwise nothing will be copied to the place, thus java jar won't be able to run the jar.
Check this out: https://vsupalov.com/docker-env-vars/
In this situation you can go in your container with this command:
docker run --rm -it <container_name> <image_name> <command>
you can use bash, ash or sh as
and after entering the container, you can check, run, or any tests in that.
I am trying to dockerize a full-stack Java(Springboot)-Angular app. The Angular app is embedded in the application and makes REST calls to the Java app as GET localhost:8080/getSomeInfo. My Dockerfile is as
FROM maven:3.6.3-openjdk-8 AS build
COPY src /home/app/src
COPY pom.xml /home/app
RUN mvn -f /home/app/pom.xml clean package
FROM openjdk:8-jdk-alpine
COPY --from=build /home/app/target/*.jar /usr/local/lib/app.jar
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} /usr/local/lib/app.jar
ENTRYPOINT ["java","-jar","/usr/local/lib/app.jar"]
FROM node:12.2.0
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY src/main/web/package.json /app/package.json
RUN npm install
RUN npm install -g #angular/cli#10.1.2
COPY src/main/web /app
CMD ng serve --host 0.0.0.0
I build it as
docker build -t springio/myapp .
I need to expose both the angular port and the java port, so I run it as
docker run -p 9898:4200 -p 8080:8080 -t springio/myapp
I am able to bring up the web page, but it cannot reach out to the Java server (can't connect to 8080). How can this be fixed please?
I have tried putting 'EXPOSE 8080' in the dockerfile, but that did not work
You should not put 2 applications in the same container. Although you can, it is considered a bad practise and it defeats the purpose of using containers.
I suggest having 2 Dockerfile: one for the back-end (java app) and one for the front-end (Angular app). Build each of them separately and start them independently.
For your specific problem I don't think the port is the problem, but is the Java app that is not even starting (it is actually not even present in the final image). Splitting the Dockerfile and starting the apps separately will fix your issue.
EXPOSE doesn't actually do anything. It is there to inform users of the Dockerfile which ports the application is listening on, so that they know which ports to map on the host.
Build docker images using docker file for maven project
When try running docker run getting error saying Unable to access jarfile.
Can some one assist on whats wrong with .
FROM openjdk:8-jre-alpine as release
RUN addgroup -g 1001 -S user1 && user1 -u 1001 -S user1 -G user1
WORKDIR /home/app
COPY --from=builder /home/app/service-1.0.0.jar .
RUN chown -R user1:user1 /home/app
USER user1
ENTRYPOINT ["java", "-jar" ,"/home/app/service-1.0.0.jar"]
but when i go for docker run with local config files as build mount
docker run -it --mount type=bind,source=D:/Java/service/docker/config,target=/home/app services
Unable to access jarfile /home/app/service-1.0.0.jar
Can someone assist on this or is something wrong i did??
I am not sure if you are looking for multistage docker build. If not, you need not use "COPY --from=builder" as it tires to copy the build artifact from your previous stage to this new stage. If it is a single stage docker build, you might just use the copy as follows -
COPY /home/app/service-1.0.0.jar .
Able to resolve the same, Issue was due to mound of config files not happened properly.
instead of docker run -it --mount type=bind,source=D:/Java/service/docker/config,target=/home/app services changes it to docker run -it --mount type=bind,source=D:/Java/service/docker/config/app.config,target=/home/app services which made service to load and work
This is my docker file
FROM openjdk:8-jre-slim
RUN mkdir /app
COPY dept-1.0.jar /app
CMD java -jar /app/dept-1.0.jar
EXPOSE 8080
The docker image can be run without any issues if I were to run like without port-forward
docker run --name=department dept:latest
But with port-forward docker run --name=department dept:latest -p 8082:8080 I see this error -
docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"-p\": executable file not found in $PATH": unknown.
Can someone help pls ?
I changed the following in the Dockerfil
CMD java -jar /app/dept-1.0.jar
to
ENTRYPOINT ["java", "-jar", "/app/dept-1.0.jar"]
This solved my issue.
Please note: I know this questions is very similar to this one however you'll note that the solution in that case was to EXPOSE the port, which I am already doing. Hence although this questions sounds similar, I think its simply a different problem altogether with similar symptoms as the other question.
Docker Version 17.12.0-ce-mac49 (21995) here. I am experimenting with Docker for the first time and have built my first Docker image. My Dockerfile is:
FROM openjdk:8
RUN mkdir /opt/myapp
ADD build/libs/myapp.jar /opt/myapp
ADD application.yml /opt/myapp
ADD logback.groovy /opt/myapp
WORKDIR /opt/myapp
EXPOSE 9200
ENTRYPOINT java -Dspring.config=. -jar myapp.jar
I build it via:
docker build -t myapp .
Everything succeeds. I then tag it as if I'm going to push it to Quay:
docker tag <imageId> quay.io/myregistry/myapp:0.1.0-SNAPSHOT
However before I publish to Quay I want to run it locally to make sure it works:
docker run -it -p 9200:9200 -d --env-file /Users/myuser/myapp-local.env --name myapp myapp
When I run this I get an indication that the container is running, and I can even see it for a few seconds via docker ps:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f3fa8f7a4288 myapp "/bin/sh -c 'java -D…" Less than a second ago Up 7 seconds 0.0.0.0:9200->9200/tcp myapp
However after a few seconds it stops running and disappears from docker ps altogether:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Furthermore I'm not able to SSH into the container:
docker exec -it f3fa8f7a4288 bash
Error: No such container: f3fa8f7a4288
...or see any logs/console output.
When I run myapp.jar outside of Docker (as a typical Spring Boot app, it starts up and runs beautifully without exceptions). How can I troubleshoot what is going on?
The docker logs command will show you the output a container is generating when you run it detached (with -d). This is likely to include the error message.
docker logs --tail 50 --follow --timestamps container
You can run the image in the foreground without the -d to see the output like when you run myapp.jar outside of Docker.
docker run my/image
So in this specific case:
docker run -it -p 9200:9200 --env-file /Users/myuser/myapp-local.env --name myapp myapp
If I am not mistaken, the issue you are experiencing is because you are using the shell form of ENTRYPOINT. Change it to use the exec version, as follows:
ENTRYPOINT ["java", "-Dspring.config=.", "-jar", "myapp.jar"]
The shell form will launch Java as a separate process just like a shell command. This causes PID 1 to return making Docker believe the container is finished. Using the exec form, the Java process replaces PID 1 and the container will continue running.