SQLite Forum

Mac M1/Docker/QEMU corrupts database
Login

Mac M1/Docker/QEMU corrupts database

(1.1) By example-user on 2021-09-28 01:25:41 edited from 1.0 [source]

Hello,

My computer is a Mac M1, I have Docker Desktop installed.

I am running a container, sharing a directory from my host to the guest:

docker run --platform -v /m1-host-dir:/vol linux/amd64 ubuntu

When Docker for M1 runs based amd64 containers, I think it uses QEMU to emulate a amd64 CPU on the arm based M1.

This is slow but seems to work for code.

But the issue I have is that there is SQLite code running inside the container, writing to a DB file that should be persisted to the host disk (I assume via some sort of feature to share directories host->QEMU).

I am getting strange results; the process continues as if it can write to the database, but both inside of and outside of the container sqlite3 seems to show a frozen version of the file (not showing the most recent writes). I also get a range of errors.

Is there any way this could work?

I assume it does not work because the way SQLite does locking/wal writes is by using the same OS, and docker for Mac M1 is probably emulating complete second OS with a Linux kernel.

Edit: This seems to be the set up https://news.ycombinator.com/item?id=25454121

(2) By meglio on 2024-01-21 03:33:18 in reply to 1.1 [link] [source]

I experience the same problem with Apple M1 Max.

I'm developing a php app that uses sqlite3. The sqlite file is stored in a folder mounted by Docker into the container. Quite often the file gets corrupted and I have to either reset it or restore from a backup. This happens on a daily basis.

WAL mode ON.

(3) By Warren Young (wyoung) on 2024-01-21 04:25:16 in reply to 1.1 [link] [source]

Is there any way this could work?

Nope.

Scroll up for the test program proving it.