mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #10056 from coolljt0725/add_link_accept_ID
Add --link accept container ID
This commit is contained in:
commit
37b69408f8
3 changed files with 56 additions and 5 deletions
|
@ -753,10 +753,7 @@ func (daemon *Daemon) RegisterLinks(container *Container, hostConfig *runconfig.
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
child, err := daemon.GetByName(parts["name"])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
child := daemon.Get(parts["name"])
|
||||
if child == nil {
|
||||
return fmt.Errorf("Could not get container for %s", parts["name"])
|
||||
}
|
||||
|
|
|
@ -314,6 +314,60 @@ func TestRunWithoutNetworking(t *testing.T) {
|
|||
logDone("run - disable networking with -n=false")
|
||||
}
|
||||
|
||||
//test --link use container name to link target
|
||||
func TestRunLinksContainerWithContainerName(t *testing.T) {
|
||||
cmd := exec.Command(dockerBinary, "run", "-t", "-d", "--name", "parent", "busybox")
|
||||
out, _, _, err := runCommandWithStdoutStderr(cmd)
|
||||
if err != nil {
|
||||
t.Fatal("failed to run container: %v, output: %q", err, out)
|
||||
}
|
||||
cmd = exec.Command(dockerBinary, "inspect", "-f", "{{.NetworkSettings.IPAddress}}", "parent")
|
||||
ip, _, _, err := runCommandWithStdoutStderr(cmd)
|
||||
if err != nil {
|
||||
t.Fatal("failed to inspect container: %v, output: %q", err, ip)
|
||||
}
|
||||
ip = strings.TrimSpace(ip)
|
||||
cmd = exec.Command(dockerBinary, "run", "--link", "parent:test", "busybox", "/bin/cat", "/etc/hosts")
|
||||
out, _, err = runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatal("failed to run container: %v, output: %q", err, out)
|
||||
}
|
||||
if !strings.Contains(out, ip+" test") {
|
||||
t.Fatalf("use a container name to link target failed")
|
||||
}
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("run - use a container name to link target work")
|
||||
}
|
||||
|
||||
//test --link use container id to link target
|
||||
func TestRunLinksContainerWithContainerId(t *testing.T) {
|
||||
cmd := exec.Command(dockerBinary, "run", "-t", "-d", "busybox")
|
||||
cID, _, _, err := runCommandWithStdoutStderr(cmd)
|
||||
if err != nil {
|
||||
t.Fatal("failed to run container: %v, output: %q", err, cID)
|
||||
}
|
||||
cID = strings.TrimSpace(cID)
|
||||
cmd = exec.Command(dockerBinary, "inspect", "-f", "{{.NetworkSettings.IPAddress}}", cID)
|
||||
ip, _, _, err := runCommandWithStdoutStderr(cmd)
|
||||
if err != nil {
|
||||
t.Fatal("faild to inspect container: %v, output: %q", err, ip)
|
||||
}
|
||||
ip = strings.TrimSpace(ip)
|
||||
cmd = exec.Command(dockerBinary, "run", "--link", cID+":test", "busybox", "/bin/cat", "/etc/hosts")
|
||||
out, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatal("failed to run container: %v, output: %q", err, out)
|
||||
}
|
||||
if !strings.Contains(out, ip+" test") {
|
||||
t.Fatalf("use a container id to link target failed")
|
||||
}
|
||||
|
||||
deleteAllContainers()
|
||||
|
||||
logDone("run - use a container id to link target work")
|
||||
}
|
||||
|
||||
// Regression test for #4741
|
||||
func TestRunWithVolumesAsFiles(t *testing.T) {
|
||||
runCmd := exec.Command(dockerBinary, "run", "--name", "test-data", "--volume", "/etc/hosts:/target-file", "busybox", "true")
|
||||
|
|
|
@ -67,7 +67,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe
|
|||
|
||||
cmd.Var(&flAttach, []string{"a", "-attach"}, "Attach to STDIN, STDOUT or STDERR.")
|
||||
cmd.Var(&flVolumes, []string{"v", "-volume"}, "Bind mount a volume (e.g., from the host: -v /host:/container, from Docker: -v /container)")
|
||||
cmd.Var(&flLinks, []string{"#link", "-link"}, "Add link to another container in the form of name:alias")
|
||||
cmd.Var(&flLinks, []string{"#link", "-link"}, "Add link to another container in the form of <name|id>:alias")
|
||||
cmd.Var(&flDevices, []string{"-device"}, "Add a host device to the container (e.g. --device=/dev/sdc:/dev/xvdc:rwm)")
|
||||
|
||||
cmd.Var(&flEnv, []string{"e", "-env"}, "Set environment variables")
|
||||
|
|
Loading…
Reference in a new issue