diff --git a/commands/start.go b/commands/start.go index fd61726c..e5672f13 100644 --- a/commands/start.go +++ b/commands/start.go @@ -61,6 +61,11 @@ func StartCommand() cli.Command { Value: 8080, Usage: "Specify port number to bind to on the host.", }, + cli.StringFlag{ + Name: "iofs-dir", + Usage: "--iofs-dir to specify a directory or container engine volume for Fn Server to create unix socket file for cross container communication.\n" + + "By default, container named volume is used: \"fnserversocket\"", + }, }, } } @@ -75,10 +80,24 @@ func start(c *cli.Context) error { fnDir = filepath.Join(home, ".fn") } + // User could override iofs directory. The iofs path is used by Fn Server to create unix socket file + // for the communication between Fn Server and Fn Containers. + // If user is using Podman or Rancher desktop where the socket file could not be created under HOME directory + // (see: https://github.com/fnproject/fn/issues/1577#issuecomment-1297736260), user could provide a container + // named volume to work around. + // On Windows docker desktop, if we use OS directory as iofs path, we also observed that the fsnotify did not + // notify fnserver container when the socket file was created. However, named volume worked well. + // As a result, we decided to use named volume as default as it works in all cases. + // The named volume will be created automatically if it is not in the host machine. + iofsDir := "fnserversocket" + if c.String("iofs-dir") != "" { + iofsDir = c.String("iofs-dir") + } + args := []string{"run", "--rm", "-i", "--name", "fnserver", - "-v", fmt.Sprintf("%s/iofs:/iofs", fnDir), - "-e", fmt.Sprintf("FN_IOFS_DOCKER_PATH=%s/iofs", fnDir), + "-v", fmt.Sprintf("%s:/iofs:Z", iofsDir), + "-e", fmt.Sprintf("FN_IOFS_DOCKER_PATH=%s", iofsDir), "-e", "FN_IOFS_PATH=/iofs", "-v", fmt.Sprintf("%s/data:/app/data", fnDir), "-v", "/var/run/docker.sock:/var/run/docker.sock",