mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #22367 from dnephin/fix_dockerd_lookup_and_warn
Fix lookup of dockerd when called from outside of $PATH
This commit is contained in:
commit
ba6209f744
5 changed files with 32 additions and 8 deletions
|
@ -1,11 +1,16 @@
|
|||
// +build !daemon
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// CmdDaemon reports on an error on windows, because there is no exec
|
||||
func (p DaemonProxy) CmdDaemon(args ...string) error {
|
||||
return fmt.Errorf(
|
||||
"`docker daemon` does not exist on windows. Please run `dockerd` directly")
|
||||
"`docker daemon` is not supported on %s. Please run `dockerd` directly",
|
||||
strings.Title(runtime.GOOS))
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
// +build !daemon
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -9,7 +11,7 @@ func TestCmdDaemon(t *testing.T) {
|
|||
proxy := NewDaemonProxy()
|
||||
err := proxy.CmdDaemon("--help")
|
||||
if err == nil {
|
||||
t.Fatal("Expected CmdDaemon to fail in Windows.")
|
||||
t.Fatal("Expected CmdDaemon to fail on Windows.")
|
||||
}
|
||||
|
||||
if !strings.Contains(err.Error(), "Please run `dockerd`") {
|
|
@ -1,31 +1,44 @@
|
|||
// +build !windows
|
||||
// +build daemon
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// CmdDaemon execs dockerd with the same flags
|
||||
// TODO: add a deprecation warning?
|
||||
func (p DaemonProxy) CmdDaemon(args ...string) error {
|
||||
// Use os.Args[1:] so that "global" args are passed to dockerd
|
||||
args = stripDaemonArg(os.Args[1:])
|
||||
|
||||
// TODO: check dirname args[0] first
|
||||
binaryAbsPath, err := exec.LookPath(daemonBinary)
|
||||
binaryPath, err := findDaemonBinary()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return syscall.Exec(
|
||||
binaryAbsPath,
|
||||
binaryPath,
|
||||
append([]string{daemonBinary}, args...),
|
||||
os.Environ())
|
||||
}
|
||||
|
||||
// findDaemonBinary looks for the path to the dockerd binary starting with
|
||||
// the directory of the current executable (if one exists) and followed by $PATH
|
||||
func findDaemonBinary() (string, error) {
|
||||
execDirname := filepath.Dir(os.Args[0])
|
||||
if execDirname != "" {
|
||||
binaryPath := filepath.Join(execDirname, daemonBinary)
|
||||
if _, err := os.Stat(binaryPath); err == nil {
|
||||
return binaryPath, nil
|
||||
}
|
||||
}
|
||||
|
||||
return exec.LookPath(daemonBinary)
|
||||
}
|
||||
|
||||
// stripDaemonArg removes the `daemon` argument from the list
|
||||
func stripDaemonArg(args []string) []string {
|
||||
for i, arg := range args {
|
||||
|
|
|
@ -127,6 +127,7 @@ if [ "$DOCKER_EXPERIMENTAL" ]; then
|
|||
DOCKER_BUILDTAGS+=" experimental"
|
||||
fi
|
||||
|
||||
DOCKER_BUILDTAGS+=" daemon"
|
||||
if pkg-config 'libsystemd >= 209' 2> /dev/null ; then
|
||||
DOCKER_BUILDTAGS+=" journald"
|
||||
elif pkg-config 'libsystemd-journal' 2> /dev/null ; then
|
||||
|
|
|
@ -35,7 +35,10 @@ for platform in $DOCKER_CROSSPLATFORMS; do
|
|||
fi
|
||||
|
||||
if [ -z "${daemonSupporting[$platform]}" ]; then
|
||||
export LDFLAGS_STATIC_DOCKER="" # we just need a simple client for these platforms
|
||||
# we just need a simple client for these platforms
|
||||
export LDFLAGS_STATIC_DOCKER=""
|
||||
# remove the "daemon" build tag from platforms that aren't supported
|
||||
export BUILDFLAGS=( "${ORIG_BUILDFLAGS[@]/ daemon/}" )
|
||||
source "${MAKEDIR}/binary-client"
|
||||
else
|
||||
source "${MAKEDIR}/binary-client"
|
||||
|
|
Loading…
Add table
Reference in a new issue