VIJ
VIJ

Reputation: 1636

Spring boot running as container issues

I am running a spring boot with REST API inside a docker container. Everything seems to work fine when i run from eclipse or as jar. But when i dockerize it and run i am facing below issues

First Not able to access REST Endpoint within container.

http://localhost:9000/ --> works But

http://localhost:9000/api/v1/test --> it does not identify.

However i can run it from swagger.

Second issue org.postgresql.util.PSQLException: ERROR: permission denied for schema < schema_name >

However i have given all permissions for the schema like

GRANT ALL ON SCHEMA < schemaname> TO < username>;
GRANT USAGE ON SCHEMA < schemaname> TO < username>;

These issues are only when i try to run from a container.

Commands use for docker

docker run -p 9000:9000 < image name >

Am using spring boot 2.1.9

Dockerfile

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD run-app.sh run-app.sh
RUN chmod +x run-app.sh
EXPOSE 9000
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} dummy.jar
ENTRYPOINT ./run-app.sh

run-app.sh

java  $JAVA_OPTS -jar /dummy.jar

My postgresql Db is running in aws.

My spring boot is able to start, but only while my API is querying i am facing the exception

Upvotes: 0

Views: 258

Answers (2)

Vinay Prajapati
Vinay Prajapati

Reputation: 7546

For first issue I will need more details.

For second issue, the problem is two containers are not on the same network and hence service container can't communicate with psql container. You can actually create a docker-compose.yml file to run those on same network. Or create a network and join the containers on that network.

Upvotes: 0

Pranay
Pranay

Reputation: 69

Can you share dockerfile content if possible, would like to see what commands you have given with endpoints. and for postgresql which you are using, is it embeded in docker with spring boot app or another server?

I do already setup spring boot with nginx and postgresql dockerized but in different servers/containers which working pretty smooth on production.

Upvotes: 0

Related Questions