3

I'm using non-root user on a secured env to run stock DB docker container (elasticsearch). Of course - I want the data to be mounted so I won't lose it when the container is destroyed.

The problem is that this container writes to that volume with root ownership, and then the host doesn't have permissions to move/rm them.

I know that most docker images use root user from inside, but how can I control the file ownership of the hosting machine?

orshachar
  • 4,837
  • 14
  • 45
  • 68

2 Answers2

2

You can create a data container docker create -v /usr/share/elasticsearch/data --name esdata elasticsearch /bin/true, then use it in your container docker run -d --volumes-from esdata --name some-elasticsearch elasticsearch.

This is a prefer data pattern for docker, you can find out more in this docker page.

booyaa
  • 4,437
  • 2
  • 26
  • 32
0

To answer you question use "docker run --user '$(id -u)' ..." it will run program within container with current user id, then you might have the same question as I did.

I answered it in some way I hope it might be useful. Docker with '--user' can not write to volume with different ownership

Community
  • 1
  • 1
Andrey Kartashov
  • 1,368
  • 1
  • 12
  • 20