mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
de6732a403
```console $ docker --context=rootless version ... Server: ... rootlesskit: Version: 0.14.2 ApiVersion: 1.1.1 NetworkDriver: slirp4netns PortDriver: builtin StateDir: /tmp/rootlesskit245426514 slirp4netns: Version: 1.1.9 GitCommit: 4e37ea557562e0d7a64dc636eff156f64927335e ``` Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
39 lines
1 KiB
Go
39 lines
1 KiB
Go
package rootless // import "github.com/docker/docker/rootless"
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"sync"
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/rootless-containers/rootlesskit/pkg/api/client"
|
|
)
|
|
|
|
const (
|
|
// RootlessKitDockerProxyBinary is the binary name of rootlesskit-docker-proxy
|
|
RootlessKitDockerProxyBinary = "rootlesskit-docker-proxy"
|
|
)
|
|
|
|
var (
|
|
runningWithRootlessKit bool
|
|
runningWithRootlessKitOnce sync.Once
|
|
)
|
|
|
|
// RunningWithRootlessKit returns true if running under RootlessKit namespaces.
|
|
func RunningWithRootlessKit() bool {
|
|
runningWithRootlessKitOnce.Do(func() {
|
|
u := os.Getenv("ROOTLESSKIT_STATE_DIR")
|
|
runningWithRootlessKit = u != ""
|
|
})
|
|
return runningWithRootlessKit
|
|
}
|
|
|
|
// GetRootlessKitClient returns RootlessKit client
|
|
func GetRootlessKitClient() (client.Client, error) {
|
|
stateDir := os.Getenv("ROOTLESSKIT_STATE_DIR")
|
|
if stateDir == "" {
|
|
return nil, errors.New("environment variable `ROOTLESSKIT_STATE_DIR` is not set")
|
|
}
|
|
apiSock := filepath.Join(stateDir, "api.sock")
|
|
return client.New(apiSock)
|
|
}
|