mirror of https://github.com/docker/docs.git
Merge pull request #1340 from jimmyxian/volume-driver
Move VolumeDriver to HostConfig
This commit is contained in:
commit
d2c5446ea0
|
@ -118,7 +118,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/samalba/dockerclient",
|
"ImportPath": "github.com/samalba/dockerclient",
|
||||||
"Rev": "a3241e22d7230854778614ebca9c7f869776c5f0"
|
"Rev": "c17bc9a62a1e2f966c05987313e187568e2ca894"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/samuel/go-zookeeper/zk",
|
"ImportPath": "github.com/samuel/go-zookeeper/zk",
|
||||||
|
|
|
@ -21,7 +21,8 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrNotFound = errors.New("Not found")
|
ErrImageNotFound = errors.New("Image not found")
|
||||||
|
ErrNotFound = errors.New("Not found")
|
||||||
|
|
||||||
defaultTimeout = 30 * time.Second
|
defaultTimeout = 30 * time.Second
|
||||||
)
|
)
|
||||||
|
@ -103,6 +104,17 @@ func (client *DockerClient) doStreamRequest(method string, path string, in io.Re
|
||||||
}
|
}
|
||||||
if resp.StatusCode == 404 {
|
if resp.StatusCode == 404 {
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
data, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, ErrNotFound
|
||||||
|
}
|
||||||
|
if len(data) > 0 {
|
||||||
|
// check if is image not found error
|
||||||
|
if strings.Index(string(data), "No such image") != -1 {
|
||||||
|
return nil, ErrImageNotFound
|
||||||
|
}
|
||||||
|
return nil, errors.New(string(data))
|
||||||
|
}
|
||||||
return nil, ErrNotFound
|
return nil, ErrNotFound
|
||||||
}
|
}
|
||||||
if resp.StatusCode >= 400 {
|
if resp.StatusCode >= 400 {
|
||||||
|
|
|
@ -23,7 +23,6 @@ type ContainerConfig struct {
|
||||||
Cmd []string
|
Cmd []string
|
||||||
Image string
|
Image string
|
||||||
Volumes map[string]struct{}
|
Volumes map[string]struct{}
|
||||||
VolumeDriver string
|
|
||||||
WorkingDir string
|
WorkingDir string
|
||||||
Entrypoint []string
|
Entrypoint []string
|
||||||
NetworkDisabled bool
|
NetworkDisabled bool
|
||||||
|
@ -32,6 +31,9 @@ type ContainerConfig struct {
|
||||||
Labels map[string]string
|
Labels map[string]string
|
||||||
StopSignal string
|
StopSignal string
|
||||||
|
|
||||||
|
// FIXME: VolumeDriver have been removed since docker 1.9
|
||||||
|
VolumeDriver string
|
||||||
|
|
||||||
// FIXME: The following fields have been removed since API v1.18
|
// FIXME: The following fields have been removed since API v1.18
|
||||||
Memory int64
|
Memory int64
|
||||||
MemorySwap int64
|
MemorySwap int64
|
||||||
|
@ -83,6 +85,7 @@ type HostConfig struct {
|
||||||
LogConfig LogConfig
|
LogConfig LogConfig
|
||||||
CgroupParent string
|
CgroupParent string
|
||||||
ConsoleSize [2]int
|
ConsoleSize [2]int
|
||||||
|
VolumeDriver string
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeviceMapping struct {
|
type DeviceMapping struct {
|
||||||
|
|
|
@ -505,7 +505,7 @@ func (e *Engine) Create(config *ContainerConfig, name string, pullImage bool) (*
|
||||||
|
|
||||||
if id, err = client.CreateContainer(&dockerConfig, name); err != nil {
|
if id, err = client.CreateContainer(&dockerConfig, name); err != nil {
|
||||||
// If the error is other than not found, abort immediately.
|
// If the error is other than not found, abort immediately.
|
||||||
if err != dockerclient.ErrNotFound || !pullImage {
|
if err != dockerclient.ErrImageNotFound || !pullImage {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Otherwise, try to pull the image...
|
// Otherwise, try to pull the image...
|
||||||
|
|
|
@ -200,9 +200,9 @@ func TestCreateContainer(t *testing.T) {
|
||||||
// Image not found, pullImage == false
|
// Image not found, pullImage == false
|
||||||
name = "test2"
|
name = "test2"
|
||||||
mockConfig.CpuShares = int64(math.Ceil(float64(config.CpuShares*1024) / float64(mockInfo.NCPU)))
|
mockConfig.CpuShares = int64(math.Ceil(float64(config.CpuShares*1024) / float64(mockInfo.NCPU)))
|
||||||
client.On("CreateContainer", &mockConfig, name).Return("", dockerclient.ErrNotFound).Once()
|
client.On("CreateContainer", &mockConfig, name).Return("", dockerclient.ErrImageNotFound).Once()
|
||||||
container, err = engine.Create(config, name, false)
|
container, err = engine.Create(config, name, false)
|
||||||
assert.Equal(t, err, dockerclient.ErrNotFound)
|
assert.Equal(t, err, dockerclient.ErrImageNotFound)
|
||||||
assert.Nil(t, container)
|
assert.Nil(t, container)
|
||||||
|
|
||||||
// Image not found, pullImage == true, and the image can be pulled successfully
|
// Image not found, pullImage == true, and the image can be pulled successfully
|
||||||
|
@ -210,7 +210,7 @@ func TestCreateContainer(t *testing.T) {
|
||||||
id = "id3"
|
id = "id3"
|
||||||
mockConfig.CpuShares = int64(math.Ceil(float64(config.CpuShares*1024) / float64(mockInfo.NCPU)))
|
mockConfig.CpuShares = int64(math.Ceil(float64(config.CpuShares*1024) / float64(mockInfo.NCPU)))
|
||||||
client.On("PullImage", config.Image+":latest", mock.Anything).Return(nil).Once()
|
client.On("PullImage", config.Image+":latest", mock.Anything).Return(nil).Once()
|
||||||
client.On("CreateContainer", &mockConfig, name).Return("", dockerclient.ErrNotFound).Once()
|
client.On("CreateContainer", &mockConfig, name).Return("", dockerclient.ErrImageNotFound).Once()
|
||||||
client.On("CreateContainer", &mockConfig, name).Return(id, nil).Once()
|
client.On("CreateContainer", &mockConfig, name).Return(id, nil).Once()
|
||||||
client.On("ListContainers", true, false, fmt.Sprintf(`{"id":[%q]}`, id)).Return([]dockerclient.Container{{Id: id}}, nil).Once()
|
client.On("ListContainers", true, false, fmt.Sprintf(`{"id":[%q]}`, id)).Return([]dockerclient.Container{{Id: id}}, nil).Once()
|
||||||
client.On("ListImages", mock.Anything).Return([]*dockerclient.Image{}, nil).Once()
|
client.On("ListImages", mock.Anything).Return([]*dockerclient.Image{}, nil).Once()
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -114,11 +115,14 @@ func (c *Cluster) CreateContainer(config *cluster.ContainerConfig, name string)
|
||||||
container, err := c.createContainer(config, name, false)
|
container, err := c.createContainer(config, name, false)
|
||||||
|
|
||||||
// fails with image not found, then try to reschedule with soft-image-affinity
|
// fails with image not found, then try to reschedule with soft-image-affinity
|
||||||
if err != nil && strings.HasSuffix(err.Error(), "not found") && !config.HaveNodeConstraint() {
|
if err != nil {
|
||||||
// Check if the image exists in the cluster
|
bImageNotFoundError, _ := regexp.MatchString(`image \S* not found`, err.Error())
|
||||||
// If exists, retry with a soft-image-affinity
|
if bImageNotFoundError && !config.HaveNodeConstraint() {
|
||||||
if image := c.Image(config.Image); image != nil {
|
// Check if the image exists in the cluster
|
||||||
container, err = c.createContainer(config, name, true)
|
// If exists, retry with a soft-image-affinity
|
||||||
|
if image := c.Image(config.Image); image != nil {
|
||||||
|
container, err = c.createContainer(config, name, true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return container, err
|
return container, err
|
||||||
|
|
|
@ -128,3 +128,19 @@ function teardown() {
|
||||||
[[ "${output}" != *"unable to find a node that satisfies"* ]]
|
[[ "${output}" != *"unable to find a node that satisfies"* ]]
|
||||||
[[ "${output}" == *"busyboxabcde:latest not found"* ]]
|
[[ "${output}" == *"busyboxabcde:latest not found"* ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "docker run - with not exist volume driver" {
|
||||||
|
start_docker_with_busybox 2
|
||||||
|
swarm_manage
|
||||||
|
|
||||||
|
# make sure no container exist
|
||||||
|
run docker_swarm ps -qa
|
||||||
|
[ "${#lines[@]}" -eq 0 ]
|
||||||
|
|
||||||
|
# run
|
||||||
|
run docker_swarm run -d --volume-driver=not_exist_volume_driver -v testvolume:/testvolume --name test_container busybox sleep 100
|
||||||
|
|
||||||
|
# check error message
|
||||||
|
[ "$status" -ne 0 ]
|
||||||
|
[[ "${output}" == *"Plugin not found"* ]]
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue