Solucionado (ver solução)

Importante

Você está vendo a versão anterior da nova experiência da Alura que estamos preparando para você. Em breve, ela ganha uma identidade visual novinha totalmente pensada em potencializar seus estudos!

Solucionado
(ver solução)
11
respostas

[Bug] Erro ao subir docker

![](Insira aqui a descrição dessa imagem para ajudar na acessibilidade )

docker-compose-yaml

services:
  mysql:
    image: mysql:8.0.36
    env_file: ./env/mysql.env
    volumes:
      - ./mysql-data:/var/lib/mysql
    restart: unless-stopped
    healthcheck:
      test: mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD
      interval: 5s
      timeout: 5s
      retries: 10

  app:
    build:
      context: .
    env_file: ./env/app.env
    restart: unless-stopped
    depends_on:
      mysql:
        condition: service_healthy

volumes:
  mysql-data:

Dockerfile

FROM eclipse-temurin:17-jdk-alpine as builder
WORKDIR application
COPY mvnw .
COPY .mvn .mvn
COPY pom.xml .
COPY src src
RUN ./mvnw package -DskipTests
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} application.jar
RUN java -Djarmode=layertools -jar application.jar extract

FROM eclipse-temurin:17-jre-alpine
WORKDIR application
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/application/ ./
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]

app.env

SPRING_PROFILES_ACTIVE=prod
SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/codechella
SPRING_DATASOURCE_USERNAME=codechella_user
SPRING_DATASOURCE_PASSWORD=codechella_pwd
MAIL_HOST=smtp.gmail.com
MAIL_USER=mail_user
MAIL_PASSWORD=mail_pwd
APP_JWT_SECRET=jwt_secret

mysql.env

MYSQL_RANDOM_ROOT_PASSWORD=true
MYSQL_DATABASE=codechella
MYSQL_USER=codechella_user
MYSQL_PASSWORD=codechella_pwd
11 respostas

Oi!

Manda o log aqui que saiu no console:

Insira aqui a descrição dessa imagem para ajudar na acessibilidade

encontrei esse erro na classe Insira aqui a descrição dessa imagem para ajudar na acessibilidade

log


Attaching to app-1, mysql-1
mysql-1  | 2024-07-23 20:05:37+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.37-1debian12 started.
mysql-1  | 2024-07-23 20:05:38+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql-1  | 2024-07-23 20:05:38+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.37-1debian12 started.
mysql-1  | mysqld: [Warning] World-writable config file '/etc/mysql/my.cnf' is ignored.                                                                                                                                             
mysql-1  | 2024-07-23T20:05:38.538543Z 0 [Warning] [MY-010101] [Server] Insecure configuration for --secure-file-priv: Location is accessible to all OS users. Consider choosing a different directory.
mysql-1  | 2024-07-23T20:05:38.538634Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.37) starting as process 1
mysql-1  | 2024-07-23T20:05:38.545107Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive                                                                
mysql-1  | 2024-07-23T20:05:38.589294Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysql-1  | 2024-07-23T20:05:39.050425Z 1 [ERROR] [MY-012960] [InnoDB] Cannot create redo log files because data files are corrupt or the database was not shut down cleanly after creating the data files.
mysql-1  | 2024-07-23T20:05:39.050500Z 1 [ERROR] [MY-012930] [InnoDB] Plugin initialization aborted with error Generic error.
mysql-1  | 2024-07-23T20:05:39.416219Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine                                                                                                                        
mysql-1  | 2024-07-23T20:05:39.416509Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
mysql-1  | 2024-07-23T20:05:39.416580Z 0 [ERROR] [MY-010119] [Server] Aborting                                                                                                                                                      
mysql-1  | 2024-07-23T20:05:39.417813Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.37)  MySQL Community Server - GPL.
Gracefully stopping... (press Ctrl+C again to force)                                                                                                                                                                                
[+] Stopping 1/0
 ✔ Container 3700-arquitetura-java-aula_1-app-1    Stopped                                                                                                                                                                     0.0s 
 - Container 3700-arquitetura-java-aula_1-mysql-1  Stopping                                                                                                                                                                    0.1s 
dependency failed to start: container 3700-arquitetura-java-aula_1-mysql-1 is unhealthy

segue o meu git https://github.com/gbrazdev/3700-arquitetura-java

A princípio é algum erro com o container do MySQL. Apague a pasta mysal-data do seu computador e tente subir o compose novamente.

fiz, e deletei os containers, volumes e imagens, continua o erro.

refiz o projeto do zero e nada feito, novo repositorio no git: https://github.com/gbrazdev/Arquitetura-Java

O problema é no container do MySQL e não no projeto.

Roda esses comandos para apagar os volumes e imagem mysql:

docker volume prune
docker system prune
docker rmi mysql

E tente novamente

redei os comandos continua o mesmo erro, ate mudei a versão do mysql p ver se era algum erro na imagem.

[+] Running 3/3
 ✔ Network arquitetura-java_default    Created                                                                                                                                                                                 0.2s 
 ✔ Container arquitetura-java-mysql-1  Created                                                                                                                                                                                11.2s 
 ✔ Container arquitetura-java-app-1    Created                                                                                                                                                                                 0.9s 
Attaching to app-1, mysql-1
mysql-1  | 2024-07-24 17:40:37+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 9.0.1-1.el9 started.
mysql-1  | 2024-07-24 17:40:38+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql-1  | 2024-07-24 17:40:38+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 9.0.1-1.el9 started.
mysql-1  | 2024-07-24 17:40:38+00:00 [Note] [Entrypoint]: Initializing database files
mysql-1  | 2024-07-24T17:40:38.544581Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
mysql-1  | 2024-07-24T17:40:38.546801Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 9.0.1) initializing of server in progress as process 81
mysql-1  | 2024-07-24T17:40:38.557322Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive                                                                
mysql-1  | 2024-07-24T17:40:38.623410Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.                                                                                                                           
mysql-1  | 2024-07-24T17:40:45.568503Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql-1  | 2024-07-24T17:41:04.858112Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
mysql-1  | 2024-07-24T17:41:24.585393Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
mysql-1  | 2024-07-24 17:41:24+00:00 [Note] [Entrypoint]: Database files initialized
mysql-1  | 2024-07-24 17:41:24+00:00 [Note] [Entrypoint]: Starting temporary server
mysql-1  | 2024-07-24T17:41:24.710696Z 0 [System] [MY-015015] [Server] MySQL Server - start.                                                                                                                                        
mysql-1  | 2024-07-24T17:41:24.950977Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 9.0.1) starting as process 176
mysql-1  | 2024-07-24T17:41:24.958155Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive                                                                
mysql-1  | 2024-07-24T17:41:25.000831Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.                                                                                                                           
Gracefully stopping... (press Ctrl+C again to force)
[+] Stopping 1/0
 ✔ Container arquitetura-java-app-1    Stopped                                                                                                                                                                                 0.0s 
 - Container arquitetura-java-mysql-1  Stopping                                                                                                                                                                                0.1s 
dependency failed to start: container arquitetura-java-mysql-1 is unhealthy
solução!

Agora não deu mais os logs de erro.

Pelo log agora você está apertando CTRL + C, que força os container a pararem.

fiz o teste subindo apenas o container mysql e subiu

PS D:\Documents\GABRIEL\cursos\java\Alura\Arquitetura Java\Arquitetura-Java> docker compose up --build
time="2024-07-24T14:47:20-03:00" level=warning msg="D:\\Documents\\GABRIEL\\cursos\\java\\Alura\\Arquitetura Java\\Arquitetura-Java\\compose.yaml: `version` is obsolete"
[+] Running 0/0
 - Network arquitetura-java_default  Creating                                                                                                                                                                                  0.1s 
[+] Running 2/24T14:47:20-03:00" level=warning msg="Found orphan containers ([arquitetura-java-app-1]) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orp
 ✔ Network arquitetura-java_default    Created                                                                                                                                                                                 0.1s 
 ✔ Container arquitetura-java-mysql-1  Created                                                                                                                                                                                 0.3s 
Attaching to mysql-1
mysql-1  | 2024-07-24 17:47:21+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 9.0.1-1.el9 started.
mysql-1  | 2024-07-24 17:47:21+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql-1  | 2024-07-24 17:47:21+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 9.0.1-1.el9 started.
mysql-1  | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'                                                                                                                                                             
mysql-1  | 2024-07-24T17:47:22.194439Z 0 [System] [MY-015015] [Server] MySQL Server - start.
mysql-1  | 2024-07-24T17:47:22.462879Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 9.0.1) starting as process 1
mysql-1  | 2024-07-24T17:47:22.469704Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive                                                                
mysql-1  | 2024-07-24T17:47:22.497280Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.                                                                                                                           
mysql-1  | 2024-07-24T17:47:26.319341Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql-1  | 2024-07-24T17:47:30.091777Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
mysql-1  | 2024-07-24T17:47:30.092570Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
mysql-1  | 2024-07-24T17:47:30.134385Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.       
mysql-1  | 2024-07-24T17:47:30.177744Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
mysql-1  | 2024-07-24T17:47:30.177955Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '9.0.1'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.
                                                                                                                                                                                                                        

passou da parte do mysql agora ponta esse erro:

app-1    | 2024-07-24T19:51:04.718Z ERROR 1 --- [           main] o.s.b.web.embedded.tomcat.TomcatStarter  : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'securityFilter' defined in file [/application/BOOT-INF/classes/br/com/alura/codechella/infra/security/SecurityFilter.class]: Unsatisfied dependency expressed through constructor parameter 1: Error cr
eating bean with name 'usuarioRepository' defined in br.com.alura.codechella.domain.autenticacao.repository.UsuarioRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaSharedEM_entityManagerFactory' while setting bean property 'entityManager'