【发布时间】:2020-01-09 15:06:03
【问题描述】:
我有一个使用 sqlite 的 Spring Boot 应用程序。当我尝试创建容器时出现异常
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [clients]
容器似乎无法访问数据库文件。
文件结构是
Dockerfile
FROM openjdk:8
ADD project-app.jar project-app.jar
ADD mydb.db mydb.db
ENTRYPOINT ["java","-jar","project-app.jar"]
EXPOSE 8082
docker-compose.yml
version: '3.3'
services:
project-app:
build: ./
image: project-app:1.0
restart: always
container_name: project-app
ports:
- 8082:8082
volumes:
- /var/run/docker.sock:/var/run/docker.sock
network_mode: bridge
我尝试像容器一样添加 sqlite,我还尝试在 docker-compose.yml 上复制 MySQL 配置,但仍然遇到相同的异常。
编辑:探索容器后,数据库文件似乎存在 mydb.db 但它是空的,这意味着 Dockerfile 不会复制数据库。
4 drwxr-xr-x 1 root root 4096 Sep 6 18:27 .
4 drwxr-xr-x 1 root root 4096 Sep 6 18:27 ..
0 -rwxr-xr-x 1 root root 0 Sep 6 18:27 .dockerenv
4 drwxr-xr-x 1 root root 4096 Aug 14 11:23 bin
4 drwxr-xr-x 2 root root 4096 Mar 28 09:12 boot
0 drwxr-xr-x 5 root root 340 Sep 6 18:57 dev
4 drwxr-xr-x 1 root root 4096 Sep 6 18:27 etc
4 drwxr-xr-x 2 root root 4096 Mar 28 09:12 home
4 drwxr-xr-x 1 root root 4096 Aug 12 00:00 lib
4 drwxr-xr-x 2 root root 4096 Aug 12 00:00 lib64
4 drwxr-xr-x 2 root root 4096 Aug 12 00:00 media
4 drwxr-xr-x 2 root root 4096 Aug 12 00:00 mnt
4 drwxr-xr-x 2 root root 4096 Aug 12 00:00 opt
0 dr-xr-xr-x 145 root root 0 Sep 6 18:57 proc
4 drwx------ 1 root root 4096 Aug 14 11:25 root
4 drwxr-xr-x 1 root root 4096 Sep 6 18:27 run
4 drwxr-xr-x 1 root root 4096 Aug 14 06:24 sbin
46260 -rwxr-xr-x 1 root root 47367833 Sep 6 17:02 project-app.jar
0 -rw-r--r-- 1 root root 0 Sep 6 18:27 mydb.db
4 drwxr-xr-x 2 root root 4096 Aug 12 00:00 srv
0 dr-xr-xr-x 13 root root 0 Sep 6 18:57 sys
4 drwxrwxrwt 1 root root 4096 Sep 6 18:57 tmp
4 drwxr-xr-x 1 root root 4096 Aug 12 00:00 usr
4 drwxr-xr-x 1 root root 4096 Aug 12 00:00 var
【问题讨论】:
-
1.尝试 COPY 而不是 ADD 2. 使用
privileged标志授予 root 权限。 -
还要检查你的主机中
mydb.db的权限 -
@Rash 成功了,如果你愿意,你可以把它写成答案。
标签: java sqlite spring-boot docker docker-compose