1
0
mirror of https://github.com/docker/docs.git synced 2026-10-31 10:34:26 +03:00

use docker 1.6, add affinity tests and add doc

Signed-off-by: Victor Vieux <victorvieux@gmail.com>
This commit is contained in:
Victor Vieux
2015-04-23 15:43:30 -07:00
parent f388d700fe
commit 28a358d9b2
4 changed files with 90 additions and 7 deletions

View File

@@ -101,7 +101,7 @@ without specifying them when starting the node. Those tags are sourced from
#### Containers
You can schedule 2 containers and make the container #2 next to the container #1.
You can schedule 2 containers and make the container #2 next to the container #1 using it's name or ID.
```bash
$ docker run -d -p 80:80 --name front nginx
@@ -164,6 +164,33 @@ CONTAINER ID IMAGE COMMAND CREATED
As you can see here, the containers were only scheduled on nodes with the `redis` image already pulled.
#### Labels
You can schedule 2 containers and make the container #2 next to the container #1 using it's labels.
```bash
$ docker run -d -p 80:80 --label com.example.type=front nginx
87c4376856a8
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NODE NAMES
87c4376856a8 nginx:latest "nginx" Less than a second ago running 192.168.0.42:80->80/tcp node-1 trusting_yonath
```
Using `-e affinity:com.example.type==front` will schedule a container next to the container with label `front`.
```bash
$ docker run -d -e affinity:com.example.type==front logger
87c4376856a8
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NODE NAMES
87c4376856a8 nginx:latest "nginx" Less than a second ago running 192.168.0.42:80->80/tcp node-1 trusting_yonath
963841b138d8 logger:latest "logger" Less than a second ago running node-1 happy_hawking
```
The `logger` container ends up on `node-1` because its affinity with the container `front`.
#### Expression Syntax
An affinity or a constraint expression consists of a `key` and a `value`.

View File

@@ -15,14 +15,14 @@ func TestParseExprs(t *testing.T) {
_, err = parseExprs("constraint", []string{"constraint:node ==node1"})
assert.Error(t, err)
// Cannot use dot in key
_, err = parseExprs("constraint", []string{"constraint:no.de==node1"})
assert.Error(t, err)
// Cannot use * in key
_, err = parseExprs("constraint", []string{"constraint:no*de==node1"})
assert.Error(t, err)
// Allow dot in key
_, err = parseExprs("constraint", []string{"constraint:no.de==node1"})
assert.NoError(t, err)
// Allow leading underscore
_, err = parseExprs("constraint", []string{"constraint:_node==_node1"})
assert.NoError(t, err)

View File

@@ -0,0 +1,56 @@
#!/usr/bin/env bats
load helpers
function teardown() {
swarm_manage_cleanup
stop_docker
}
@test "container affinty" {
start_docker 2
swarm_manage
run docker_swarm run --name c1 -e constraint:node==node-0 -d busybox:latest sh
[ "$status" -eq 0 ]
run docker_swarm run --name c2 -e affinity:container==c1 -d busybox:latest sh
[ "$status" -eq 0 ]
run docker_swarm run --name c3 -e affinity:container!=c1 -d busybox:latest sh
[ "$status" -eq 0 ]
run docker_swarm inspect c1
[ "$status" -eq 0 ]
[[ "${output}" == *'"Name": "node-0"'* ]]
run docker_swarm inspect c2
[ "$status" -eq 0 ]
[[ "${output}" == *'"Name": "node-0"'* ]]
run docker_swarm inspect c3
[ "$status" -eq 0 ]
[[ "${output}" == *'"Name": "node-1"'* ]]
}
@test "label affinity" {
start_docker 2
swarm_manage
run docker_swarm run --name c1 --label test.label=true -e constraint:node==node-0 -d busybox:latest sh
[ "$status" -eq 0 ]
run docker_swarm run --name c2 -e affinity:test.label==true -d busybox:latest sh
[ "$status" -eq 0 ]
run docker_swarm run --name c3 -e affinity:test.label!=true -d busybox:latest sh
[ "$status" -eq 0 ]
run docker_swarm inspect c1
[ "$status" -eq 0 ]
[[ "${output}" == *'"Name": "node-0"'* ]]
run docker_swarm inspect c2
[ "$status" -eq 0 ]
[[ "${output}" == *'"Name": "node-0"'* ]]
run docker_swarm inspect c3
[ "$status" -eq 0 ]
[[ "${output}" == *'"Name": "node-1"'* ]]
}

View File

@@ -4,8 +4,8 @@
SWARM_ROOT=${SWARM_ROOT:-${BATS_TEST_DIRNAME}/../..}
# Docker image and version to use for integration tests.
DOCKER_IMAGE=${DOCKER_IMAGE:-aluzzardi/docker}
DOCKER_VERSION=${DOCKER_VERSION:-1.5}
DOCKER_IMAGE=${DOCKER_IMAGE:-dockerswarm/docker}
DOCKER_VERSION=${DOCKER_VERSION:-1.6}
# Host on which the manager will listen to (random port between 6000 and 7000).
SWARM_HOST=127.0.0.1:$(( ( RANDOM % 1000 ) + 6000 ))