diff --git a/cmd/control/console_init.go b/cmd/control/console_init.go index 1b0c2ef5e..e67d8ca9d 100644 --- a/cmd/control/console_init.go +++ b/cmd/control/console_init.go @@ -203,6 +203,13 @@ $(tput sgr0) } } + // create Docker CLI plugins folder + if _, err := os.Stat("/usr/libexec/docker/cli-plugins"); os.IsNotExist(err) { + if err = os.MkdirAll("/usr/libexec/docker/cli-plugins", 0755); err != nil { + log.Error(err) + } + } + baseSymlink := symLinkEngineBinary() if _, err := os.Stat(dockerCompletionFile); err == nil { @@ -211,40 +218,6 @@ $(tput sgr0) }) } - // create placeholder for docker binary with "docker compose" support - const DockerPlaceholder = `#!/bin/bash -if [ "$1" == "compose" ]; then - /usr/local/bin/docker-compose "${@:2}" -elif [ "$1" == "build" ]; then - DOCKER_VERSION=$(sudo system-docker inspect --format "{{.Config.Image}}" docker | cut -d ":" -f 2) - docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -w /build -v $PWD:/build docker:$DOCKER_VERSION-cli docker build "${@:2}" -elif [ "$1" == "builder" ]; then - DOCKER_VERSION=$(sudo system-docker inspect --format "{{.Config.Image}}" docker | cut -d ":" -f 2) - docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -w /builder -v $PWD:/builder docker:$DOCKER_VERSION-cli docker builder "${@:2}" -elif [ "$1" == "buildx" ]; then - DOCKER_VERSION=$(sudo system-docker inspect --format "{{.Config.Image}}" docker | cut -d ":" -f 2) - docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -w /buildx -v $PWD:/buildx docker:$DOCKER_VERSION-cli docker buildx "${@:2}" -else - /usr/bin/docker "$@" -fi -` - if _, err := os.Stat("/usr/local/bin/docker"); os.IsNotExist(err) { - if err := ioutil.WriteFile("/usr/local/bin/docker", []byte(DockerPlaceholder), 0755); err != nil { - log.Error(err) - } - } - - // create placeholder for docker-compose binary - const ComposePlaceholder = `#!/bin/bash -DOCKER_VERSION=$(sudo system-docker inspect --format "{{.Config.Image}}" docker | cut -d ":" -f 2) -docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -w /compose -v $PWD:/compose docker:$DOCKER_VERSION-cli docker compose "$@" -` - if _, err := os.Stat("/usr/local/bin/docker-compose"); os.IsNotExist(err) { - if err := ioutil.WriteFile("/usr/local/bin/docker-compose", []byte(ComposePlaceholder), 0755); err != nil { - log.Error(err) - } - } - for _, link := range baseSymlink { syscall.Unlink(link.newname) if err := os.Symlink(link.oldname, link.newname); err != nil { @@ -317,14 +290,6 @@ docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -w /compose -v log.Error(err) } - if err := util.RunScript("/etc/rc.local"); err != nil { - log.Error(err) - } - - if err := util.RunScript("/etc/init.d/apparmor", "start"); err != nil { - log.Error(err) - } - // Check if user Docker has ever run in this installation yet and switch to latest version if not if _, err := os.Stat("/var/lib/docker/engine-id"); os.IsNotExist(err) { log.Warn("User Docker does not exist, switching to latest version") @@ -336,6 +301,14 @@ docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -w /compose -v } } + if err := util.RunScript("/etc/rc.local"); err != nil { + log.Error(err) + } + + if err := util.RunScript("/etc/init.d/apparmor", "start"); err != nil { + log.Error(err) + } + // Enable Bash colors enableBashRC("/root", 0, 0) enableBashRC(rancherHome, 1100, 1100) diff --git a/cmd/control/user_docker.go b/cmd/control/user_docker.go index 03f320ca0..7849485e5 100644 --- a/cmd/control/user_docker.go +++ b/cmd/control/user_docker.go @@ -22,11 +22,13 @@ import ( ) const ( - defaultStorageContext = "console" - dockerPidFile = "/var/run/docker.pid" - sourceDirectory = "/engine" - destDirectory = "/var/lib/rancher/engine" - dockerCompletionFName = "completion" + defaultStorageContext = "console" + dockerPidFile = "/var/run/docker.pid" + sourceDirectory = "/engine" + destDirectory = "/var/lib/rancher/engine" + pluginsSourceDirectory = "/engine-plugins" + pluginsDestDirectory = "/var/lib/rancher/engine-plugins" + dockerCompletionFName = "completion" ) var ( @@ -41,6 +43,10 @@ func userDockerAction(c *cli.Context) error { return err } + if err := copyBinaries(pluginsSourceDirectory, pluginsDestDirectory); err != nil { + return err + } + if err := syscall.Mount("/host/sys", "/sys", "", syscall.MS_BIND|syscall.MS_REC, ""); err != nil { return err } diff --git a/cmd/control/util.go b/cmd/control/util.go index e899dd995..0dea4eee0 100644 --- a/cmd/control/util.go +++ b/cmd/control/util.go @@ -54,6 +54,11 @@ func symLinkEngineBinary() []symlink { {"/var/lib/rancher/engine/docker-containerd-ctr", "/usr/bin/docker-containerd-ctr"}, {"/var/lib/rancher/engine/docker-containerd-shim", "/usr/bin/docker-containerd-shim"}, {"/var/lib/rancher/engine/docker-runc", "/usr/bin/docker-runc"}, + + // Docker CLI plugins + {"/var/lib/rancher/engine-plugins/docker-compose", "/usr/bin/docker-compose"}, + {"/var/lib/rancher/engine-plugins/docker-compose", "/usr/libexec/docker/cli-plugins/docker-compose"}, + {"/var/lib/rancher/engine-plugins/docker-buildx", "/usr/libexec/docker/cli-plugins/docker-buildx"}, } return baseSymlink }