Error in running Spring-Boot Application on Docker - spring-boot

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.

Related

running DockerFile of spring app is not working on windows

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)

ERROR: failed to launch: determine start command: when there is no default process a command is required

After upgrading spring boot to 2.4 we cannot run the final docker image that we create via this script:
script:
- echo $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
- apk add openjdk11
- ./gradlew bootBuildImage --imageName=$DOCKER_IMAGE_INTERMEDIATE
- docker build -f ./docker/Dockerfile --build-arg base_image=$DOCKER_IMAGE_INTERMEDIATE -t $DOCKER_IMAGE_TAGGED .
- docker push $DOCKER_IMAGE_TAGGED
- docker tag $DOCKER_IMAGE_TAGGED $DOCKER_IMAGE_LATEST
- docker push $DOCKER_IMAGE_LATEST
our Dockerfile just creates a folder and chowns it to the CNB user:
# The base_image holds a reference to the image created by ./gradlew bootBuildImage
ARG base_image
FROM ${base_image}
ENV SOME_PATH /var/lib/some/files
USER root
RUN mkdir -p ${SOME_PATH}
RUN chown ${CNB_USER_ID}:${CNB_GROUP_ID} ${SOME_PATH}
USER ${CNB_USER_ID}:${CNB_GROUP_ID}
ENTRYPOINT /cnb/lifecycle/launcher
While this worked fine in spring boot 2.3, we now get this error after upgrading to spring boot 2.4 when trying to run the image:
ERROR: failed to launch: determine start command: when there is no default process a command is required
Edit:
The CI log output shows this line at the end of the bootBuildImage command:
[creator] Setting default process type 'web'
Edit2:
By further inspecting the differences of the images created by bootBuildImage with spring-boot 2.3 and 2.4 I found a hint that the default ENTRYPOINT no longer is /cnb/lifecycle/launcher but /cnb/process/web.
Updating the last line of our Dockerfile to select this entrypoint:
ENTRYPOINT /cnb/process/web
enables us to start the image! yay! :)
However, I leave the question open, because I still wonder why the default process is no longer used by the lifecycle launcher?!

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?

Permission issues with own built Docker container with Elasticsearch 2.1

When I pull an image from public elasticsearch repo, spawning container with that pulled image is working fine for me with no permission issues.
docker pull elasticsearch
docker run -d elasticsearch
But when I spawn a container with the Dockerfile which is available there with the public repo gives me permission issues. I do have a same directory structure as public repo.
myfolder/Dockerfile
myfolder/docker-entrypoint.sh
myfolder/config/elasticsearch.yml
myfolder/config/logging.yml
https://github.com/docker-library/elasticsearch/tree/0d393d9a0a2e24fca022a89ad10c7050b2925292/2.1
Commands:-
1) To build an image with the Dockerfile
sudo docker build -t testuser/testelastic:v1 .
2) Spawn container out of the built image
sudo docker run -d --name elastic -v ./config:/config testuser/testelastic:v1
But it gives me following error everytime when I tried to spawn any container out of the above custom build image.
Error response from daemon: Cannot start container 8e72f3c33d054f5883b2de9e7673bc032333e633e3f43905d7d22a12ea76ad04: [8] System error: exec: "/docker-entrypoint.sh": permission denied
chmod +x docker-entrypoint.sh
You need the script to be executable. Then build and run.

How to override the CMD command in the docker run line

How you can replace the cmd based on the docker documentation:
https://docs.docker.com/reference/builder/#cmd
You can override the CMD command
Dockerfile:
RUN chmod +x /srv/www/bin/* & chmod -R 755 /srv/www/app
RUN pip3 install -r /srv/www/app/pip-requirements.txt
EXPOSE 80
CMD ["/srv/www/bin/gunicorn.sh"]
the docker run command is:
docker run --name test test/test-backend
I tried
docker run --name test test --cmd ["/srv/www/bin/gunicorn.sh"]
docker run --name test test cmd ["/srv/www/bin/gunicorn.sh"]
But the console say this error:
System error: exec: "cmd": executable file not found in $PATH
The right way to do it is deleting cmd ["..."]
docker run --name test test/test-backend /srv/www/bin/gunicorn.sh
The Dockerfile uses CMD instruction which allows defaults for the container being executed.
The below line will execute the script /srv/www/bin/gunicorn.sh as its already provide in CMD instruction in your Dockerfile as a default value, which internally gets executed as /bin/sh -c /srv/www/bin/gunicorn.sh during runtime.
docker run --name test test/test-backend
Now say if you want to run some thing else, just add that at a end of the docker run. Now below line should run bash instead.
docker run --name test test/test-backend /bin/bash
Ref: Dockerfile Best Practices
For those using docker-compose:
docker-compose run [your-service-name-here-from-docker-compose.yml] /srv/www/bin/gunicorn.sh
In my case I'm reusing the same docker service to run the development and production builds of my react application:
docker-compose run my-react-app npm run build
Will run my webpack.config.production.js and build the application to the dist. But yes, to the original question, you can override the CMD in the CLI.
Try this in your Dockerfile
CMD ["sh" , "-c", "command && bash"]

Resources