1

I am trying to run spring-boot application through docker container. I am using docker-compose for the same. But the container is not getting UP. It's status is showing always 'restarting X seconds'. I'm unable to find the issue because i can't go inside the container to check logs. even 'docker logs' giving any response.

Can anyone let me know if there is any way to find the issue.

below is docker-compose.yml

version: "3"

services:

 test-create-backend:
  restart: always
  build: .
  container_name: test-create-backend
  environment:
   - JASYPT_PWD=${JASYPT_PWD}
  networks:
   - test-proxy
  ports:
   - "8096:8096"
  volumes: 
   - /home/ubuntu/tnc_logs:/TnC/logs

 nginx:
  restart: always
  container_name: nginx
  image: nginx
  networks:
   - test-proxy
  depends_on:
   - test-create-backend
  ports:
   - '80:80'
   - '443:443'
  volumes:
   - './nginx_proxy/conf.d:/etc/nginx/conf.d:ro'
   - './build:/var/www'
   - '/etc/ssl/certs:/etc/ssl/certs:ro'

networks:
 disip-proxy:
    external:
      name: test-proxy

below is Dockerfile

FROM maven:3.6.0-jdk-11-slim AS build

# Copy the source code
RUN rm -rf /usr/src/app/*
COPY src /usr/src/app/src
COPY pom.xml /usr/src/app
USER root
# Setup working directory
WORKDIR /usr/src/app

# Speed up Maven JVM a bit
ENV MAVEN_OPTS="-XX:+TieredCompilation -XX:TieredStopAtLevel=1"

# Compile the code, run unit tests and pack the fat-JAR file
RUN mvn -T 1C -f /usr/src/app/pom.xml clean package  -DskipTests

# Building the final image with fatjar
FROM openjdk:11-jre-slim
COPY --from=build /usr/src/app/target/test*.jar /home/app/app.jar
ENTRYPOINT java -jar -Dspring.profiles.active=local -Djasypt.encryptor.password=${JASYPT_PWD} /home/app/app.jar
Madhu Sudhan Reddy
  • 607
  • 5
  • 15
  • 22

2 Answers2

0

The container seems to be crashing on boot for some reason. Try to start it using the pseudo-TTY "-dit" argument to see why its failing

docker run -it MYCONTAINER /bin/sh

That should give you an idea about why it is crashing.

Bouzid Zitouni
  • 1,119
  • 8
  • 12
  • You can take it another step back and do docker run -it openjdk /bin/sh , then run the command that you're sending in the ENTRYPOINT, if that exits immediately then that's the problem, you can refer to this question for the solution [link](https://stackoverflow.com/questions/28212380/why-docker-container-exits-immediately) I could have tested it for you if you actually provided a text compose file instead of a screenshot. – Bouzid Zitouni Aug 19 '19 at 18:15
  • Actually this helped me , docker run -it openjdk /bin/sh. We had a problem with 'openjdk:11-jre-slim' this image. I used latest .Now, it's working fine. Thank you so much @Bouzid – Madhu Sudhan Reddy Aug 20 '19 at 14:07
0

You should run the built image overriding the entrypoint and troubleshoot from there using the following:

# Assuming you have /bin/bash
docker run -it --entrypoint "/bin/bash" myimagename:myimagetag

You should be able to get into the container from here with your app added to it and then run the java command in your entrypoint which is likely the issue (which may be failing silently).

leeman24
  • 2,729
  • 3
  • 29
  • 42
  • (If you change ENTRYPOINT to CMD in the `Dockerfile`, the simpler debug-shell invocation in the @BouzidZitouni's answer will work.) – David Maze Aug 19 '19 at 23:35