[英]Access to Sqlite database during create docker app using Entity Framework
I have a .NET Core app that is using Entity Framework with a Sqlite database. 我有一个.NET Core应用程序,它将Entity Framework与Sqlite数据库一起使用。
Right now, the app is creating the database using name in appsettings.json
during startup of the application. 现在,该应用程序正在启动应用程序时使用
appsettings.json
中的名称创建数据库。
I want to use previously created database file (with .db
extension). 我想使用以前创建的数据库文件(
.db
名为.db
)。 I copied database file to app, changed name in appsettings.json
. 我将数据库文件复制到app,在
appsettings.json
更改了名称。
This file is a fully created database. 该文件是一个完全创建的数据库。 I copied it from running docker container.
我从运行docker容器复制了它。
But when I run docker-compose image, then app is started, but database file are overwritten. 但是当我运行docker-compose image时,应用程序启动了,但是数据库文件被覆盖了。
How I can omit creating database process and use previously created database? 如何省略创建数据库过程并使用以前创建的数据库?
This is my docker-compose file. 这是我的docker-compose文件。 Frontend part is omitted due to backend tests
由于进行了后端测试,因此省略了前端部分
version: '3.7'
services:
backend:
build: './backend'
ports:
- "80:80"
networks:
- gateway
environment:
- Logger:FilePath=//logs//logs.txt
- Database:Name=Data Source = ./database.db
volumes:
- type: bind
source: /Users/grzegorzogrodowski/Desktop/logs
target: /app/logs/
#frontend:
# build: './frontend'
# depends_on:
# - backend
# ports:
# - "4200:4200"
# networks:
# - gateway
networks:
gateway: {}
使用'docker-compose down --rmi all'命令,因为它会删除保存的图像,并且在您运行docker-compose up命令时,它将使用新数据上传另一个图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.