зеркало из https://github.com/microsoft/docker.git
Merge pull request #1124 from crosbymichael/buildfile-volumes
+ Builder: Add VOLUME instruction to buildfile
This commit is contained in:
Коммит
637eceb6a7
21
buildfile.go
21
buildfile.go
|
@ -173,6 +173,27 @@ func (b *buildFile) CmdEntrypoint(args string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *buildFile) CmdVolume(args string) error {
|
||||||
|
if args == "" {
|
||||||
|
return fmt.Errorf("Volume cannot be empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
var volume []string
|
||||||
|
if err := json.Unmarshal([]byte(args), &volume); err != nil {
|
||||||
|
volume = []string{args}
|
||||||
|
}
|
||||||
|
if b.config.Volumes == nil {
|
||||||
|
b.config.Volumes = NewPathOpts()
|
||||||
|
}
|
||||||
|
for _, v := range volume {
|
||||||
|
b.config.Volumes[v] = struct{}{}
|
||||||
|
}
|
||||||
|
if err := b.commit("", b.config.Cmd, fmt.Sprintf("VOLUME %s", args)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (b *buildFile) addRemote(container *Container, orig, dest string) error {
|
func (b *buildFile) addRemote(container *Container, orig, dest string) error {
|
||||||
file, err := utils.Download(orig, ioutil.Discard)
|
file, err := utils.Download(orig, ioutil.Discard)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -87,6 +87,15 @@ run [ "$FOO" = "BAR" ]
|
||||||
from %s
|
from %s
|
||||||
ENTRYPOINT /bin/echo
|
ENTRYPOINT /bin/echo
|
||||||
CMD Hello world
|
CMD Hello world
|
||||||
|
`,
|
||||||
|
nil,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
`
|
||||||
|
from %s
|
||||||
|
VOLUME /test
|
||||||
|
CMD Hello world
|
||||||
`,
|
`,
|
||||||
nil,
|
nil,
|
||||||
},
|
},
|
||||||
|
@ -114,3 +123,39 @@ func TestBuild(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestVolume(t *testing.T) {
|
||||||
|
runtime, err := newTestRuntime()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer nuke(runtime)
|
||||||
|
|
||||||
|
srv := &Server{
|
||||||
|
runtime: runtime,
|
||||||
|
pullingPool: make(map[string]struct{}),
|
||||||
|
pushingPool: make(map[string]struct{}),
|
||||||
|
}
|
||||||
|
|
||||||
|
buildfile := NewBuildFile(srv, ioutil.Discard)
|
||||||
|
imgId, err := buildfile.Build(mkTestContext(`
|
||||||
|
from %s
|
||||||
|
VOLUME /test
|
||||||
|
CMD Hello world
|
||||||
|
`, nil, t))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
img, err := srv.ImageInspect(imgId)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(img.Config.Volumes) == 0 {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
for key, _ := range img.Config.Volumes {
|
||||||
|
if key != "/test" {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -160,6 +160,13 @@ files and directories are created with mode 0700, uid and gid 0.
|
||||||
|
|
||||||
The `ENTRYPOINT` instruction adds an entry command that will not be overwritten when arguments are passed to docker run, unlike the behavior of `CMD`. This allows arguments to be passed to the entrypoint. i.e. `docker run <image> -d` will pass the "-d" argument to the entrypoint.
|
The `ENTRYPOINT` instruction adds an entry command that will not be overwritten when arguments are passed to docker run, unlike the behavior of `CMD`. This allows arguments to be passed to the entrypoint. i.e. `docker run <image> -d` will pass the "-d" argument to the entrypoint.
|
||||||
|
|
||||||
|
2.9 VOLUME
|
||||||
|
----------
|
||||||
|
|
||||||
|
``VOLUME ["/data"]``
|
||||||
|
|
||||||
|
The `VOLUME` instruction will add one or more new volumes to any container created from the image.
|
||||||
|
|
||||||
3. Dockerfile Examples
|
3. Dockerfile Examples
|
||||||
======================
|
======================
|
||||||
|
|
||||||
|
|
3
utils.go
3
utils.go
|
@ -89,4 +89,7 @@ func MergeConfig(userConf, imageConf *Config) {
|
||||||
if userConf.Entrypoint == nil || len(userConf.Entrypoint) == 0 {
|
if userConf.Entrypoint == nil || len(userConf.Entrypoint) == 0 {
|
||||||
userConf.Entrypoint = imageConf.Entrypoint
|
userConf.Entrypoint = imageConf.Entrypoint
|
||||||
}
|
}
|
||||||
|
if userConf.Volumes == nil || len(userConf.Volumes) == 0 {
|
||||||
|
userConf.Volumes = imageConf.Volumes
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче