1

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
151291
  • 3,308
  • 7
  • 48
  • 81
  • 1
    You'll probably have a little more luck using a server-based database like PostgreSQL or MySQL; it will run in a separate container and you won't have to deal with the complexities of Docker filesystem sharing. – David Maze Apr 03 '20 at 17:15
  • @DavidMaze, Due to system performance issues, we are using sqlite3, sqlite3 will not consume more CPU process right? – 151291 Jul 21 '20 at 12:13
  • @DavidMaze, how better is `sequelize` – 151291 Jul 21 '20 at 12:18
  • It might help you work in a dual-stack environment where you use SQLite for unit tests and a server-based relational database in Docker. On its own it won't address the data storage problem, it's a question of what database you choose to put behind it. – David Maze Jul 21 '20 at 14:38

0 Answers0