Tuesday, June 25, 2019

sbt-native-packager /opt/docker permission denied

I was getting all sorts of issues when trying to create files or directories below "/opt/docker" path. I tried adding:

import com.typesafe.sbt.packager.docker.DockerChmodType
dockerChmodType := DockerChmodType.UserGroupWriteExecute

It did not work, I was still getting errors, permission denied, while trying to write PID file to "/opt/docker/PID_FILE".

The solution is adding the following:

javaOptions in Universal ++= Seq(
  // Since play uses separate pidfile we have to provide it with a proper path  // name of the pid file must be play.pid  s"-Dpidfile.path=/var/run/play.pid")

Basically indicating Play framework to write PID file in another location, then:

dockerCommands ++= Seq(
  ExecCmd("RUN", "mkdir", "-p", s"/var/run/")
)

It would create another directory. Then, execute:

sbt dist && sbt docker:publishLocal

Finally you can write the following in a bash file:

dir=$(pwd)
docker run -v $dir/my_play_project:/var/run -v \ 
$dir/my_play_project/logs:/opt/docker/logs -p 9000:9000 \ 
 my_play_project:1.0