Skip to content

Commit c64dbbc

Browse files
authored
Merge pull request docker#9523 from laurazard/add-links-container-create
Add links to container create request.
2 parents e90c6ba + 81182fc commit c64dbbc

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

pkg/compose/create.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project,
355355
volumesFrom = append(volumesFrom, v[len("container:"):])
356356
}
357357

358+
links, err := s.getLinks(ctx, p.Name, service, number)
359+
if err != nil {
360+
return nil, nil, nil, err
361+
}
362+
358363
securityOpts, err := parseSecurityOpts(p, service.SecurityOpt)
359364
if err != nil {
360365
return nil, nil, nil, err
@@ -389,6 +394,7 @@ func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project,
389394
Runtime: service.Runtime,
390395
LogConfig: logConfig,
391396
GroupAdd: service.GroupAdd,
397+
Links: links,
392398
}
393399

394400
return &containerConfig, &hostConfig, networkConfig, nil
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
container1:
3+
image: nginx
4+
network_mode: bridge
5+
container2:
6+
image: nginx
7+
network_mode: bridge
8+
links:
9+
- container1

pkg/e2e/networks_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestNetworks(t *testing.T) {
6969
})
7070
}
7171

72-
func TestNetworkAliassesAndLinks(t *testing.T) {
72+
func TestNetworkAliasses(t *testing.T) {
7373
c := NewParallelE2eCLI(t, binDir)
7474

7575
const projectName = "network_alias_e2e"
@@ -93,6 +93,25 @@ func TestNetworkAliassesAndLinks(t *testing.T) {
9393
})
9494
}
9595

96+
func TestNetworkLinks(t *testing.T) {
97+
c := NewParallelE2eCLI(t, binDir)
98+
99+
const projectName = "network_link_e2e"
100+
101+
t.Run("up", func(t *testing.T) {
102+
c.RunDockerComposeCmd("-f", "./fixtures/network-links/compose.yaml", "--project-name", projectName, "up", "-d")
103+
})
104+
105+
t.Run("curl links in default bridge network", func(t *testing.T) {
106+
res := c.RunDockerComposeCmd("-f", "./fixtures/network-links/compose.yaml", "--project-name", projectName, "exec", "-T", "container2", "curl", "http://container1/")
107+
assert.Assert(t, strings.Contains(res.Stdout(), "Welcome to nginx!"), res.Stdout())
108+
})
109+
110+
t.Run("down", func(t *testing.T) {
111+
_ = c.RunDockerComposeCmd("--project-name", projectName, "down")
112+
})
113+
}
114+
96115
func TestIPAMConfig(t *testing.T) {
97116
c := NewParallelE2eCLI(t, binDir)
98117

0 commit comments

Comments
 (0)