H2 console not working on Docker (remote connections ('webAllowOthers') are disabled) - spring

I have an api application which works on port 8080 with h2 db and h2-console is working good when I run the application from the IDE.
I have dockerized the project with dockerfile and docker-compose.yml, the project is working without problem, everything seems fine except that I cannot reach the h2-console when I run the project from docker.
Am getting the error: "Sorry, remote connections ('webAllowOthers') are disabled on this server."
I checked some solutions and applied
spring.h2.console.settings.web-allow-others=true
to application-DOCKER.properties and also application.properties file but still cannot see the h2 console when I run the project on docker.
How can I solve this?

i had the same problem.
I found this answer after researching this problem.
Before starting jar in the Dockerfile, you can make it start by giving the following arguments. ("-web -webAllowOthers -tcp -tcpAllowOthers -browser")
My Dockerfile;
FROM openjdk:8-jdk-alpine
ADD target/*.jar app.jar
ENTRYPOINT ["java", "-jar", "/app.jar", "-web -webAllowOthers -tcp -tcpAllowOthers -browser"]
EXPOSE 8080
In this way, I hope there will be no problems.

Make sure to not have any spaces around comma:
Instead of : ENTRYPOINT ["java", "-jar", "/app.jar", "-web -webAllowOthers -tcp -tcpAllowOthers -browser"]
For below worked:
ENTRYPOINT ["java","-jar","/app.jar","-web -webAllowOthers -tcp -tcpAllowOthers -browser"]

Related

can't access to a spring boot API based in remote docker

I'm trying to get a connection to a Spring Boot application containerized in a old docker:
My docker version is 1.12.2
Spring Boot 2.5.1
here is my Dockerfile:
FROM openjdk:8-alpine
ADD manager.jar manager.jar
EXPOSE 8443
ENTRYPOINT ["java","-Dspring.profiles.active=dev","-jar","manager.jar"]
I've build the image inside docker with this simple command:
docker build -t manager .
and then run the container:
docker run -p 8443:8443 -t manager manager
But when I'm trying to have a connection by typing the adress:
https://SERVERNAME:8443
...timeout.
Did I make a mistake somewhere?
So like I said in my last post, after remove the TLS properties from the application.properties, everything is solved. It's a server configuration problem.

How to pass application.properties to SpringBoot app in Docker container?

Assume we have a simple Dockerfile where my_sb_app.jar is a SpringBoot application:
FROM bellsoft/liberica-openjdk-alpine:11.0.9-12
WORKDIR /app
COPY target/my_sb_app.jar /app
EXPOSE 8080
ENTRYPOINT java -jar my_sb_app.jar
I would like to pass custom app.properties on each run
docker run my_image_name /somewhere/on/my/host/app.properties
so the expected final command (inside the container) could be identical to the following
java -jar my_sb_app.jar --spring.config.location=%%file_with_contents_of_app.properties%%
What is the standard way of passing a file into a Docker container?
How the Docker image sould be changed?
The standard way to pass files from host to the container is with volumes:
https://docs.docker.com/storage/bind-mounts/
https://docs.docker.com/storage/volumes/
In your example:
docker run -v /somewhere/on/my/host/app.properties:/opt/app.properties my_image_name
java -jar my_sb_app.jar --spring.config.location=/opt/app.properties

unable to run docker container as getting this error:Unable to access jarfile app.jar

I have created the image using below Docker file.Its working fine in local when I run it in the container using this image[docker run -p 80:8080 username/spring-boot-docker-aws-demo:tag
FROM openjdk:8-jdk-alpine
COPY target/spring-boot-docker-aws-demo.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","app.jar"]
I have pushed this image to Docker hub to run it in EC2 instance.when I run it its saying "Error: Unable to access jarfile app.jar"
https://hub.docker.com/layers/chaituu/spring-boot-docker-aws-demo/docker-aws-demo-tag/images/sha256-110363a016eb2250264d96c8890dede518d8e519fdc9a27174334fe1096a540e?context=repo
what could be the issue?
I had a similar issue today (although in my case it wouldn't even run locally). Here's what your Dockerfile would look like with my fix:
FROM openjdk:8-jdk-alpine
COPY target/spring-boot-docker-aws-demo.jar /app/app.jar
EXPOSE 8080
ENTRYPOINT ["sh"]
CMD ["-c", "java -jar /app/app.jar"]

Why does my Spring Boot App hang when started in a Docker Swarm

I created a docker image of a Spring Boot app and when I run it using
docker run -d -p 4000:8080 stanlick/stats:v1
It works great! However, when I try to run it as a swarm (even with replicas:1) it hangs on startup.
Running
docker service logs play-ball_web
reveals:
Dockerfile:
FROM openjdk:12-jdk-alpine
VOLUME /tmp ARG JAR_FILE
COPY target/*.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

How to deploy Spring Boot RESTful Web Service Docker img to EC2?

What I'm trying to do is simple, deploy a Spring Boot RESTful Web Service to EC2 so it's accessible publicly.
For this I need to do the following:
Write Spring Boot web service, containerize and test locally - done
Here is my Dockerfile:
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
ADD ${JAR_FILE} app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
When I docker run this locally on 8080 it works fine (returns static json).
Push to Dockerhub - done
Launch an Amazon Linux AMI on aws and make it http accessible (port 80) - done
Install apache (httpd) and start - done
Here is where I need some help
I run docker image from dockerhub like so
docker run --rm -p 80:8080 kaspartr/demo
It doesn't allow cause of course the port is taken by apache. And if I stop it and run it is deployed but I cannot access it online.
Can someone please explain how do you deploy docker image into the apache?
Do I need to change the Dockerfile or something else?
Thank you!!
Typically I run application on separate port and do docker forward:
Add yo you application.properties
server.port=9001
And add to docker-compose.yml:
version: '1'
services:
your-service:
build: .
ports:
- '9001:9001'
environment:
SERVICE_URL: http://service:9001/path
Since Apache has already taken port 80, you cannot make your container runs on port 80 too.
My guess is that you are planning to use Apache as a reverse proxy to your container. Try publishing your container to another port, and proxying port 80 to the container using Apache.

Resources