0

I am using sbt-docker and trying to setup ssh on docker by following this link: https://docs.docker.com/examples/running_ssh_service/.

sbt-docker seems not to understand below:

run("echo", "'root:root' | chpasswd")

Instead of changing the root user password, this run command simply prints string "'root:root' | chpasswd".

Similarly,

run("echo", "root:root", "&>", "rootpasswd.txt")

This command print "root:root &> rootpasswd.txt" instead of writing "root:root" into rootpasswd.txt file.

Any idea how to make sbt-docker correctly execute these echo commands? Thanks!

jiangok
  • 2,622
  • 3
  • 21
  • 26

1 Answers1

2

Docker can run commands in 2 ways, shell form and exec form. The shell form will run your command in a shell. sbt-docker supports both formats with the methods: run (exec) and runShell (shell).

Since you are using a pipe you need to run your command using a shell. This is what the runShell method is for:

runShell("echo", "root:root", "|", "chpasswd")
runShell("echo", "root:root", "&>", "rootpasswd.txt")

You can also use the runRaw method, which allowes you to freely use any form:

runRaw("echo root:root | chpasswd")
runRaw("echo root:root &> rootpasswd.txt")