We are running two container one is from Python flask and the other one is ExpressJS, we have created a docker volume manually docker volume create --name localdb
, this volume runs fine with python app where I have created docker-compose and defined volume as external true.
We have inserted some data from Python and the records are exit, so we are trying to read the existing data from lacaldb/reviews.db
But it does not works for direct access via Docker run for ExpressJs App
Docker command:
docker container run -v localdb:/database --name dcserver --rm localserver:v1
Using nodeJs v12
and ExpressJs
with SQlite3
for data storage, create Docker volume for Sqlite database, We have created the volume manually using docker command, and trying to access it via docker run
command but getting an error.
Error:
[Error: SQLITE_CANTOPEN: unable to open database file
Emitted 'error' event on Database instance at:
] {
errno: 14,
code: 'SQLITE_CANTOPEN'
}
Sample NodeJs Script:
var sqlite3 = require('sqlite3').verbose()
var db = new sqlite3.Database(process.env.LOCAL_DB_PATH)
console.log(process.env.LOCAL_DB_PATH) // Prints "/localdb/reviews.db"
async function getReviews(){
db.all(`SELECT * from REVIEWS`, [], function(err, res) {
if (err) {
console.log(err.message)
}
console.log(res)
})
}
export default getReviews
Inspected localdb volume:
$ docker volume inspect localdb
[
{
"CreatedAt": "2020-04-03T17:01:29Z",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/localdb/_data",
"Name": "localdb",
"Options": {},
"Scope": "local"
}
]
docker-compose.yml // here runs fine
version: "3.7"
services:
flask:
build: ./flask
container_name: flask
restart: always
environment:
- APP_NAME=myFlaskApp
expose:
- 8080
volumes:
- localdb:/database
nginx:
build: ./nginx
container_name: nginx
restart: always
ports:
- "80:80"
volumes:
localdb:
external: true