dinedal / textql

Execute SQL against structured text like CSV or TSV
MIT License
9.05k stars 300 forks source link

Cannot spawn a Docker container running as unprivileged user #112

Open xi-ao opened 5 years ago

xi-ao commented 5 years ago

The advice of creating such an alias in the README is really good and works well:

alias textql='docker run --rm -it -v $(pwd):/tmp textql '

but the problem with it is that it runs textql as root and so the output files are created with that user.

Ideally, the solution would be to use this command instead:

alias textql='docker run --rm --user $(id -u):$(id -g) -it -v $(pwd):/tmp textql '

which works fine when called like this

textql
(...usage shown...)

but not when an actual SQL processing is requested:

textql -sql 'SELECT * FROM groups LIMIT 2' groups.csv
2019/02/12 07:26:44 user: unknown userid 1000

Is there a way to fix that?

supriya commented 3 years ago

@xi-ao Perhaps the change can be as simple as adding a new user in the dockerfile like RUN useradd app USER app

and then you can run docker run --rm -u app:app -it -v $(pwd):/tmp textql -header -sql "select count() from test" test.csv

Let me if this solution looks good to you. I can open a PR.