简而言之,我有一个非常简单的Spring Cloud Config服务器,我想在Docker容器中运行它。相同的应用程序在本地成功运行,但是当我在Docker中运行它并尝试通过邮递员ping时,出现了“根本原因无法加载环境”。
Dockerfile
FROM openjdk:8-jdk-alpine
MAINTAINER jimis.drpc@gmail.com
COPY files/config-server-0.0.1-SNAPSHOT.jar /opt/spring-cloud/lib/
ENV SPRING_APPLICATION_JSON='{"spring": {"cloud": {"config": {"server": {"git": {"uri": "/home/jimis/_d/GITs/spring_cloud_config_server", "clone-on-start": true}}}}}}'
ENTRYPOINT ["/usr/bin/java"]
CMD ["-jar", "/opt/spring-cloud/lib/config-server-0.0.1-SNAPSHOT.jar"]
VOLUME /var/lib/spring-cloud/config-repo
EXPOSE 8888
Spring Boot Application属性
server.port=8888
#spring.cloud.config.server.git.uri=ssh://localhost/config-repo
#spring.cloud.config.server.git.uri=file://${user.home}/spring_cloud_config_server
spring.cloud.config.server.git.uri=/home/jimis/_d/GITs/spring_cloud_config_server
spring.cloud.config.server.git.clone-on-start=true
management.security.enabled=true
spring.autoconfigure.exclude=org.springframawork.boot.autoconfigure.SecurityAutoConfiguration
日志:
构建
[test]$ docker build --no-cache --file=Dockerfile --tag=config-server:latest --rm=true .
Sending build context to Docker daemon 30.3MB
Step 1/8 : FROM openjdk:8-jdk-alpine
---> 88d1c219f815
Step 2/8 : MAINTAINER jimis.drpc@gmail.com
---> Running in 7b72f2d1ec23
Removing intermediate container 7b72f2d1ec23
---> 2a98b9e543c6
Step 3/8 : COPY files/config-server-0.0.1-SNAPSHOT.jar /opt/spring-cloud/lib/
---> c8faa6d9894f
Step 4/8 : ENV SPRING_APPLICATION_JSON='{"spring": {"cloud": {"config": {"server": {"git": {"uri": "/home/jimis/_d/GITs/spring_cloud_config_server", "clone-on-start": true}}}}}}'
---> Running in 3dd9f0b7d942
Removing intermediate container 3dd9f0b7d942
---> e138afcae721
Step 5/8 : ENTRYPOINT ["/usr/bin/java"]
---> Running in 796639f2a81c
Removing intermediate container 796639f2a81c
---> 492be6659259
Step 6/8 : CMD ["-jar", "/opt/spring-cloud/lib/config-server-0.0.1-SNAPSHOT.jar"]
---> Running in 036a4958ba3d
Removing intermediate container 036a4958ba3d
---> 9cee8c28dba8
Step 7/8 : VOLUME /var/lib/spring-cloud/config-repo
---> Running in 1f02d9ddc900
Removing intermediate container 1f02d9ddc900
---> abf89d1b2459
Step 8/8 : EXPOSE 8888
---> Running in 3fe0f63d04d8
Removing intermediate container 3fe0f63d04d8
---> 48c63e065b4b
Successfully built 48c63e065b4b
Successfully tagged config-server:latest
运行
[test]$ docker run -ti --rm -d -p 8888:8888 jimis/myapp /bin/sh
76e183ca312a8aea8f83acdd9212aff02bab27c1b4302ef0433e5ad693040824
PS:我希望“ / bin / sh”允许我进入这样的容器,但是没有发生
从邮递员打来的电话
[ test]$ docker logs 76e183ca312a
2019-04-11 14:17:07.320 INFO 1 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$f9c07f94] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.3.RELEASE)
2019-04-11 14:17:07.575 INFO 1 --- [ main] c.m.c.ConfigServerApplication : No active profile set, falling back to default profiles: default
2019-04-11 14:17:09.430 INFO 1 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=11be5ef3-61b1-3539-a246-b6326ba4f12c
2019-04-11 14:17:09.487 INFO 1 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$f9c07f94] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-04-11 14:17:10.075 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8888 (http)
2019-04-11 14:17:10.151 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-04-11 14:17:10.152 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.16]
2019-04-11 14:17:10.176 INFO 1 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/lib/jvm/java-1.8-openjdk/jre/lib/amd64/server:/usr/lib/jvm/java-1.8-openjdk/jre/lib/amd64:/usr/lib/jvm/java-1.8-openjdk/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
2019-04-11 14:17:10.440 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-04-11 14:17:10.441 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2842 ms
2019-04-11 14:17:12.517 INFO 1 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@291a7e3c, org.springframework.security.web.context.SecurityContextPersistenceFilter@63f259c3, org.springframework.security.web.header.HeaderWriterFilter@106cc338, org.springframework.security.web.csrf.CsrfFilter@67d18ed7, org.springframework.security.web.authentication.logout.LogoutFilter@78d6692f, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@6cce16f4, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@600b90df, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@5c2375a9, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@ca30bc1, org.springframework.security.web.session.SessionManagementFilter@6cc558c6, org.springframework.security.web.access.ExceptionTranslationFilter@132e0cc, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@2f67b837]
2019-04-11 14:17:12.742 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-04-11 14:17:13.370 INFO 1 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2019-04-11 14:17:13.821 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8888 (http) with context path ''
2019-04-11 14:17:13.827 INFO 1 --- [ main] c.m.c.ConfigServerApplication : Started ConfigServerApplication in 7.907 seconds (JVM running for 8.818)
2019-04-11 14:17:14.983 INFO 1 --- [nio-8888-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-04-11 14:17:14.983 INFO 1 --- [nio-8888-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2019-04-11 14:17:15.005 INFO 1 --- [nio-8888-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 22 ms
2019-04-11 14:17:15.345 ERROR 1 --- [nio-8888-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Cannot load environment] with root cause
java.lang.IllegalStateException: No directory at file:///root/spring_cloud_config_server
at org.springframework.util.Assert.state(Assert.java:73) ~[spring-core-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
at org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.copyFromLocalRepository(JGitEnvironmentRepository.java:576) ~[spring-cloud-config-server-2.1.1.RELEASE.jar!/:2.1.1.RELEASE]
...