Docker Postgres Jest: EACCESS Permission denied postgres-data

Docker Jul 5, 2023

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

Problem:

  1. If we do chgrp or chown, Docker cannot read this file anymore
  2. 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!

Tags

TeamCMD

We are CODEMONDAY team and provide a variety of content about Business , technology, and Programming. Let's enjoy it with us.