简体   繁体   English

将 Docker Sqlite 容器连接到 Java

[英]Connecting Docker Sqlite container to Java

I just can't find the correct information on the web.我只是在网上找不到正确的信息。

I plan to run sqlite with Docker so that the information can be persisted to a local volume.我计划使用 Docker 运行 sqlite,以便将信息持久化到本地卷。 My Dockerfile is我的 Dockerfile 是

FROM alpine:3.14
RUN apk add --update sqlite
RUN mkdir /db
WORKDIR /db
ENTRYPOINT ["sqlite3"]
CMD ["mydb.db"]

docker run -p 5000:5000 -v `passwd`:/db my-sqlite mydb.db

How do I mount this to a volume, so that data is persisted to the disk?如何将其安装到卷上,以便将数据保存到磁盘? Now I need the connection string - to connect from a Java project.现在我需要连接字符串 - 从 Java 项目连接。 What will this be ?这会是什么? I want to load up data from this db on starting the program, how would this be done?我想在启动程序时从这个数据库加载数据,这将如何完成?

You're having a big misconception about sqlite.你对sqlite有很大的误解。 Sqlite is an embedded database - that means it doesn't need a server to run but rather runs in the application. Sqlite 是一个嵌入式数据库——这意味着它不需要服务器来运行,而是在应用程序中运行。

Therefore you need to mount the *.db file into your application's container and use the JDBC driver of sqlite in order to use the database.因此,您需要将*.db文件挂载到应用程序的容器中,并使用 sqlite 的 JDBC 驱动程序才能使用数据库。

As far as I know, sqlite doesn't even support any sort of remote connection because that's not what it was made for.据我所知,sqlite 甚至不支持任何类型的远程连接,因为这不是它的目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM