0
votes

I created a SPRING-BOOT application with docker and I'm deploying this image to Elastic-beanstalk, everything goes well and through the logs, the application starts, but then access the ulr, I get a 503, I've tried several things, can anyone give an idea?

My Dockerrun file:

{
    "AWSEBDockerrunVersion": "2",
    "containerDefinitions": [
        {
            "essential": true,
            "image": "187190575110.dkr.ecr.us-east-1.amazonaws.com/kroton-app:${TAG}",
            "memory": 512,
            "memoryReservation": 256,
            "mountPoints": [],
            "name": "kroton-app",
            "portMappings": [
                {
                    "containerPort": "8080",
                    "hostPort": "80"
                }
            ]
        }
    ]
}

My Docker file:

FROM node:12-alpine

#TEST

# JAVA DEPS
RUN apk --no-cache add openjdk11 --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community
RUN apk --no-cache add maven

# NPM DEPS
RUN mkdir -p /eventos/src/main/resources/node
WORKDIR /eventos
COPY ./src/main/resources/node/package.json src/main/resources/node

RUN cd src/main/resources/node && \
    npm install

# NODE APP
COPY ./src/main/resources/node src/main/resources/node

# NODE BUILD
RUN cd src/main/resources/node && \
    npm run build:prod

# MAVEN DEPS
COPY ./pom.xml /eventos
RUN mvn dependency:go-offline

# MAVEN BUILD
COPY . /eventos
run mvn clean package -Dspring.profiles.active=prod,storage-s3
RUN mvn install -DskipTests

# CLEANUP
RUN rm -rf src/main/resources/node

EXPOSE 8080
CMD ["java","-jar","-Dspring.profiles.active=prod,storage-s3","/eventos/target/eventos-1.0.0-RELEASE.jar"]

My aws logs of application on container (var/log/containers/app.log)

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/eventos/target/eventos-1.0.0-RELEASE.jar!/BOOT-INF/lib/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/eventos/target/eventos-1.0.0-RELEASE.jar!/BOOT-INF/lib/slf4j-simple-1.7.28.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.4.RELEASE)

2020-10-01 18:07:36.768  INFO 1 --- [           main] b.c.p.eventos.EventosApplication         : Starting EventosApplication v1.0.0-RELEASE on 4e2622a12739 with PID 1 (/eventos/target/eventos-1.0.0-RELEASE.jar started by root in /eventos)
2020-10-01 18:07:36.779  INFO 1 --- [           main] b.c.p.eventos.EventosApplication         : The following profiles are active: prod,storage-s3
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (jar:file:/eventos/target/eventos-1.0.0-RELEASE.jar!/BOOT-INF/lib/groovy-2.5.6.jar!/) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2020-10-01 18:07:39.229  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2020-10-01 18:07:39.394  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 145ms. Found 9 repository interfaces.
2020-10-01 18:07:40.934  INFO 1 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$65e536b6] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-10-01 18:07:40.974  INFO 1 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.hateoas.config.HateoasConfiguration' of type [org.springframework.hateoas.config.HateoasConfiguration$$EnhancerBySpringCGLIB$$e56583e8] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-10-01 18:07:41.968  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-10-01 18:07:42.045  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-10-01 18:07:42.046  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.17]
2020-10-01 18:07:42.217  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-10-01 18:07:42.217  INFO 1 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 4768 ms
2020-10-01 18:07:43.643  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2020-10-01 18:07:44.648  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2020-10-01 18:07:44.781  INFO 1 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2020-10-01 18:07:45.017  INFO 1 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.3.9.Final}
2020-10-01 18:07:45.023  INFO 1 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2020-10-01 18:07:45.560  INFO 1 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2020-10-01 18:07:46.462  INFO 1 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL57Dialect
2020-10-01 18:07:47.990  INFO 1 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-10-01 18:07:50.035  INFO 1 --- [           main] b.c.p.e.service.impl.S3StorageService    : S3 Service succesfully connected!
2020-10-01 18:07:50.127  INFO 1 --- [           main] o.h.h.i.QueryTranslatorFactoryInitiator  : HHH000397: Using ASTQueryTranslatorFactory
2020-10-01 18:07:52.377  INFO 1 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@2a16d393, org.springframework.security.web.context.SecurityContextPersistenceFilter@1edac3b4, org.springframework.security.web.header.HeaderWriterFilter@437c1a87, org.springframework.security.web.csrf.CsrfFilter@7294a684, org.springframework.security.web.authentication.logout.LogoutFilter@24842b8e, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@5d6b5d3d, org.springframework.security.web.session.ConcurrentSessionFilter@4a2653a0, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@11069eac, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@3d9c8c3c, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@14d1032a, org.springframework.security.web.session.SessionManagementFilter@6c8e5ac4, org.springframework.security.web.access.ExceptionTranslationFilter@75663443, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@d08f85a]
2020-10-01 18:07:52.662  INFO 1 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-10-01 18:07:52.700  WARN 1 --- [           main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-10-01 18:07:53.811  INFO 1 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 2 endpoint(s) beneath base path '/actuator'
2020-10-01 18:07:54.089  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2020-10-01 18:07:54.093  INFO 1 --- [           main] b.c.p.eventos.EventosApplication         : Started EventosApplication in 18.837 seconds (JVM running for 20.264)

SSH response:

$ sudo docker ps
CONTAINER ID        IMAGE                                                            COMMAND                  CREATED             STATUS                   PORTS                    NAMES
60208e7c7429        187190575110.dkr.ecr.us-east-1.amazonaws.com/kroton-app:master   "docker-entrypoint.s…"   5 minutes ago       Up 5 minutes             0.0.0.0:8080->8080/tcp   ecs-awseb-kroton-prod-ywvf9pvxrr-19-kroton-app-bc9591de9be2fd9f3000
3cee31b0f74d        amazon/amazon-ecs-agent:latest                                   "/agent"                 6 minutes ago       Up 6 minutes (healthy)                            ecs-agent



$ curl http://localhost:8080
<!doctype html> <html lang="pt"> <head> <title>Eventos Kroton - Home</title> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/> <link rel="stylesheet" href="/css/eventos-977e18c37ae6ce996d5f9871a231481b.css"> </head> <body> <input name="_csrf" value="a03be7d3-b991-4f48-a596-b0c4b6f82dce" id="csrf-token" type="hidden"/> <div> <script src="/js/eventos-82e6dbb5b75296a131489f409be47723.js"></script> </div> <header> <div class="border-bottom"> <div class="mobile-header container my-2 d-md-none"> <span class="mobile-menu-btn fa fa-3x fa-bars"></span> </div> <div class="mini-header container py-2 d-md-block d-none"> <div class="row"> <div class="col"> <a class="text-uppercase" href="https://pgsskroton.com.br/" target="_blank">Portal Strictu Sensu</a> </div> <div class="col text-right"> </div> </div> </div> </div> <div class="main-header container-fluid d-flex py-2 px-xl-5"> <div class="row m-0 w-100"> <div class="search-box form-inline col-4 d-md-flex d-none"> <div class="form-group w-100"> <label class="mr-2" for="search"><span class="fa fa-2x fa-search"></span></label> <select class="flex-grow-1 form-control form-control-sm border-0" id="search" placeholder="Pesquisar" type="text"> </select> </div> </div> <div class="logo-container align-self-center col-12 col-md-4"> <a class="text-decoration-none" href="/" title="Eventos Kroton"> <img alt="Eventos Kroton" class="mx-auto d-block" src="/img/logo.svg"> </a> </div> <ul class="header-menu list-inline text-right align-self-center col-4 d-md-block d-none m-0" id="desktop-menu">   <li class="list-inline-item"><a href="/login">Login</a></li> <li class="list-inline-item"><a href="/registrar">Criar Nova Conta</a></li>  </ul> </div> </div> </header> <div> <section id="events-banner" class="py-5"> <div class="events-featured container"> <div id="events-carousel" class="carousel slide carousel-fade" data-ride="carousel"> <ol class="carousel-indicators">  </ol> <div class="carousel-inner">  </div> </div> </div> </section>   </div> <div> <div class="footer navbar-fixed-bottom text-center" style="background-color: #046eb1; color: white;padding : 5px; margin: 5px;"> <address> Kroton Educacional 2020. Todos os Direitos Reservados - Sistema de Eventos<br> Contato: <a style="color: white;hover: red;" href="mailto:[email protected]">[email protected]</a> </address> </div> </div> <script>EventosJs.init();function searchSelectize(a){a("#search").selectize({valueField:"id",labelField:"titulo",searchField:"titulo",preload:true,options:[],create:false,render:{option:function(c,b){return'<div><div class="row px-1 mb-2 cursor-pointer"><div class="col-4"><img class="img-fluid" src="/img/eventos/'+c.id+"/thumb/"+c.imgMiniaturaName+'.jpg" ></div><div class="col-8">'+b(c.titulo)+"</div></div></div>"}},load:function(b,c){a.ajax({url:"/api/evento/find",type:"GET",dataType:"json",data:{titulo:b},error:function(){c()},success:function(d){c(d.content)}})},onChange:function(b){this.clearOptions();window.location="/eventos/"+b}})}EventosJs.addEvent(searchSelectize);</script> </body> </html>
2
If you ssh into the instance, does the contaiener run? You can run sudo docker ps. Check exposed ports, and curl the container directly to see if the app works on localhost.Marcin
Ok, I plugged it in instance and run a docker ps and Curl on the port, added the result above as an SSH responseJoão Junior

2 Answers

0
votes

Your new output shows that you are using port 8080:

0.0.0.0:8080->8080/tcp

Your Dockerrun does not match these ports:

            "portMappings": [
                {
                    "containerPort": "8000",
                    "hostPort": "80"
                }

So somehow you are using different ports in Dockerrun and in the actual docker when it runs.

Maybe don't need to use EXPOSE 8080 in your Dokerfile.

0
votes

You're exposing port 8080 on Dockerfile and mapping 8000 on Dockerrun.aws.json. I believe this is the real problem. For solve, you can expose the port 8000 on image and after deploy, trying to access the endpoint with the port.

Can you try to build an image with this Dockerfile?

FROM node:12-alpine

#TEST

# JAVA DEPS
RUN apk --no-cache add openjdk11 --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community
RUN apk --no-cache add maven

# NPM DEPS
RUN mkdir -p /eventos/src/main/resources/node
WORKDIR /eventos
COPY ./src/main/resources/node/package.json src/main/resources/node

RUN cd src/main/resources/node && \
    npm install

# NODE APP
COPY ./src/main/resources/node src/main/resources/node

# NODE BUILD
RUN cd src/main/resources/node && \
    npm run build:prod

# MAVEN DEPS
COPY ./pom.xml /eventos
RUN mvn dependency:go-offline

# MAVEN BUILD
COPY . /eventos
run mvn clean package -Dspring.profiles.active=prod,storage-s3
RUN mvn install -DskipTests

# CLEANUP
RUN rm -rf src/main/resources/node

EXPOSE 8000
CMD ["java","-jar","-Dspring.profiles.active=prod,storage-s3","/eventos/target/eventos-1.0.0-RELEASE.jar"]