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

chown: changing ownership of '/var/...': Operation not permitted #796

Closed
sfl0r3nz05 opened this issue Dec 7, 2020 · 4 comments
Closed
Labels
question Usability question, not directly related to an error with the image

Comments

@sfl0r3nz05
Copy link

sfl0r3nz05 commented Dec 7, 2020

Hi,

I am deploying the docker postgres as part of a docker-compose, using a volume (data-volume) to export a .csv file, which is sent to elasticsearch via logstash. When I try to copy a query row to this file via:

const rows = await db.query(COPY (SELECT * FROM tokenoffchain WHERE id = (SELECT MAX(id) FROM tokenoffchain)) TO '${process.env.PATH_ELK_CSV}' WITH CSV DELIMITER ',' HEADER ESCAPE '\n' );

, I get a write permission error. So I create the "docker-entrypoint.sh" and pass it through volume as the figure shown.

image

Considering that I have set both POSTGRES_USER and POSTGRES_PASSWORD as environment variables, I am not clear why I cannot change the property or enable the permissions on the .csv file if the docker-entrypoint.sh is:

image

At this moment, I'm setting the permission manually.

Thanks in advance,

Santiago.

@wglambert wglambert added the question Usability question, not directly related to an error with the image label Dec 7, 2020
@wglambert
Copy link

The POSTGRES_USER variable is for the database not for the user in the container

You can also run as an arbitrary user or UID which you could then set any local files/folders to match that arbitrary user
https://github.com/docker-library/docs/tree/master/postgres#arbitrary---user-notes

@sfl0r3nz05
Copy link
Author

@wglambert thanks for the response.

I have tried via:

  1. Adding: ALTER ROLE postgres SUPERUSER; as part of my init.sql in order to set postgres as SUPERUSER.
  2. Including "--name" and "postgres" as entrypoint in the docker-compose.

But fail in both cases. Do you know another way to do that?

In additon, I have not found an environmental variable for this purpose.

Thanks in advance.

Santiago.

@tianon
Copy link
Member

tianon commented Dec 7, 2020

The entrypoint initdb scripts don't ever run as root, so chown/chmod won't work there and if you need files with different ownership, you'll need to do that before the entrypoint runs (preferably on the host directly, but you could also do something like docker run ... sh -c 'chown ... && chmod ... && exec docker-entrypoint.sh ...'.

@sfl0r3nz05
Copy link
Author

Thanks @tianon, since I need to use docker-compose y have tried passing "sh -c 'chown ... && chmod ..." via command, creating the volume (- data-volume:/var/local) before, but it fail until now. I will continue setting permissions manually, until I found a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usability question, not directly related to an error with the image
Projects
None yet
Development

No branches or pull requests

3 participants