chucklin72's avatar

sail sqlite file not found

from my docker-compose.yml

sqlite3:
    image: nouchka/sqlite3:latest
    stdin_open: true
    tty: true
    volumes:
      - ./db/:/root/db/

I actually have this working in one instance, but cannot get it to work again.

I have tried:

config:clear

numerous sail build --no-cache

touched a blank file

in .env

DB_DATABASE="../db/database.sqlite"

touched database.sqlite in all database paths

blew away vendor/

copied a working database.sqlite file into the path

tried DB_DATABASE with full path

restarted Docker

All result in

Database (../db/database.sqlite) does not exist. (SQL: PRAGMA foreign_keys = ON;)

Docker Compose version v2.10.2

Laravel 9.22.1

PHP 8.1.10

0 likes
12 replies
rodrigo.pedra's avatar

What is the base path of your application?

Depending on the base path this line could require either a second ../ or a different path.

DB_DATABASE="../db/database.sqlite"
chucklin72's avatar

@rodrigo.pedra The absolute weirdest part is "db/databse.sqlite" worked to do a sail artisan migrate but from the browser I get an error saying the file was not found. So sail was able to resolve the network but docker container was not able to find the correct path. Then I changed it back to "../db/database.sqlite" and that worked.

rodrigo.pedra's avatar

@chucklin72

Well, if you can share it is the base absolute path, inside docker, it will be easier to help.

Also you can try providing the absolute path to the database fie, which from the configuration you shared so far would be:

DB_DATABASE="/root/db/database.sqlite"

With no dots, or relative paths.

1 like
chucklin72's avatar

@rodrigo.pedra

# For more information: https://laravel.com/docs/sail
version: '3'
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.1
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.1/app
        extra_hosts:
            - 'host.docker.internal:host-gateway'
        ports:
            - '${APP_PORT:-80}:80'
            - '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
            XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
            XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
        volumes:
            - '.:/var/www/html'

        networks:
            - sail
        depends_on:
            - sqlite3
    mailhog:
        image: 'mailhog/mailhog:latest'
        ports:
            - '${FORWARD_MAILHOG_PORT:-1025}:1025'
            - '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
        networks:
            - sail
    sqlite3:
        image: nouchka/sqlite3:latest
        stdin_open: true
        tty: true
        volumes:
            - './db/:/root/db/'
networks:
    sail:
        driver: bridge
volumes:
    sqlite3:
        driver: local
chucklin72's avatar

I made docker-compose.yml

    sqlite3:
        image: nouchka/sqlite3:latest
        stdin_open: true
        tty: true
        volumes:
            - '/var/www/html/db/:/root/db/'

that seems to work.

chucklin72's avatar

@rodrigo.pedra thanks! That gave me something else to try that worked.

    sqlite3:
        image: nouchka/sqlite3:latest
        stdin_open: true
        tty: true
        volumes:
            - '/var/www/html/db/:/root/db/'

also set DB_DATABASE = "/var/www/html/db/database.sqlite" in .env

rodrigo.pedra's avatar

@chucklin72 try

DB_DATABASE=./db/database.sqlite

Illuminate\Database\Connectors\SQLiteConnector uses PHP's realpath() function to find the absolute path.

I thought using the absolute path from within the docker volume should work, the code above is trying to resolve from your local path

rodrigo.pedra's avatar

Wait a minute... you are downloading a different image for sqlite... does it create a new volume?

That is why /root/db/ is not available on the web/application container.

Why are you spinning up a different container just for SQLite?

If your PHP's image inside your web/application container have the php-sqlite module installed, sqlite is then embedded in PHP.

Do as a regular Laravel application, create the file ./database/database.sqlite inside your project's directory, and you should be good to go.

If you really want to use a folder name ./db/ inside your project's structure, just create the /db/ directory and a blank file named database.sqlite inside of it.

The blank file must exist before migrating. in Linux/macOS you can use the touch CLI command to create a blank file.

Then you can even remove this nouchka/sqlite3 container from your docker-compose file.

1 like
chucklin72's avatar

this worked: DB_DATABASE="db/database.sqlite"

1 like
chucklin72's avatar

It would seem that sail artisan migrate:status runs from inside the container so .env DB_DATABASE needs to be "db/database.sqlite"

However, the app runs from public/ so DB_DATABASE needs to to be "../db/database.sqlite"

If I create a symlink from public db to ../db then I risk exposing database.sqlite to the world.

Anyone know how I can solve this?

onovaes's avatar

I used DB_DATABASE=/var/www/html/database/database.sqlite (full path inside container)

and worked with artisan and web application

1 like

Please or to participate in this conversation.