Hello, @Pablo Schor !
Why am I running into a wrong ownership
/ server must be started by the user that owns the data directory
error when creating a PostgreSQL container instance with Azure Container Instances?
This is a bit of a gray area as the error you are running into is a PostgreSQL error rather than an ACI error so as a quick disclaimer, I should point out that PostgreSQL is not my area of expertise. Having said that, we did speak with the database team who reminded us that Azure Database for PostgreSQL may be a good solution for this scenario with less overhead. If you are still interested in trying to run this on ACI, I'll do my best to point you in the right direction however it is not recommended.
Encountering wrong ownership
/ server must be started by the user that owns the data directory
is a common PostgreSQL issue that stems from the root folder location requirement which conflicts with the dependency Azure Container Instances (ACI) has on Azure FileShares for their volume mounts.
While there are workarounds, they are not generally advised. I've reached out directly to the ACI team for official guidance regarding PostgreSQL on ACI and will let you know if I learn more.
From Rich Kurtzman's blog, Why you should use Azure Database for PostGreSQL storage:
Azure Container Instances is not a Solution Azure Container Instances (ACI) is a service provided by Microsoft Azure that allows users to easily run containers in the cloud without the need to manage any underlying infrastructure. Unfortunately, you can’t just use Azure Container Instances as a storage option for a PostgreSQL database. PostgreSQL requires the folder in which the volume is mounted to be owned by a different user, not the “root” user. Azure Container Instances must use Azure FileShares as their volume mounts, and these do NOT support the "chown" command for changing ownership. That’s why you can’t simply use Azure Container Instances as a storage option. While you could potentially use Azure Container Instances to host a PostgreSQL database by building a custom container image that includes PostgreSQL, this would not be a recommended production deployment target because you would be responsible for managing the database infrastructure yourself.
From Charles Xu on Stack Overflow:
This is a known error for mounting Azure File Share to Azure Container Instance. Currently, it does not support to change the ownership of the mount point. If you do not want to use other services, then you need to create a script to move the data to the mount point and the mount point should be a new folder that does not exist in the image. For you, the mount point
/var/lib/postgresql/data
exists in the image and contains the files that Postgresql depends on, then this point cannot be the mount point.
I hope this helps!
Resources:
- Blog: Why you should use Azure Database for PostGreSQL storage
- What is Azure Database for PostgreSQL flexible server?
- (Stack Overflow) Deploying Postgres database on azure Container Instance?
- (Stack Overflow) Postgresql raises 'data directory has wrong ownership' when trying to use volume
- (Stack Overflow) Storing Docker PostgreSQL data to an Azure Storage Account
- (Docker) Data directory “/var/lib/postgresql/data/pgdata” has wrong ownership