2014-04-07 14:34:07 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-01-21 17:34:08 -05:00
|
|
|
"fmt"
|
2014-05-21 18:07:40 -04:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2014-04-07 14:34:07 -04:00
|
|
|
"os/exec"
|
2014-12-03 20:52:06 -05:00
|
|
|
"reflect"
|
2015-01-21 17:34:08 -05:00
|
|
|
"regexp"
|
2014-05-21 18:07:40 -04:00
|
|
|
"strings"
|
2014-10-24 17:39:12 -04:00
|
|
|
"time"
|
2015-01-21 17:34:08 -05:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
"github.com/go-check/check"
|
2014-04-07 14:34:07 -04:00
|
|
|
)
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestLinksEtcHostsRegularFile(c *check.C) {
|
2014-05-21 18:07:40 -04:00
|
|
|
runCmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "ls", "-la", "/etc/hosts")
|
|
|
|
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
2014-10-14 15:50:35 -04:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(out, err)
|
2014-10-14 15:50:35 -04:00
|
|
|
}
|
2014-05-21 18:07:40 -04:00
|
|
|
|
|
|
|
if !strings.HasPrefix(out, "-") {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Errorf("/etc/hosts should be a regular file")
|
2014-05-21 18:07:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestLinksEtcHostsContentMatch(c *check.C) {
|
|
|
|
testRequires(c, SameHostDaemon)
|
2015-02-13 17:53:39 -05:00
|
|
|
|
2014-05-21 18:07:40 -04:00
|
|
|
runCmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "cat", "/etc/hosts")
|
|
|
|
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
2014-10-14 15:50:35 -04:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(out, err)
|
2014-10-14 15:50:35 -04:00
|
|
|
}
|
2014-05-21 18:07:40 -04:00
|
|
|
|
|
|
|
hosts, err := ioutil.ReadFile("/etc/hosts")
|
|
|
|
if os.IsNotExist(err) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Skip("/etc/hosts does not exist, skip this test")
|
2014-05-21 18:07:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if out != string(hosts) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Errorf("container")
|
2014-05-21 18:07:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestLinksPingUnlinkedContainers(c *check.C) {
|
2014-04-07 14:34:07 -04:00
|
|
|
runCmd := exec.Command(dockerBinary, "run", "--rm", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1")
|
|
|
|
exitCode, err := runCommand(runCmd)
|
|
|
|
|
|
|
|
if exitCode == 0 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal("run ping did not fail")
|
2014-04-07 14:34:07 -04:00
|
|
|
} else if exitCode != 1 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("run ping failed with errors: %v", err)
|
2014-04-07 14:34:07 -04:00
|
|
|
}
|
2014-08-28 01:25:57 -04:00
|
|
|
|
2014-04-07 14:34:07 -04:00
|
|
|
}
|
|
|
|
|
2015-02-13 15:14:38 -05:00
|
|
|
// Test for appropriate error when calling --link with an invalid target container
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestLinksInvalidContainerTarget(c *check.C) {
|
2015-02-20 01:56:02 -05:00
|
|
|
|
2015-02-13 15:14:38 -05:00
|
|
|
runCmd := exec.Command(dockerBinary, "run", "--link", "bogus:alias", "busybox", "true")
|
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
|
|
|
|
if err == nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal("an invalid container target should produce an error")
|
2015-02-13 15:14:38 -05:00
|
|
|
}
|
|
|
|
if !strings.Contains(out, "Could not get container") {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("error output expected 'Could not get container', but got %q instead; err: %v", out, err)
|
2015-02-13 15:14:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestLinksPingLinkedContainers(c *check.C) {
|
2015-02-20 01:56:02 -05:00
|
|
|
|
2015-02-16 00:00:51 -05:00
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "container1", "--hostname", "fred", "busybox", "top")
|
|
|
|
if _, err := runCommand(runCmd); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-02-16 00:00:51 -05:00
|
|
|
}
|
|
|
|
runCmd = exec.Command(dockerBinary, "run", "-d", "--name", "container2", "--hostname", "wilma", "busybox", "top")
|
|
|
|
if _, err := runCommand(runCmd); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-02-16 00:00:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
runArgs := []string{"run", "--rm", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "sh", "-c"}
|
|
|
|
pingCmd := "ping -c 1 %s -W 1 && ping -c 1 %s -W 1"
|
2014-08-28 01:25:57 -04:00
|
|
|
|
2015-02-16 00:00:51 -05:00
|
|
|
// test ping by alias, ping by name, and ping by hostname
|
|
|
|
// 1. Ping by alias
|
2015-04-18 12:46:47 -04:00
|
|
|
dockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "alias1", "alias2"))...)
|
2015-02-16 00:00:51 -05:00
|
|
|
// 2. Ping by container name
|
2015-04-18 12:46:47 -04:00
|
|
|
dockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "container1", "container2"))...)
|
2015-02-16 00:00:51 -05:00
|
|
|
// 3. Ping by hostname
|
2015-04-18 12:46:47 -04:00
|
|
|
dockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "fred", "wilma"))...)
|
2015-02-16 00:00:51 -05:00
|
|
|
|
2014-04-07 14:34:07 -04:00
|
|
|
}
|
2014-05-10 13:27:24 -04:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestLinksPingLinkedContainersAfterRename(c *check.C) {
|
2015-02-20 01:56:02 -05:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
|
2015-04-06 09:21:18 -04:00
|
|
|
idA := strings.TrimSpace(out)
|
2015-04-18 12:46:47 -04:00
|
|
|
out, _ = dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top")
|
2015-04-06 09:21:18 -04:00
|
|
|
idB := strings.TrimSpace(out)
|
2015-04-18 12:46:47 -04:00
|
|
|
dockerCmd(c, "rename", "container1", "container_new")
|
|
|
|
dockerCmd(c, "run", "--rm", "--link", "container_new:alias1", "--link", "container2:alias2", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1")
|
|
|
|
dockerCmd(c, "kill", idA)
|
|
|
|
dockerCmd(c, "kill", idB)
|
2014-10-04 22:47:54 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestLinksInspectLinksStarted(c *check.C) {
|
2014-07-08 16:27:58 -04:00
|
|
|
var (
|
|
|
|
expected = map[string]struct{}{"/container1:/testinspectlink/alias1": {}, "/container2:/testinspectlink/alias2": {}}
|
|
|
|
result []string
|
|
|
|
)
|
2015-04-18 12:46:47 -04:00
|
|
|
dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
|
|
|
|
dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top")
|
|
|
|
dockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "top")
|
2014-07-08 16:27:58 -04:00
|
|
|
links, err := inspectFieldJSON("testinspectlink", "HostConfig.Links")
|
2014-06-27 04:26:02 -04:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2014-06-27 04:26:02 -04:00
|
|
|
}
|
2014-07-08 16:27:58 -04:00
|
|
|
|
|
|
|
err = unmarshalJSON([]byte(links), &result)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2014-07-08 16:27:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
output := convertSliceOfStringsToMap(result)
|
|
|
|
|
2014-12-03 20:52:06 -05:00
|
|
|
equal := reflect.DeepEqual(output, expected)
|
2014-07-08 16:27:58 -04:00
|
|
|
|
|
|
|
if !equal {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Links %s, expected %s", result, expected)
|
2014-06-27 04:26:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestLinksInspectLinksStopped(c *check.C) {
|
2014-07-22 18:13:52 -04:00
|
|
|
var (
|
|
|
|
expected = map[string]struct{}{"/container1:/testinspectlink/alias1": {}, "/container2:/testinspectlink/alias2": {}}
|
|
|
|
result []string
|
|
|
|
)
|
2015-04-18 12:46:47 -04:00
|
|
|
dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
|
|
|
|
dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top")
|
|
|
|
dockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "true")
|
2014-07-22 18:13:52 -04:00
|
|
|
links, err := inspectFieldJSON("testinspectlink", "HostConfig.Links")
|
2014-06-27 04:26:02 -04:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2014-06-27 04:26:02 -04:00
|
|
|
}
|
2014-07-22 18:13:52 -04:00
|
|
|
|
|
|
|
err = unmarshalJSON([]byte(links), &result)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2014-06-27 04:26:02 -04:00
|
|
|
}
|
2014-07-22 18:13:52 -04:00
|
|
|
|
|
|
|
output := convertSliceOfStringsToMap(result)
|
|
|
|
|
2014-12-03 20:52:06 -05:00
|
|
|
equal := reflect.DeepEqual(output, expected)
|
2014-07-22 18:13:52 -04:00
|
|
|
|
|
|
|
if !equal {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Links %s, but expected %s", result, expected)
|
2014-07-22 18:13:52 -04:00
|
|
|
}
|
|
|
|
|
2014-06-27 04:26:02 -04:00
|
|
|
}
|
2014-11-06 18:25:14 -05:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestLinksNotStartedParentNotFail(c *check.C) {
|
2014-11-06 18:25:14 -05:00
|
|
|
runCmd := exec.Command(dockerBinary, "create", "--name=first", "busybox", "top")
|
|
|
|
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(out, err)
|
2014-11-06 18:25:14 -05:00
|
|
|
}
|
|
|
|
runCmd = exec.Command(dockerBinary, "create", "--name=second", "--link=first:first", "busybox", "top")
|
|
|
|
out, _, _, err = runCommandWithStdoutStderr(runCmd)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(out, err)
|
2014-11-06 18:25:14 -05:00
|
|
|
}
|
|
|
|
runCmd = exec.Command(dockerBinary, "start", "first")
|
|
|
|
out, _, _, err = runCommandWithStdoutStderr(runCmd)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(out, err)
|
2014-11-06 18:25:14 -05:00
|
|
|
}
|
|
|
|
}
|
2014-10-24 17:39:12 -04:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestLinksHostsFilesInject(c *check.C) {
|
|
|
|
testRequires(c, SameHostDaemon, ExecSupport)
|
2014-10-24 17:39:12 -04:00
|
|
|
|
|
|
|
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-itd", "--name", "one", "busybox", "top"))
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err, out)
|
2014-10-24 17:39:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
idOne := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "-itd", "--name", "two", "--link", "one:onetwo", "busybox", "top"))
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err, out)
|
2014-10-24 17:39:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
idTwo := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
|
2015-02-16 14:32:25 -05:00
|
|
|
contentOne, err := readContainerFileWithExec(idOne, "/etc/hosts")
|
2014-10-24 17:39:12 -04:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err, string(contentOne))
|
2014-10-24 17:39:12 -04:00
|
|
|
}
|
|
|
|
|
2015-02-16 14:32:25 -05:00
|
|
|
contentTwo, err := readContainerFileWithExec(idTwo, "/etc/hosts")
|
2014-10-24 17:39:12 -04:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err, string(contentTwo))
|
2014-10-24 17:39:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(string(contentTwo), "onetwo") {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal("Host is not present in updated hosts file", string(contentTwo))
|
2014-10-24 17:39:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-12-08 14:33:18 -05:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestLinksNetworkHostContainer(c *check.C) {
|
2014-12-08 14:33:18 -05:00
|
|
|
|
|
|
|
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--net", "host", "--name", "host_container", "busybox", "top"))
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err, out)
|
2014-12-08 14:33:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "should_fail", "--link", "host_container:tester", "busybox", "true"))
|
2015-05-12 23:04:07 -04:00
|
|
|
if err == nil || !strings.Contains(out, "--net=host can't be used with links. This would result in undefined behavior") {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Running container linking to a container with --net host should have failed: %s", out)
|
2014-12-08 14:33:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-01-21 17:34:08 -05:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestLinksUpdateOnRestart(c *check.C) {
|
|
|
|
testRequires(c, SameHostDaemon, ExecSupport)
|
2015-01-21 17:34:08 -05:00
|
|
|
|
|
|
|
if out, err := exec.Command(dockerBinary, "run", "-d", "--name", "one", "busybox", "top").CombinedOutput(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err, string(out))
|
2015-01-21 17:34:08 -05:00
|
|
|
}
|
|
|
|
out, err := exec.Command(dockerBinary, "run", "-d", "--name", "two", "--link", "one:onetwo", "--link", "one:one", "busybox", "top").CombinedOutput()
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err, string(out))
|
2015-01-21 17:34:08 -05:00
|
|
|
}
|
|
|
|
id := strings.TrimSpace(string(out))
|
|
|
|
|
|
|
|
realIP, err := inspectField("one", "NetworkSettings.IPAddress")
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-01-21 17:34:08 -05:00
|
|
|
}
|
2015-02-16 14:32:25 -05:00
|
|
|
content, err := readContainerFileWithExec(id, "/etc/hosts")
|
2015-01-21 17:34:08 -05:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err, string(content))
|
2015-01-21 17:34:08 -05:00
|
|
|
}
|
|
|
|
getIP := func(hosts []byte, hostname string) string {
|
|
|
|
re := regexp.MustCompile(fmt.Sprintf(`(\S*)\t%s`, regexp.QuoteMeta(hostname)))
|
|
|
|
matches := re.FindSubmatch(hosts)
|
|
|
|
if matches == nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Hostname %s have no matches in hosts", hostname)
|
2015-01-21 17:34:08 -05:00
|
|
|
}
|
|
|
|
return string(matches[1])
|
|
|
|
}
|
|
|
|
if ip := getIP(content, "one"); ip != realIP {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("For 'one' alias expected IP: %s, got: %s", realIP, ip)
|
2015-01-21 17:34:08 -05:00
|
|
|
}
|
|
|
|
if ip := getIP(content, "onetwo"); ip != realIP {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("For 'onetwo' alias expected IP: %s, got: %s", realIP, ip)
|
2015-01-21 17:34:08 -05:00
|
|
|
}
|
|
|
|
if out, err := exec.Command(dockerBinary, "restart", "one").CombinedOutput(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err, string(out))
|
2015-01-21 17:34:08 -05:00
|
|
|
}
|
|
|
|
realIP, err = inspectField("one", "NetworkSettings.IPAddress")
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-01-21 17:34:08 -05:00
|
|
|
}
|
2015-02-16 14:32:25 -05:00
|
|
|
content, err = readContainerFileWithExec(id, "/etc/hosts")
|
2015-01-21 17:34:08 -05:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err, string(content))
|
2015-01-21 17:34:08 -05:00
|
|
|
}
|
|
|
|
if ip := getIP(content, "one"); ip != realIP {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("For 'one' alias expected IP: %s, got: %s", realIP, ip)
|
2015-01-21 17:34:08 -05:00
|
|
|
}
|
|
|
|
if ip := getIP(content, "onetwo"); ip != realIP {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("For 'onetwo' alias expected IP: %s, got: %s", realIP, ip)
|
2015-01-21 17:34:08 -05:00
|
|
|
}
|
|
|
|
}
|
2015-04-25 07:42:43 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestLinksEnvs(c *check.C) {
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "-e", "e1=", "-e", "e2=v2", "-e", "e3=v3=v3", "--name=first", "busybox", "top")
|
|
|
|
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
|
|
if err != nil {
|
|
|
|
c.Fatalf("Run of first failed: %s\n%s", out, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "run", "--name=second", "--link=first:first", "busybox", "env")
|
|
|
|
|
|
|
|
out, stde, rc, err := runCommandWithStdoutStderr(runCmd)
|
|
|
|
if err != nil || rc != 0 {
|
|
|
|
c.Fatalf("run of 2nd failed: rc: %d, out: %s\n err: %s", rc, out, stde)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(out, "FIRST_ENV_e1=\n") ||
|
|
|
|
!strings.Contains(out, "FIRST_ENV_e2=v2") ||
|
|
|
|
!strings.Contains(out, "FIRST_ENV_e3=v3=v3") {
|
|
|
|
c.Fatalf("Incorrect output: %s", out)
|
|
|
|
}
|
|
|
|
}
|
2015-05-07 16:02:14 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestLinkShortDefinition(c *check.C) {
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "shortlinkdef", "busybox", "top")
|
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
cid := strings.TrimSpace(out)
|
|
|
|
c.Assert(waitRun(cid), check.IsNil)
|
|
|
|
|
|
|
|
runCmd = exec.Command(dockerBinary, "run", "-d", "--name", "link2", "--link", "shortlinkdef", "busybox", "top")
|
|
|
|
out, _, err = runCommandWithOutput(runCmd)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
cid2 := strings.TrimSpace(out)
|
|
|
|
c.Assert(waitRun(cid2), check.IsNil)
|
|
|
|
|
|
|
|
links, err := inspectFieldJSON(cid2, "HostConfig.Links")
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
c.Assert(links, check.Equals, "[\"/shortlinkdef:/link2/shortlinkdef\"]")
|
|
|
|
}
|