From 6132818163a9215d09a34cf1f318d5fc8a978d43 Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Sat, 26 Sep 2015 00:45:11 +0200 Subject: [PATCH] Ability to configure docker run arguments (fix #13) --- client.go | 4 +++- cmd/ssh2docker/main.go | 14 ++++++++++++++ server.go | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index bfcd5bd..eda0b5b 100644 --- a/client.go +++ b/client.go @@ -116,7 +116,9 @@ func (c *Client) HandleChannelRequests(channel ssh.Channel, requests <-chan *ssh } ok = true - args := []string{"run", "-it", "--rm", c.Conn.User(), "/bin/sh"} + args := []string{"run"} + args = append(args, c.Server.DockerRunArgs...) + args = append(args, c.Conn.User(), c.Server.DefaultShell) logrus.Debugf("Executing 'docker %s'", strings.Join(args, " ")) cmd := exec.Command("docker", args...) cmd.Env = c.Env.List() diff --git a/cmd/ssh2docker/main.go b/cmd/ssh2docker/main.go index fa00a3d..a93ac44 100644 --- a/cmd/ssh2docker/main.go +++ b/cmd/ssh2docker/main.go @@ -75,6 +75,16 @@ func main() { Usage: "List of allowed images, i.e: alpine,ubuntu:trusty,1cf3e6c", Value: "", }, + cli.StringFlag{ + Name: "shell", + Usage: "Default shell", + Value: "/bin/sh", + }, + cli.StringFlag{ + Name: "docker-run-args", + Usage: "'docker run' arguments", + Value: "-it --rm", + }, } app.Action = Action @@ -105,6 +115,10 @@ func Action(c *cli.Context) { server.AllowedImages = strings.Split(c.String("allowed-images"), ",") } + // Set defaults + server.DefaultShell = c.String("shell") + server.DockerRunArgs = strings.Split(c.String("docker-run-args"), " ") + // Register the SSH host key hostKey := c.String("host-key") if hostKey == "built-in" { diff --git a/server.go b/server.go index ed59614..04ffcb8 100644 --- a/server.go +++ b/server.go @@ -13,6 +13,8 @@ type Server struct { // Clients []Client AllowedImages []string + DefaultShell string + DockerRunArgs []string } // NewServer initialize a new Server instance with default values @@ -22,6 +24,8 @@ func NewServer() (*Server, error) { PasswordCallback: server.PasswordCallback, } server.AllowedImages = nil + server.DefaultShell = "/bin/sh" + server.DockerRunArgs = []string{"-it", "--rm"} return &server, nil }