Я работал над небольшим весенним загрузочным приложением, используя docker -compose. У меня есть контейнер с веб-приложением и один с базой данных. Для разработки / отладки я запускал только контейнер базы данных с использованием docker -compose и запускал приложение весенней загрузки в режиме отладки в Eclipse. Все идет нормально.
Затем я пытаюсь запустить все это, используя docker -compose. Это мой файл yml и выходные данные журнала (некоторые имена были изменены, чтобы защитить невинных) ... для проверки части docker, которую я сопоставил с файлом jar, вместо того, чтобы каждый раз перестраивать образ docker.
version: '3'
services:
myapp-service:
image: myapp-service
env_file:
- common.env
ports:
- 8080:8080
volumes:
- "./target/myapp-service.jar:/myapp-service.jar"
depends_on:
- database
database:
image: mongo
env_file:
- common.env
volumes:
- "./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro"
ports:
- "27017-27019:27017-27019"
У меня есть пользовательская форма входа в систему, и в Eclipse она работает просто отлично. Это то, что я получаю, когда запускаю все это в docker и перехожу на веб-страницу:
myapp-service_1 | 2020-05-04 00:20:27.083 DEBUG 1 --- [nio-8080-exec-8] o.s.security.web.FilterChainProxy : /login reached end of additional filter chain; proceeding with original chain
myapp-service_1 | 2020-05-04 00:20:27.083 DEBUG 1 --- [nio-8080-exec-8] o.s.web.servlet.DispatcherServlet : GET "/login", parameters={}
myapp-service_1 | 2020-05-04 00:20:27.084 DEBUG 1 --- [nio-8080-exec-8] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to com.sammckee.data.controller.LoginController#login()
myapp-service_1 | 2020-05-04 00:20:27.085 DEBUG 1 --- [nio-8080-exec-8] o.s.w.s.v.ContentNegotiatingViewResolver : Selected 'text/html' given [text/html, application/xhtml+xml, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.9, */*;q=0.8]
myapp-service_1 | 2020-05-04 00:20:27.085 DEBUG 1 --- [nio-8080-exec-8] o.s.web.servlet.view.JstlView : View name 'login', model {}
myapp-service_1 | 2020-05-04 00:20:27.086 DEBUG 1 --- [nio-8080-exec-8] o.s.web.servlet.view.JstlView : Forwarding to [/WEB-INF/views/login.jsp]
myapp-service_1 | 2020-05-04 00:20:27.092 DEBUG 1 --- [nio-8080-exec-8] o.s.s.w.header.writers.HstsHeaderWriter : Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@49e79d09
myapp-service_1 | 2020-05-04 00:20:27.092 DEBUG 1 --- [nio-8080-exec-8] w.c.HttpSessionSecurityContextRepository : SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.web.servlet.DispatcherServlet : Completed 404 NOT_FOUND
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.s.w.a.ExceptionTranslationFilter : Chain processed normally
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] s.s.w.c.SecurityContextPersistenceFilter : SecurityContextHolder now cleared, as request processing completed
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.security.web.FilterChainProxy : /error at position 1 of 11 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.security.web.FilterChainProxy : /error at position 2 of 11 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] w.c.HttpSessionSecurityContextRepository : HttpSession returned null object for SPRING_SECURITY_CONTEXT
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] w.c.HttpSessionSecurityContextRepository : No SecurityContext was available from the HttpSession: org.apache.catalina.session.StandardSessionFacade@6c18ca17. A new one will be created.
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.security.web.FilterChainProxy : /error at position 3 of 11 in additional filter chain; firing Filter: 'HeaderWriterFilter'
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.security.web.FilterChainProxy : /error at position 4 of 11 in additional filter chain; firing Filter: 'LogoutFilter'
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.s.web.util.matcher.OrRequestMatcher : Trying to match using Ant [pattern='/logout', GET]
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.s.w.u.matcher.AntPathRequestMatcher : Checking match of request : '/error'; against '/logout'
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.s.web.util.matcher.OrRequestMatcher : Trying to match using Ant [pattern='/logout', POST]
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.s.w.u.matcher.AntPathRequestMatcher : Request 'GET /error' doesn't match 'POST /logout'
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.s.web.util.matcher.OrRequestMatcher : Trying to match using Ant [pattern='/logout', PUT]
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.s.w.u.matcher.AntPathRequestMatcher : Request 'GET /error' doesn't match 'PUT /logout'
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.s.web.util.matcher.OrRequestMatcher : Trying to match using Ant [pattern='/logout', DELETE]
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.s.w.u.matcher.AntPathRequestMatcher : Request 'GET /error' doesn't match 'DELETE /logout'
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.s.web.util.matcher.OrRequestMatcher : No matches found
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.security.web.FilterChainProxy : /error at position 5 of 11 in additional filter chain; firing Filter: 'UsernamePasswordAuthenticationFilter'
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.s.w.u.matcher.AntPathRequestMatcher : Request 'GET /error' doesn't match 'POST /login'
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.security.web.FilterChainProxy : /error at position 6 of 11 in additional filter chain; firing Filter: 'RequestCacheAwareFilter'
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.s.w.s.DefaultSavedRequest : pathInfo: both null (property equals)
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.s.w.s.DefaultSavedRequest : queryString: both null (property equals)
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.s.w.s.DefaultSavedRequest : requestURI: arg1=/; arg2=/error (property not equals)
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.s.w.s.HttpSessionRequestCache : saved request doesn't match
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.security.web.FilterChainProxy : /error at position 7 of 11 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
myapp-service_1 | 2020-05-04 00:20:27.093 DEBUG 1 --- [nio-8080-exec-8] o.s.security.web.FilterChainProxy : /error at position 8 of 11 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'
myapp-service_1 | 2020-05-04 00:20:27.094 DEBUG 1 --- [nio-8080-exec-8] o.s.s.w.a.AnonymousAuthenticationFilter : Populated SecurityContextHolder with anonymous token: 'org.springframework.security.authentication.AnonymousAuthenticationToken@48fd2a32: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@0: RemoteIpAddress: 172.30.0.1; SessionId: 7F4F9718EE23E9AA0244329F374437D3; Granted Authorities: ROLE_ANONYMOUS'
myapp-service_1 | 2020-05-04 00:20:27.094 DEBUG 1 --- [nio-8080-exec-8] o.s.security.web.FilterChainProxy : /error at position 9 of 11 in additional filter chain; firing Filter: 'SessionManagementFilter'
myapp-service_1 | 2020-05-04 00:20:27.094 DEBUG 1 --- [nio-8080-exec-8] o.s.security.web.FilterChainProxy : /error at position 10 of 11 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
myapp-service_1 | 2020-05-04 00:20:27.094 DEBUG 1 --- [nio-8080-exec-8] o.s.security.web.FilterChainProxy : /error at position 11 of 11 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
myapp-service_1 | 2020-05-04 00:20:27.094 DEBUG 1 --- [nio-8080-exec-8] o.s.security.web.FilterChainProxy : /error reached end of additional filter chain; proceeding with original chain
myapp-service_1 | 2020-05-04 00:20:27.094 DEBUG 1 --- [nio-8080-exec-8] o.s.web.servlet.DispatcherServlet : "ERROR" dispatch for GET "/error", parameters={}
myapp-service_1 | 2020-05-04 00:20:27.094 DEBUG 1 --- [nio-8080-exec-8] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#errorHtml(HttpServletRequest, HttpServletResponse)
myapp-service_1 | 2020-05-04 00:20:27.097 DEBUG 1 --- [nio-8080-exec-8] o.s.w.s.v.ContentNegotiatingViewResolver : Selected 'text/html' given [text/html, text/html;q=0.8]
myapp-service_1 | 2020-05-04 00:20:27.097 DEBUG 1 --- [nio-8080-exec-8] o.s.web.servlet.DispatcherServlet : Exiting from "ERROR" dispatch, status 404
myapp-service_1 | 2020-05-04 00:20:27.097 DEBUG 1 --- [nio-8080-exec-8] o.s.s.w.a.ExceptionTranslationFilter : Chain processed normally
myapp-service_1 | 2020-05-04 00:20:27.097 DEBUG 1 --- [nio-8080-exec-8] w.c.HttpSessionSecurityContextRepository : SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
myapp-service_1 | 2020-05-04 00:20:27.097 DEBUG 1 --- [nio-8080-exec-8] s.s.w.c.SecurityContextPersistenceFilter : SecurityContextHolder now cleared, as request processing completed
Есть мысли о том, чего мне не хватает? Опять же, он отлично работает в Eclipse. Извините за длинный текст журнала - я хотел убедиться, что предоставил всю необходимую информацию.
Редактировать / добавить: Когда я перехожу к веб-приложению, я вижу это:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon May 04 00:20:27 GMT 2020
There was an unexpected error (type=Not Found, status=404).
/WEB-INF/views/login.jsp
Мои DAO происходят из класса, который подключается к базе данных, например:
String client_url = "mongodb://" + dbuser + ":" + dbpassword + "@" + hostName + ":" + 27017 + "/"
+ databaseName;
... где имя хоста, база данных, пользователь и пароль передаются переменными среды.
Для имени хоста, которое я передаю в «базе данных», потому что это имя контейнера - так оно и должно работать в контейнере, верно? Когда я запускаю его в Eclipse, я передаю имя хоста localhost, потому что контейнер базы данных предоставляет тот же номер порта локальной среде, и он работает нормально. Я ожидаю увидеть сообщения об ошибках базы данных, если это проблема с моим подключением mon go, но, возможно, нет.
Редактировать / Приложение 2: Похоже, что Сприни я что-то не так делаю. Я сделал небольшой скрипт для установки переменных окружения и запустил jar-файл автономно в bash, вне контейнера, и он работает как положено. Внутри docker контейнера я получаю ошибки. Это часть журнала, которая бросается в глаза:
Returning cached instance of singleton bean 'loginController'
s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to com.myapp.bank.controller.LoginController#login()
.w.s.m.m.a.ServletInvocableHandlerMethod : Arguments: []
o.s.w.s.v.InternalResourceViewResolver : View with key [login] served from cache
o.s.w.s.v.ContentNegotiatingViewResolver : Selected 'text/html' given [text/html, application/xhtml+xml, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.9, */*;q=0.8]
o.s.web.servlet.DispatcherServlet : Rendering view [org.springframework.web.servlet.view.JstlView: name 'login'; URL [/WEB-INF/views/login.jsp]]
o.s.web.servlet.view.JstlView : View name 'login', model {}
o.s.b.f.s.DefaultListableBeanFactory : Returning cached instance of singleton bean 'requestDataValueProcessor'
o.s.web.servlet.view.JstlView : Forwarding to [/WEB-INF/views/login.jsp]
o.s.s.w.header.writers.HstsHeaderWriter : Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@70ad1909
w.c.HttpSessionSecurityContextRepository : SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
o.s.web.servlet.DispatcherServlet : Completed 404 NOT_FOUND, headers={masked}
o.s.s.w.a.ExceptionTranslationFilter : Chain processed normally
Редактировать / Приложение 3: Все еще в тупике. Я подтвердил, что могу скопировать JAR-файл в другие места, и он там работает нормально, обслуживает JSP, как и ожидалось, и выполняет все, что я хочу. Так что, мне кажется, сам файл jar должен быть в порядке. Я озадачен тем, что может отличаться, когда оно внутри docker.