Docker Postgres Jest: EACCESS Permission denied postgres-data
There are time when the docker volume can be a problem.
Especially when running watch
e.g. jest --watch
throws:
Error: EACCES: permission denied, scandir '/home/development/myproject/postgres-data'
Then we see the problem
drwxr-xr-x. 2 tanut tanut 4.0K Dec 4 21:28 db.sql
drwx------. 19 avahi tanut 4.0K Dec 7 10:27 postgres-data
drwx------. 19 avahi tanut 4.0K Dec 7 10:27 postgres-data
Problem:
- If we do
chgrp
orchown
, Docker cannot read this file anymore - Docker cannot run but when elevated with
sudo
, the command try to revert the change.
Solution:
One way is to mount the volume somewhere outside the repos.
Easier way is to make jest ignore this path by editing jest.config.json
file.
This file is loaded by default. No need to specified in jest
command.
// jest.config.json
{
"testRegex": "((\\.|/*.)(spec))\\.js?$",
"clearMocks": true,
"testEnvironment": "node",
"testPathIgnorePatterns": [
"/node_modules/",
"postgres-data",
"db.sql"
],
"watchPathIgnorePatterns": [
"/node_modules/",
"postgres-data",
"db.sql"
]
}
Leave me some comment if this save your time.
Cheers!