Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker mkdir: cannot create directory ‘/data/db’: Permission denied #10827

Closed
DriftingShadows opened this issue May 20, 2024 · 5 comments
Closed
Assignees
Labels
bug unconfirmed Unconfirmed bug

Comments

@DriftingShadows
Copy link

Describe the bug
On a clean Ubuntu install of 24.04, the following error is shown in the docker logs after following the instructions at here.

mkdir: cannot create directory ‘/data/db’: Permission denied
The files belonging to this database system will be owned by user "thingsboard".
This user must also own the server process.

The database cluster will be initialized with locale "C.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory /data/db ... initdb: error: could not create directory "/data/db": Permission denied
pg_ctl: database system initialization failed
Starting Postgresql...
pg_ctl: directory "/data/db" does not exist
Connecting to Postgres, 300 attempts left...
Connecting to Postgres, 299 attempts left...
Connecting to Postgres, 298 attempts left...

To Reproduce
Steps to reproduce the behavior:

  1. Install docker
  2. Follow instructions to install thingsboard for docker on ubuntu
  3. docker compose up -d
  4. See error

Additional context
Please feel free to add any other context about the problem here.
This issue only occurs when using the mounted volumes for data and logs. I have done the chown -R 799:799 for both folders. I have also followed these instructions. When executing ls -lh to view permissions for the /data folder in the container, it shows the following

drwxrwxr-x   2 nobody nogroup 4.0K May 20 06:42 data
@pon0marev
Copy link

Make sure this command was executed correctly and the owner of folders is 799. 799 is the user ID of thingsboard inside the container.
image

Try to delete and recreate the folders using the command:

mkdir -p ~/.mytb-data && sudo chown -R 799:799 ~/.mytb-data
mkdir -p ~/.mytb-logs && sudo chown -R 799:799 ~/.mytb-logs

@jk4e
Copy link

jk4e commented May 23, 2024

Same error as @DriftingShadows. I have tried several times. Always get this error:

  2024-05-23 21:23:02 mkdir: cannot create directory ‘/data/db’: Permission denied  
  2024-05-23 21:23:02 The files belonging to this database system will be owned by user "thingsboard".  
  2024-05-23 21:23:02 This user must also own the server process.  
  2024-05-23 21:23:02   
  2024-05-23 21:23:02 The database cluster will be initialized with locale "C.UTF-8".  
  2024-05-23 21:23:02 The default database encoding has accordingly been set to "UTF8".  
  2024-05-23 21:23:02 The default text search configuration will be set to "english".
  2024-05-23 21:23:02 
  2024-05-23 21:23:02 Data page checksums are disabled.
  2024-05-23 21:23:02 
  2024-05-23 21:23:02 creating directory /data/db ... initdb: error: could not create directory "/data/db": Permission denied
  2024-05-23 21:23:02 pg_ctl: database system initialization failed
  2024-05-23 21:23:02 Starting Postgresql...
  2024-05-23 21:23:02 pg_ctl: directory "/data/db" does not exist
  2024-05-23 21:23:02 Connecting to Postgres, 300 attempts left...
  2024-05-23 21:23:03 Connecting to Postgres, 299 attempts left...
  2024-05-23 21:23:05 Connecting to Postgres, 298 attempts left...
  2024-05-23 21:23:06 Connecting to Postgres, 297 attempts left...

I have checked the permissions of the folders (with ls -ld):

xxx@xxx:~$ ls -ld .mytb-logs
drwxrwxr-x 2 799 799 4096 May 23 20:51 .mytb-logs
xxx@xxx:~$ ls -ld .mytb-data
drwxrwxr-x 2 799 799 4096 May 23 20:51 .mytb-data

My version of OS and docker:

  • OS: Linux Mint 21.3 Virginia (Ubuntu)
  • Docker version 26.1.3

I have tried:

  • build from docker compose file,
  • Docker Hub: Pull and Run

Maybe someone can help us solve this problem. That would be great. Thanks for your help!

@trikimiki
Copy link
Member

hi!
i have just tested the latest tb-postgres, all should be working as per guide
share your docker compose file

@DriftingShadows
Copy link
Author

Same error as @DriftingShadows. I have tried several times. Always get this error:

  2024-05-23 21:23:02 mkdir: cannot create directory ‘/data/db’: Permission denied  
  2024-05-23 21:23:02 The files belonging to this database system will be owned by user "thingsboard".  
  2024-05-23 21:23:02 This user must also own the server process.  
  2024-05-23 21:23:02   
  2024-05-23 21:23:02 The database cluster will be initialized with locale "C.UTF-8".  
  2024-05-23 21:23:02 The default database encoding has accordingly been set to "UTF8".  
  2024-05-23 21:23:02 The default text search configuration will be set to "english".
  2024-05-23 21:23:02 
  2024-05-23 21:23:02 Data page checksums are disabled.
  2024-05-23 21:23:02 
  2024-05-23 21:23:02 creating directory /data/db ... initdb: error: could not create directory "/data/db": Permission denied
  2024-05-23 21:23:02 pg_ctl: database system initialization failed
  2024-05-23 21:23:02 Starting Postgresql...
  2024-05-23 21:23:02 pg_ctl: directory "/data/db" does not exist
  2024-05-23 21:23:02 Connecting to Postgres, 300 attempts left...
  2024-05-23 21:23:03 Connecting to Postgres, 299 attempts left...
  2024-05-23 21:23:05 Connecting to Postgres, 298 attempts left...
  2024-05-23 21:23:06 Connecting to Postgres, 297 attempts left...

I have checked the permissions of the folders (with ls -ld):

xxx@xxx:~$ ls -ld .mytb-logs
drwxrwxr-x 2 799 799 4096 May 23 20:51 .mytb-logs
xxx@xxx:~$ ls -ld .mytb-data
drwxrwxr-x 2 799 799 4096 May 23 20:51 .mytb-data

My version of OS and docker:

  • OS: Linux Mint 21.3 Virginia (Ubuntu)
  • Docker version 26.1.3

I have tried:

  • build from docker compose file,
  • Docker Hub: Pull and Run

Maybe someone can help us solve this problem. That would be great. Thanks for your help!

I solved the issue. It was related to user namespaces. It seems to be enabled by default when installing docker desktop on ubuntu. For eg. I would need to set permission on host to be 100798 to get 799 ownership in the container.

@trikimiki
Copy link
Member

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unconfirmed Unconfirmed bug
Projects
None yet
Development

No branches or pull requests

5 participants