mirror of https://github.com/docker/docs.git
support docker run --net <node>/<network>
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
633a2ba065
commit
22fedf0db0
|
@ -196,6 +196,18 @@ func (c *ContainerConfig) RemoveAffinity(affinity string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// AddConstraint to config
|
||||
func (c *ContainerConfig) AddConstraint(constraint string) error {
|
||||
constraints := c.extractExprs("constraints")
|
||||
constraints = append(constraints, constraint)
|
||||
labels, err := json.Marshal(constraints)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.Labels[SwarmLabelNamespace+".constraints"] = string(labels)
|
||||
return nil
|
||||
}
|
||||
|
||||
// HaveNodeConstraint in config
|
||||
func (c *ContainerConfig) HaveNodeConstraint() bool {
|
||||
constraints := c.extractExprs("constraints")
|
||||
|
|
|
@ -170,6 +170,13 @@ func (c *Cluster) createContainer(config *cluster.ContainerConfig, name string,
|
|||
config.SetSwarmID(swarmID)
|
||||
}
|
||||
|
||||
if network := c.Networks().Get(config.HostConfig.NetworkMode); network != nil && network.Scope == "local" {
|
||||
if !config.HaveNodeConstraint() {
|
||||
config.AddConstraint("node==~" + network.Engine.Name)
|
||||
}
|
||||
config.HostConfig.NetworkMode = network.Name
|
||||
}
|
||||
|
||||
if withImageAffinity {
|
||||
config.AddAffinity("image==" + config.Image)
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ function teardown() {
|
|||
|
||||
run docker_swarm network ls --filter type=custom
|
||||
[ "${#lines[@]}" -eq 2 ]
|
||||
|
||||
}
|
||||
|
||||
@test "docker network inspect" {
|
||||
|
@ -176,3 +175,15 @@ function teardown() {
|
|||
run docker_swarm network inspect testn
|
||||
[[ "${output}" != *"\"Containers\": {}"* ]]
|
||||
}
|
||||
|
||||
@test "docker run --net <node>/<network>" {
|
||||
start_docker_with_busybox 2
|
||||
swarm_manage
|
||||
|
||||
docker_swarm network create -d bridge node-1/testn
|
||||
|
||||
docker_swarm run -d --net node-1/testn --name test_container busybox sleep 100
|
||||
|
||||
run docker_swarm network inspect testn
|
||||
[[ "${output}" != *"\"Containers\": {}"* ]]
|
||||
}
|
||||
|
|
|
@ -48,6 +48,26 @@ function teardown() {
|
|||
[[ "${output}" == *"->80/tcp"* ]]
|
||||
}
|
||||
|
||||
@test "docker-compose up - check bridge network" {
|
||||
# docker network connect --ip is introduced in docker 1.10, skip older version without --ip
|
||||
run docker network connect --help
|
||||
if [[ "${output}" != *"--ip"* ]]; then
|
||||
skip
|
||||
fi
|
||||
|
||||
start_docker_with_busybox 2
|
||||
swarm_manage
|
||||
FILE=$TESTDATA/compose/simple_v2.yml
|
||||
|
||||
docker-compose_swarm -f $FILE up -d
|
||||
|
||||
run docker_swarm ps -q
|
||||
[ "${#lines[@]}" -eq 1 ]
|
||||
|
||||
run docker_swarm inspect compose_service1_1
|
||||
[[ "${output}" == *"testn\""* ]]
|
||||
}
|
||||
|
||||
function containerRunning() {
|
||||
local container="$1"
|
||||
local node="$2"
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
version: "2"
|
||||
|
||||
services:
|
||||
|
||||
service1:
|
||||
image: busybox
|
||||
command: sleep 100
|
||||
networks:
|
||||
- testn
|
||||
|
||||
networks:
|
||||
testn:
|
||||
driver: bridge
|
Loading…
Reference in New Issue