-
Notifications
You must be signed in to change notification settings - Fork 445
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
Working directory not writable after setting dockerChmodType
#1402
Comments
Thanks @manuzhang for this issue 😃 This sounds more like a configuration issue on your end. You need to change the user if you want the directory inside the containers to be owned by some other user Docker / daemonUser := "your-user" See https://sbt-native-packager.readthedocs.io/en/latest/formats/docker.html#environment-settings for more details for environmental settings 😊 |
Even if I add
The directory
|
Are you looking inside or outside the container? |
Inside the container and I want to create a file under
|
Thanks for the Dockerfile. It looks like there's still root being used. Whenever this issue comes up I tend to ask what you are trying to achieve? Usually it's one of the following
|
My server needs to generate a Besides, it looks weird to have a working directory owned by root rather than the current user. |
Why does mounting a volume not work?
I find docker most of the time weird 😂 However we apply this principle to all formats. Least amount of privileges as possible. The start scripts are executable and the rest is readable. Especially in container environments write access is most of the time unnecessary. |
That should work. I tried to follow the doc but it appears not accurate. |
Can you share what you have tried? |
https://github.com/manuzhang/akka-http-petstore/blob/docker/build.sbt#L32
|
But how do you start your container. How do you actually mount an external volume? |
I'm not mounting any external volume. |
Hey, this issue is closed but I still find the behavior weird and inconsistent. Running into the same issue. Inside the container, in the working directory I cannot:
yet i can
where bin is a folder that is in my working directory. I get your point of restricting the permissions, but its called a working directory for a reason. Its not a solution to mount a volume on the files that the application might want to create, as that is an unknown set, sometimes even an infinite set (for example logs). Its possible to work around this, but I doubt that this is intended behavior. Workaround, something like (change your working directory):
|
@witzatom Thanks for this, and agreed; servers may need write access to the working directory for a variety of reasons. In my case, we log to both a file and an external service so that we can monitor logs with zero latency via files when needed. Here's the complete workaround for anyone else who needs this: // Give the run user access to the working directory before switching away from ROOT
// https://github.com/sbt/sbt-native-packager/issues/1402
dockerCommands := dockerCommands.value.flatMap {
case Cmd("USER", "1001:0") =>
Seq(
Cmd("RUN", "chown -R 1001:0 /opt/docker"),
Cmd("USER", "1001:0"),
)
case cmd => Seq(cmd)
} |
sbt-native-packager 1.10.4 is concluding the Dockerfile with the following now (12-nov-2024):
But the real issue is that Write permission is not set for the directories and files even for the user/owner. |
Thanks for sharing 😊 I'm still not sure how to act on this one. There is a test covering various permission types: https://github.com/sbt/sbt-native-packager/tree/main/src/sbt-test/docker/file-permission/changes From my experience running docker images, we faced no need for write access inside the container itself. As mentioned above
The various permission strategies are layed out here: https://github.com/sbt/sbt-native-packager/blob/main/src/main/scala/com/typesafe/sbt/packager/docker/DockerPermissionStrategy.scala |
It's easy to work around by injecting the RUN chmod -R 777 command into the Dockerfile. It is interesting that there is not a DockerChmodType for UserGroupReadWriteExecute. The use case is that our running app wants to create a RUNNING_PID file in its cwd. |
That's a classic 😁 I assume you are using playframework. The PID file is a very ancient technique and not really useful in containerized environments. Here's the playframework docs on this: https://www.playframework.com/documentation/3.0.x/ProductionConfiguration#Changing-the-path-of-RUNNING_PID Add this to your
|
Expected behaviour
The working directory is writable by the running process after setting as per File Permission:
Actual behaviour
The working directory is not writable since its owner is root rather than user
Information
The text was updated successfully, but these errors were encountered: