sixeyed / diamol

Code samples for the book "Learn Docker in a Month of Lunches"
https://www.manning.com/books/learn-docker-in-a-month-of-lunches
Creative Commons Attribution Share Alike 4.0 International
496 stars 261 forks source link

Chapter 04 - image-of the-day #65

Open whiskeyo opened 7 months ago

whiskeyo commented 7 months ago

Exercise ch04/image-of-the-day

Problem Running the application image-of-the-day by calling the docker container run --name iotd -d -p 800:80 --network nat image-of-the-day with previously configured network by docker network create nat fails with the exception. The full output of docker container logs iotd:

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

2023-12-04 22:17:37.785  INFO 1 --- [           main] iotd.Application                         : Starting Application v0.1.0 on a10ca690612c with PID 1 (/app/iotd-service-0.1.0.jar started by root in /app)                                              
2023-12-04 22:17:37.787  INFO 1 --- [           main] iotd.Application                         : No active profile set, falling back to default profiles: default
2023-12-04 22:17:37.946  WARN 1 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed t
o parse configuration class [iotd.Application]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'imageController' for bean class [iotd.ImageController] conflicts with existi
ng, non-compatible bean definition of same name and class [iotd.controllers.ImageController]                                 
2023-12-04 22:17:38.196 ERROR 1 --- [           main] o.s.boot.SpringApplication               : Application run failed                                

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [iotd.Application]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'imag
eController' for bean class [iotd.ImageController] conflicts with existing, non-compatible bean definition of same name and class [iotd.controllers.ImageController]
        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181) ~[spring-context-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:315) ~[spring-context-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232) ~[spring-context-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275) ~[spring-context-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95) ~[spring-context-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:705) ~[spring-context-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531) ~[spring-context-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.3.RELEASE.jar!/:2.1.3.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.3.RELEASE.jar!/:2.1.3.RELEASE]                                                                                                                 
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.3.RELEASE.jar!/:2.1.3.RELEASE]                                                                                                          
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.3.RELEASE.jar!/:2.1.3.RELEASE]                                                                                                                     
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.1.3.RELEASE.jar!/:2.1.3.RELEASE]                                                                                                                    
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.1.3.RELEASE.jar!/:2.1.3.RELEASE]                                                                                                                    
        at iotd.Application.main(Application.java:18) ~[classes!/:0.1.0]                                                     
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]                           
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:na]                           
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:na]                       
        at java.base/java.lang.reflect.Method.invoke(Unknown Source) ~[na:na]                                                
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) ~[iotd-service-0.1.0.jar:0.1.0]                                                                                                                                  
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) ~[iotd-service-0.1.0.jar:0.1.0]                 
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) ~[iotd-service-0.1.0.jar:0.1.0]                 
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) ~[iotd-service-0.1.0.jar:0.1.0]                                                                                                                                           
Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'imageController' for bean class [iotd.ImageController] conflicts with existing, non-compatible bean definition of same name and class
 [iotd.controllers.ImageController]                           
        at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.checkCandidate(ClassPathBeanDefinitionScanner.java:348) ~[spring-context-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
        at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:286) ~[spring-context-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
        at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:132) ~[spring-context-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:287) ~[spring-context-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242) ~[spring-context-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:199) ~[spring-context-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167) ~[spring-context-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
        ... 21 common frames omitted

Docker version

Client:
 Version:           20.10.24+dfsg1
 API version:       1.41
 Go version:        go1.19.8
 Git commit:        297e128
 Built:             Thu May 18 08:38:34 2023
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          20.10.24+dfsg1
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.19.8
  Git commit:       5d6db84
  Built:            Thu May 18 08:38:34 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.20~ds1
  GitCommit:        1.6.20~ds1-1+b1
 runc:
  Version:          1.1.5+ds1
  GitCommit:        1.1.5+ds1-1+b1
 docker-init:
  Version:          0.19.0
  GitCommit:   

Code version

commit 71384f8c09a8e0b3867a2c73ae09549774a21e85 (HEAD -> master, origin/master, origin/HEAD)

Additional context Nothing :)

davelnewton commented 5 months ago

@whiskeyo Yep, don't know how it ever worked.

Fixed it locally then discovered a PR already exists. Should resolve the issue.