Em poucos dias atrás comecei meu estudo com Docker, peguei uns daqueles cursos da cod3r, pareceu lindo e maravilhoso.
E depois comecei a fazer experiências com Spring Boot, é um Arquivo JAR que eu criei a parti de uma aplicação web, e executando pelo Power Shell do windows ela consegue criar as tabelas automaticamente, ela consegue executar o TomCat através da porta 8080 .
Depois de testa-la resolvi experimentar ela no docker, criei um arquivo Dockerfile, onde ela seria chamada pelo arquivo docker-compose.yml.
Ao executa-la, a aplicação não mostra nenhuma mensagem de erro, ao contrário, ela mostra que criou as tabelas automaticamente, que se conectou com a porta 8080 e que o TomCat foi executa. Me parece mais uma mensagem FAKE, pois quando vou analisar o banco de dados Postgres, as tabelas não foram criadas, quando eu vou verificar pelo Power Shell a porta não está sendo utilizada, e quando vou ver o contexto da aplicação ela não subiu para a URL
E por favor não me perguntem se tenho certeza se o contexto da aplicação está certa, porque está!
Essa foi a mensagem que recebi, vejam com seus próprios olhos;
$ docker-compose up --force-recreate --build
Creating network "teste_postgres-compose-network" with driver "bridge"
Creating volume "teste_pgdata-teste" with default driver
Building java
Gracefully stopping... (press Ctrl+C again to force)
DESKTOP-LTE4439+resource@DESKTOP-LTE4439 MINGW64 /c/docker/teste
$ docker-compose up --force-recreate --build
Building java
Step 1/4 : FROM openjdk:8-jdk
---> 08ded5f856cc
Step 2/4 : COPY dockerTest-1.0.0-SNAPSHOT.jar webapp.jar
---> 55282bac9bfc
Step 3/4 : EXPOSE 8080
---> Running in e2c87cfc1710
Removing intermediate container e2c87cfc1710
---> bdadf54c7c4d
Step 4/4 : ENTRYPOINT ["java","-Dspring.profiles.active=docker-demo","-jar","webapp.jar"]
---> Running in c86cedbdd72a
Removing intermediate container c86cedbdd72a
---> 9c686fc91138
Successfully built 9c686fc91138
Successfully tagged teste_java:latest
Creating postgres-kwan ... done
Creating teste_java_1 ... done
Attaching to postgres-kwan, teste_java_1
postgres-kwan | The files belonging to this database system will be owned by user "postgres".
postgres-kwan | This user must also own the server process.
postgres-kwan |
postgres-kwan | The database cluster will be initialized with locale "en_US.utf8".
postgres-kwan | The default database encoding has accordingly been set to "UTF8".
postgres-kwan | The default text search configuration will be set to "english".
postgres-kwan |
postgres-kwan | Data page checksums are disabled.
postgres-kwan |
postgres-kwan | fixing permissions on existing directory /var/lib/postgresql/data ... ok
postgres-kwan | creating subdirectories ... ok
postgres-kwan | selecting default max_connections ... 100
postgres-kwan | selecting default shared_buffers ... 128MB
postgres-kwan | selecting default timezone ... Etc/UTC
postgres-kwan | selecting dynamic shared memory implementation ... posix
postgres-kwan | creating configuration files ... ok
postgres-kwan | running bootstrap script ... ok
java_1 | SLF4J: Class path contains multiple SLF4J bindings.
java_1 | SLF4J: Found binding in [jar:file:/webapp.jar!/BOOT-INF/lib/logback-classic-1.1.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
java_1 | SLF4J: Found binding in [jar:file:/webapp.jar!/BOOT-INF/lib/slf4j-simple-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
java_1 | SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
postgres-kwan | performing post-bootstrap initialization ... ok
postgres-kwan | syncing data to disk ... ok
postgres-kwan |
postgres-kwan | WARNING: enabling "trust" authentication for local connections
postgres-kwan | You can change this by editing pg_hba.conf or using the option -A, or
postgres-kwan | --auth-local and --auth-host, the next time you run initdb.
postgres-kwan |
postgres-kwan | Success. You can now start the database server using:
postgres-kwan |
postgres-kwan | pg_ctl -D /var/lib/postgresql/data -l logfile start
postgres-kwan |
postgres-kwan | waiting for server to start....2019-08-29 19:17:40.407 UTC [40] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres-kwan | 2019-08-29 19:17:40.428 UTC [41] LOG: database system was shut down at 2019-08-29 19:17:40 UTC
postgres-kwan | 2019-08-29 19:17:40.437 UTC [40] LOG: database system is ready to accept connections
postgres-kwan | done
postgres-kwan | server started
postgres-kwan | CREATE DATABASE
postgres-kwan |
postgres-kwan |
postgres-kwan | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
postgres-kwan |
postgres-kwan | 2019-08-29 19:17:41.030 UTC [40] LOG: received fast shutdown request
postgres-kwan | waiting for server to shut down....2019-08-29 19:17:41.031 UTC [40] LOG: aborting any active transactions
postgres-kwan | 2019-08-29 19:17:41.040 UTC [40] LOG: background worker "logical replication launcher" (PID 47) exited with exit code 1
postgres-kwan | 2019-08-29 19:17:41.041 UTC [42] LOG: shutting down
postgres-kwan | 2019-08-29 19:17:41.053 UTC [40] LOG: database system is shut down
postgres-kwan | done
postgres-kwan | server stopped
postgres-kwan |
postgres-kwan | PostgreSQL init process complete; ready for start up.
postgres-kwan |
postgres-kwan | 2019-08-29 19:17:41.167 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres-kwan | 2019-08-29 19:17:41.167 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgres-kwan | 2019-08-29 19:17:41.171 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres-kwan | 2019-08-29 19:17:41.207 UTC [58] LOG: database system was shut down at 2019-08-29 19:17:41 UTC
java_1 | SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
java_1 |
java_1 | . ____ _ __ _ _
java_1 | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
java_1 | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
java_1 | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
java_1 | ' |____| .__|_| |_|_| |_\__, | / / / /
java_1 | =========|_|==============|___/=/_/_/_/
java_1 | :: Spring Boot :: (v1.5.3.RELEASE)
java_1 |
java_1 | 2019-08-29 19:17:42.216 INFO 1 --- [ main] c.e.algamoney.api.DockerTestApplication : Starting DockerTestApplication v1.0.0-SNAPSHOT on 70ca5aafb40b with PID 1 (/webapp.jar started by root in /)
java_1 | 2019-08-29 19:17:42.228 INFO 1 --- [ main] c.e.algamoney.api.DockerTestApplication : The following profiles are active: docker-demo
java_1 | 2019-08-29 19:17:42.455 INFO 1 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2328c243: startup date [Thu Aug 29 19:17:42 UTC 2019]; root of context hierarchy
java_1 | 2019-08-29 19:17:47.809 INFO 1 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
java_1 | 2019-08-29 19:17:47.855 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
java_1 | 2019-08-29 19:17:47.860 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.14
java_1 | 2019-08-29 19:17:48.111 INFO 1 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
java_1 | 2019-08-29 19:17:48.113 INFO 1 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 5669 ms
java_1 | 2019-08-29 19:17:48.486 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
java_1 | 2019-08-29 19:17:48.500 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'corsFilter' to: [/*]
java_1 | 2019-08-29 19:17:48.503 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
java_1 | 2019-08-29 19:17:48.504 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
java_1 | 2019-08-29 19:17:48.509 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
java_1 | 2019-08-29 19:17:48.510 INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
java_1 | 2019-08-29 19:17:49.180 INFO 1 --- [ main] o.f.core.internal.util.VersionPrinter : Flyway 3.2.1 by Boxfuse
java_1 | 2019-08-29 19:17:49.469 INFO 1 --- [ main] o.f.c.i.dbsupport.DbSupportFactory : Database: jdbc:postgresql://kwan:5432/POSTGRESQL (PostgreSQL 11.5)
java_1 | 2019-08-29 19:17:49.575 INFO 1 --- [ main] o.f.core.internal.command.DbValidate : Validated 5 migrations (execution time 00:00.032s)
java_1 | 2019-08-29 19:17:49.599 INFO 1 --- [ main] o.f.c.i.metadatatable.MetaDataTableImpl : Creating Metadata table: "public"."schema_version"
java_1 | 2019-08-29 19:17:49.673 INFO 1 --- [ main] o.f.core.internal.command.DbMigrate : Current version of schema "public": << Empty Schema >>
java_1 | 2019-08-29 19:17:49.677 INFO 1 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "public" to version 01 - criar e registrar categorias
java_1 | 2019-08-29 19:17:49.727 INFO 1 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "public" to version 02 - criar tabela pessoa
java_1 | 2019-08-29 19:17:49.781 INFO 1 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "public" to version 03 - criar tabela e registrar lancamentos
java_1 | 2019-08-29 19:17:49.834 INFO 1 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "public" to version 04 - criar e registrar usuarios e permissoes
java_1 | 2019-08-29 19:17:49.879 INFO 1 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "public" to version 05 - criar tabela contato
java_1 | 2019-08-29 19:17:49.926 INFO 1 --- [ main] o.f.core.internal.command.DbMigrate : Successfully applied 5 migrations to schema "public" (execution time 00:00.327s).
java_1 | 2019-08-29 19:17:50.248 INFO 1 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
java_1 | 2019-08-29 19:17:50.285 INFO 1 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
java_1 | name: default
java_1 | ...]
java_1 | 2019-08-29 19:17:50.499 INFO 1 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.0.12.Final}
java_1 | 2019-08-29 19:17:50.506 INFO 1 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
java_1 | 2019-08-29 19:17:50.510 INFO 1 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
java_1 | 2019-08-29 19:17:50.620 INFO 1 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
java_1 | 2019-08-29 19:17:51.129 INFO 1 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
java_1 | 2019-08-29 19:17:51.519 INFO 1 --- [ main] o.h.e.j.e.i.LobCreatorBuilderImpl : HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
java_1 | 2019-08-29 19:17:51.525 INFO 1 --- [ main] org.hibernate.type.BasicTypeRegistry : HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@1acaf3d
java_1 | 2019-08-29 19:17:52.559 INFO 1 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
java_1 | 2019-08-29 19:17:53.843 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2328c243: startup date [Thu Aug 29 19:17:42 UTC 2019]; root of context hierarchy
java_1 | 2019-08-29 19:17:54.075 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/categorias],methods=[GET]}" onto public java.util.List<com.example.algamoney.api.model.Categoria> com.example.algamoney.api.resource.CategoriaResource.listar()
java_1 | 2019-08-29 19:17:54.079 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/categorias],methods=[POST]}" onto public org.springframework.http.ResponseEntity<com.example.algamoney.api.model.Categoria> com.example.algamoney.api.resource.CategoriaResource.criar(com.example.algamoney.api.model.Categoria,javax.servlet.http.HttpServletResponse)
java_1 | 2019-08-29 19:17:54.085 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/categorias/{codigo}],methods=[GET]}" onto public org.springframework.http.ResponseEntity<com.example.algamoney.api.model.Categoria> com.example.algamoney.api.resource.CategoriaResource.buscarPeloCodigo(java.lang.Long)
java_1 | 2019-08-29 19:17:54.091 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/lancamentos/{codigo}],methods=[DELETE]}" onto public void com.example.algamoney.api.resource.LancamentoResource.remover(java.lang.Long)
java_1 | 2019-08-29 19:17:54.097 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/lancamentos],methods=[POST]}" onto public org.springframework.http.ResponseEntity<com.example.algamoney.api.model.Lancamento> com.example.algamoney.api.resource.LancamentoResource.criar(com.example.algamoney.api.model.Lancamento,javax.servlet.http.HttpServletResponse)
java_1 | 2019-08-29 19:17:54.098 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/lancamentos/{codigo}],methods=[GET]}" onto public org.springframework.http.ResponseEntity<com.example.algamoney.api.model.Lancamento> com.example.algamoney.api.resource.LancamentoResource.buscarPeloCodigo(java.lang.Long)
java_1 | 2019-08-29 19:17:54.101 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/lancamentos],methods=[GET]}" onto public org.springframework.data.domain.Page<com.example.algamoney.api.model.Lancamento> com.example.algamoney.api.resource.LancamentoResource.pesquisar(com.example.algamoney.api.repository.filter.LancamentoFilter,org.springframework.data.domain.Pageable)
java_1 | 2019-08-29 19:17:54.117 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/pessoas/{codigo}],methods=[DELETE]}" onto public void com.example.algamoney.api.resource.PessoaResource.remover(java.lang.Long)
java_1 | 2019-08-29 19:17:54.119 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/pessoas/{codigo}],methods=[PUT]}" onto public org.springframework.http.ResponseEntity<com.example.algamoney.api.model.Pessoa> com.example.algamoney.api.resource.PessoaResource.atualizar(java.lang.Long,com.example.algamoney.api.model.Pessoa)
java_1 | 2019-08-29 19:17:54.121 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/pessoas/{codigo}/ativo],methods=[PUT]}" onto public void com.example.algamoney.api.resource.PessoaResource.atualizarPropriedadeAtivo(java.lang.Long,java.lang.Boolean)
java_1 | 2019-08-29 19:17:54.121 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/pessoas],methods=[POST]}" onto public org.springframework.http.ResponseEntity<com.example.algamoney.api.model.Pessoa> com.example.algamoney.api.resource.PessoaResource.criar(com.example.algamoney.api.model.Pessoa,javax.servlet.http.HttpServletResponse)
java_1 | 2019-08-29 19:17:54.122 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/pessoas/{codigo}],methods=[GET]}" onto public org.springframework.http.ResponseEntity<com.example.algamoney.api.model.Pessoa> com.example.algamoney.api.resource.PessoaResource.buscarPeloCodigo(java.lang.Long)
java_1 | 2019-08-29 19:17:54.139 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
java_1 | 2019-08-29 19:17:54.141 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
java_1 | 2019-08-29 19:17:54.216 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
java_1 | 2019-08-29 19:17:54.216 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
java_1 | 2019-08-29 19:17:54.260 INFO 1 --- [ main] .m.m.a.ExceptionHandlerExceptionResolver : Detected @ExceptionHandler methods in algamoneyExceptionHandler
java_1 | 2019-08-29 19:17:54.314 INFO 1 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
java_1 | 2019-08-29 19:17:54.884 INFO 1 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
java_1 | 2019-08-29 19:17:55.050 INFO 1 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)