| ... | ... |
@@ -803,18 +803,18 @@ func (srv *Server) CmdTag(stdin io.ReadCloser, stdout io.Writer, args ...string) |
| 803 | 803 |
} |
| 804 | 804 |
|
| 805 | 805 |
func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
|
| 806 |
- image, config, err := ParseRun(args) |
|
| 806 |
+ config, err := ParseRun(args) |
|
| 807 | 807 |
if err != nil {
|
| 808 | 808 |
return err |
| 809 | 809 |
} |
| 810 |
- if image == "" {
|
|
| 810 |
+ if config.Image == "" {
|
|
| 811 | 811 |
return fmt.Errorf("Image not specified")
|
| 812 | 812 |
} |
| 813 | 813 |
if len(config.Cmd) == 0 {
|
| 814 | 814 |
return fmt.Errorf("Command not specified")
|
| 815 | 815 |
} |
| 816 | 816 |
// Create new container |
| 817 |
- container, err := srv.runtime.Create(image, config) |
|
| 817 |
+ container, err := srv.runtime.Create(config) |
|
| 818 | 818 |
if err != nil {
|
| 819 | 819 |
return errors.New("Error creating container: " + err.Error())
|
| 820 | 820 |
} |
| ... | ... |
@@ -57,9 +57,10 @@ type Config struct {
|
| 57 | 57 |
OpenStdin bool // Open stdin |
| 58 | 58 |
Env []string |
| 59 | 59 |
Cmd []string |
| 60 |
+ Image string // Name of the image as it was passed by the operator (eg. could be symbolic) |
|
| 60 | 61 |
} |
| 61 | 62 |
|
| 62 |
-func ParseRun(args []string) (string, *Config, error) {
|
|
| 63 |
+func ParseRun(args []string) (*Config, error) {
|
|
| 63 | 64 |
cmd := flag.NewFlagSet("", flag.ContinueOnError)
|
| 64 | 65 |
cmd.SetOutput(ioutil.Discard) |
| 65 | 66 |
fl_user := cmd.String("u", "", "Username or UID")
|
| ... | ... |
@@ -73,9 +74,8 @@ func ParseRun(args []string) (string, *Config, error) {
|
| 73 | 73 |
var fl_env ListOpts |
| 74 | 74 |
cmd.Var(&fl_env, "e", "Set environment variables") |
| 75 | 75 |
if err := cmd.Parse(args); err != nil {
|
| 76 |
- return "", nil, err |
|
| 76 |
+ return nil, err |
|
| 77 | 77 |
} |
| 78 |
- image := cmd.Arg(0) |
|
| 79 | 78 |
config := &Config{
|
| 80 | 79 |
Ports: fl_ports, |
| 81 | 80 |
User: *fl_user, |
| ... | ... |
@@ -85,8 +85,9 @@ func ParseRun(args []string) (string, *Config, error) {
|
| 85 | 85 |
Detach: *fl_detach, |
| 86 | 86 |
Env: fl_env, |
| 87 | 87 |
Cmd: cmd.Args()[1:], |
| 88 |
+ Image: cmd.Arg(0), |
|
| 88 | 89 |
} |
| 89 |
- return image, config, nil |
|
| 90 |
+ return config, nil |
|
| 90 | 91 |
} |
| 91 | 92 |
|
| 92 | 93 |
type NetworkSettings struct {
|
| ... | ... |
@@ -20,8 +20,8 @@ func TestCommitRun(t *testing.T) {
|
| 20 | 20 |
} |
| 21 | 21 |
defer nuke(runtime) |
| 22 | 22 |
container1, err := runtime.Create( |
| 23 |
- GetTestImage(runtime).Id, |
|
| 24 | 23 |
&Config{
|
| 24 |
+ Image: GetTestImage(runtime).Id, |
|
| 25 | 25 |
Cmd: []string{"/bin/sh", "-c", "echo hello > /world"},
|
| 26 | 26 |
Memory: 33554432, |
| 27 | 27 |
}, |
| ... | ... |
@@ -53,8 +53,8 @@ func TestCommitRun(t *testing.T) {
|
| 53 | 53 |
// FIXME: Make a TestCommit that stops here and check docker.root/layers/img.id/world |
| 54 | 54 |
|
| 55 | 55 |
container2, err := runtime.Create( |
| 56 |
- img.Id, |
|
| 57 | 56 |
&Config{
|
| 57 |
+ Image: img.Id, |
|
| 58 | 58 |
Memory: 33554432, |
| 59 | 59 |
Cmd: []string{"cat", "/world"},
|
| 60 | 60 |
}, |
| ... | ... |
@@ -86,8 +86,8 @@ func TestRun(t *testing.T) {
|
| 86 | 86 |
} |
| 87 | 87 |
defer nuke(runtime) |
| 88 | 88 |
container, err := runtime.Create( |
| 89 |
- GetTestImage(runtime).Id, |
|
| 90 | 89 |
&Config{
|
| 90 |
+ Image: GetTestImage(runtime).Id, |
|
| 91 | 91 |
Memory: 33554432, |
| 92 | 92 |
Cmd: []string{"ls", "-al"},
|
| 93 | 93 |
}, |
| ... | ... |
@@ -115,9 +115,9 @@ func TestOutput(t *testing.T) {
|
| 115 | 115 |
} |
| 116 | 116 |
defer nuke(runtime) |
| 117 | 117 |
container, err := runtime.Create( |
| 118 |
- GetTestImage(runtime).Id, |
|
| 119 | 118 |
&Config{
|
| 120 |
- Cmd: []string{"echo", "-n", "foobar"},
|
|
| 119 |
+ Image: GetTestImage(runtime).Id, |
|
| 120 |
+ Cmd: []string{"echo", "-n", "foobar"},
|
|
| 121 | 121 |
}, |
| 122 | 122 |
) |
| 123 | 123 |
if err != nil {
|
| ... | ... |
@@ -139,8 +139,9 @@ func TestKill(t *testing.T) {
|
| 139 | 139 |
t.Fatal(err) |
| 140 | 140 |
} |
| 141 | 141 |
defer nuke(runtime) |
| 142 |
- container, err := runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 143 |
- Cmd: []string{"cat", "/dev/zero"},
|
|
| 142 |
+ container, err := runtime.Create(&Config{
|
|
| 143 |
+ Image: GetTestImage(runtime).Id, |
|
| 144 |
+ Cmd: []string{"cat", "/dev/zero"},
|
|
| 144 | 145 |
}, |
| 145 | 146 |
) |
| 146 | 147 |
if err != nil {
|
| ... | ... |
@@ -180,8 +181,10 @@ func TestExitCode(t *testing.T) {
|
| 180 | 180 |
} |
| 181 | 181 |
defer nuke(runtime) |
| 182 | 182 |
|
| 183 |
- trueContainer, err := runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 184 |
- Cmd: []string{"/bin/true", ""},
|
|
| 183 |
+ trueContainer, err := runtime.Create(&Config{
|
|
| 184 |
+ |
|
| 185 |
+ Image: GetTestImage(runtime).Id, |
|
| 186 |
+ Cmd: []string{"/bin/true", ""},
|
|
| 185 | 187 |
}, |
| 186 | 188 |
) |
| 187 | 189 |
if err != nil {
|
| ... | ... |
@@ -192,8 +195,9 @@ func TestExitCode(t *testing.T) {
|
| 192 | 192 |
t.Fatal(err) |
| 193 | 193 |
} |
| 194 | 194 |
|
| 195 |
- falseContainer, err := runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 196 |
- Cmd: []string{"/bin/false", ""},
|
|
| 195 |
+ falseContainer, err := runtime.Create(&Config{
|
|
| 196 |
+ Image: GetTestImage(runtime).Id, |
|
| 197 |
+ Cmd: []string{"/bin/false", ""},
|
|
| 197 | 198 |
}, |
| 198 | 199 |
) |
| 199 | 200 |
if err != nil {
|
| ... | ... |
@@ -219,8 +223,9 @@ func TestRestart(t *testing.T) {
|
| 219 | 219 |
t.Fatal(err) |
| 220 | 220 |
} |
| 221 | 221 |
defer nuke(runtime) |
| 222 |
- container, err := runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 223 |
- Cmd: []string{"echo", "-n", "foobar"},
|
|
| 222 |
+ container, err := runtime.Create(&Config{
|
|
| 223 |
+ Image: GetTestImage(runtime).Id, |
|
| 224 |
+ Cmd: []string{"echo", "-n", "foobar"},
|
|
| 224 | 225 |
}, |
| 225 | 226 |
) |
| 226 | 227 |
if err != nil {
|
| ... | ... |
@@ -251,8 +256,9 @@ func TestRestartStdin(t *testing.T) {
|
| 251 | 251 |
t.Fatal(err) |
| 252 | 252 |
} |
| 253 | 253 |
defer nuke(runtime) |
| 254 |
- container, err := runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 255 |
- Cmd: []string{"cat"},
|
|
| 254 |
+ container, err := runtime.Create(&Config{
|
|
| 255 |
+ Image: GetTestImage(runtime).Id, |
|
| 256 |
+ Cmd: []string{"cat"},
|
|
| 256 | 257 |
|
| 257 | 258 |
OpenStdin: true, |
| 258 | 259 |
}, |
| ... | ... |
@@ -300,8 +306,9 @@ func TestUser(t *testing.T) {
|
| 300 | 300 |
defer nuke(runtime) |
| 301 | 301 |
|
| 302 | 302 |
// Default user must be root |
| 303 |
- container, err := runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 304 |
- Cmd: []string{"id"},
|
|
| 303 |
+ container, err := runtime.Create(&Config{
|
|
| 304 |
+ Image: GetTestImage(runtime).Id, |
|
| 305 |
+ Cmd: []string{"id"},
|
|
| 305 | 306 |
}, |
| 306 | 307 |
) |
| 307 | 308 |
if err != nil {
|
| ... | ... |
@@ -317,8 +324,9 @@ func TestUser(t *testing.T) {
|
| 317 | 317 |
} |
| 318 | 318 |
|
| 319 | 319 |
// Set a username |
| 320 |
- container, err = runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 321 |
- Cmd: []string{"id"},
|
|
| 320 |
+ container, err = runtime.Create(&Config{
|
|
| 321 |
+ Image: GetTestImage(runtime).Id, |
|
| 322 |
+ Cmd: []string{"id"},
|
|
| 322 | 323 |
|
| 323 | 324 |
User: "root", |
| 324 | 325 |
}, |
| ... | ... |
@@ -336,8 +344,9 @@ func TestUser(t *testing.T) {
|
| 336 | 336 |
} |
| 337 | 337 |
|
| 338 | 338 |
// Set a UID |
| 339 |
- container, err = runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 340 |
- Cmd: []string{"id"},
|
|
| 339 |
+ container, err = runtime.Create(&Config{
|
|
| 340 |
+ Image: GetTestImage(runtime).Id, |
|
| 341 |
+ Cmd: []string{"id"},
|
|
| 341 | 342 |
|
| 342 | 343 |
User: "0", |
| 343 | 344 |
}, |
| ... | ... |
@@ -355,8 +364,9 @@ func TestUser(t *testing.T) {
|
| 355 | 355 |
} |
| 356 | 356 |
|
| 357 | 357 |
// Set a different user by uid |
| 358 |
- container, err = runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 359 |
- Cmd: []string{"id"},
|
|
| 358 |
+ container, err = runtime.Create(&Config{
|
|
| 359 |
+ Image: GetTestImage(runtime).Id, |
|
| 360 |
+ Cmd: []string{"id"},
|
|
| 360 | 361 |
|
| 361 | 362 |
User: "1", |
| 362 | 363 |
}, |
| ... | ... |
@@ -376,8 +386,9 @@ func TestUser(t *testing.T) {
|
| 376 | 376 |
} |
| 377 | 377 |
|
| 378 | 378 |
// Set a different user by username |
| 379 |
- container, err = runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 380 |
- Cmd: []string{"id"},
|
|
| 379 |
+ container, err = runtime.Create(&Config{
|
|
| 380 |
+ Image: GetTestImage(runtime).Id, |
|
| 381 |
+ Cmd: []string{"id"},
|
|
| 381 | 382 |
|
| 382 | 383 |
User: "daemon", |
| 383 | 384 |
}, |
| ... | ... |
@@ -402,8 +413,9 @@ func TestMultipleContainers(t *testing.T) {
|
| 402 | 402 |
} |
| 403 | 403 |
defer nuke(runtime) |
| 404 | 404 |
|
| 405 |
- container1, err := runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 406 |
- Cmd: []string{"cat", "/dev/zero"},
|
|
| 405 |
+ container1, err := runtime.Create(&Config{
|
|
| 406 |
+ Image: GetTestImage(runtime).Id, |
|
| 407 |
+ Cmd: []string{"cat", "/dev/zero"},
|
|
| 407 | 408 |
}, |
| 408 | 409 |
) |
| 409 | 410 |
if err != nil {
|
| ... | ... |
@@ -411,8 +423,9 @@ func TestMultipleContainers(t *testing.T) {
|
| 411 | 411 |
} |
| 412 | 412 |
defer runtime.Destroy(container1) |
| 413 | 413 |
|
| 414 |
- container2, err := runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 415 |
- Cmd: []string{"cat", "/dev/zero"},
|
|
| 414 |
+ container2, err := runtime.Create(&Config{
|
|
| 415 |
+ Image: GetTestImage(runtime).Id, |
|
| 416 |
+ Cmd: []string{"cat", "/dev/zero"},
|
|
| 416 | 417 |
}, |
| 417 | 418 |
) |
| 418 | 419 |
if err != nil {
|
| ... | ... |
@@ -452,8 +465,9 @@ func TestStdin(t *testing.T) {
|
| 452 | 452 |
t.Fatal(err) |
| 453 | 453 |
} |
| 454 | 454 |
defer nuke(runtime) |
| 455 |
- container, err := runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 456 |
- Cmd: []string{"cat"},
|
|
| 455 |
+ container, err := runtime.Create(&Config{
|
|
| 456 |
+ Image: GetTestImage(runtime).Id, |
|
| 457 |
+ Cmd: []string{"cat"},
|
|
| 457 | 458 |
|
| 458 | 459 |
OpenStdin: true, |
| 459 | 460 |
}, |
| ... | ... |
@@ -485,8 +499,9 @@ func TestTty(t *testing.T) {
|
| 485 | 485 |
t.Fatal(err) |
| 486 | 486 |
} |
| 487 | 487 |
defer nuke(runtime) |
| 488 |
- container, err := runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 489 |
- Cmd: []string{"cat"},
|
|
| 488 |
+ container, err := runtime.Create(&Config{
|
|
| 489 |
+ Image: GetTestImage(runtime).Id, |
|
| 490 |
+ Cmd: []string{"cat"},
|
|
| 490 | 491 |
|
| 491 | 492 |
OpenStdin: true, |
| 492 | 493 |
}, |
| ... | ... |
@@ -518,8 +533,9 @@ func TestEnv(t *testing.T) {
|
| 518 | 518 |
t.Fatal(err) |
| 519 | 519 |
} |
| 520 | 520 |
defer nuke(runtime) |
| 521 |
- container, err := runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 522 |
- Cmd: []string{"/usr/bin/env"},
|
|
| 521 |
+ container, err := runtime.Create(&Config{
|
|
| 522 |
+ Image: GetTestImage(runtime).Id, |
|
| 523 |
+ Cmd: []string{"/usr/bin/env"},
|
|
| 523 | 524 |
}, |
| 524 | 525 |
) |
| 525 | 526 |
if err != nil {
|
| ... | ... |
@@ -590,8 +606,9 @@ func TestLXCConfig(t *testing.T) {
|
| 590 | 590 |
memMin := 33554432 |
| 591 | 591 |
memMax := 536870912 |
| 592 | 592 |
mem := memMin + rand.Intn(memMax-memMin) |
| 593 |
- container, err := runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 594 |
- Cmd: []string{"/bin/true"},
|
|
| 593 |
+ container, err := runtime.Create(&Config{
|
|
| 594 |
+ Image: GetTestImage(runtime).Id, |
|
| 595 |
+ Cmd: []string{"/bin/true"},
|
|
| 595 | 596 |
|
| 596 | 597 |
Hostname: "foobar", |
| 597 | 598 |
Memory: int64(mem), |
| ... | ... |
@@ -616,8 +633,9 @@ func BenchmarkRunSequencial(b *testing.B) {
|
| 616 | 616 |
} |
| 617 | 617 |
defer nuke(runtime) |
| 618 | 618 |
for i := 0; i < b.N; i++ {
|
| 619 |
- container, err := runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 620 |
- Cmd: []string{"echo", "-n", "foo"},
|
|
| 619 |
+ container, err := runtime.Create(&Config{
|
|
| 620 |
+ Image: GetTestImage(runtime).Id, |
|
| 621 |
+ Cmd: []string{"echo", "-n", "foo"},
|
|
| 621 | 622 |
}, |
| 622 | 623 |
) |
| 623 | 624 |
if err != nil {
|
| ... | ... |
@@ -650,8 +668,9 @@ func BenchmarkRunParallel(b *testing.B) {
|
| 650 | 650 |
complete := make(chan error) |
| 651 | 651 |
tasks = append(tasks, complete) |
| 652 | 652 |
go func(i int, complete chan error) {
|
| 653 |
- container, err := runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 654 |
- Cmd: []string{"echo", "-n", "foo"},
|
|
| 653 |
+ container, err := runtime.Create(&Config{
|
|
| 654 |
+ Image: GetTestImage(runtime).Id, |
|
| 655 |
+ Cmd: []string{"echo", "-n", "foo"},
|
|
| 655 | 656 |
}, |
| 656 | 657 |
) |
| 657 | 658 |
if err != nil {
|
| ... | ... |
@@ -64,9 +64,9 @@ func (runtime *Runtime) containerRoot(id string) string {
|
| 64 | 64 |
return path.Join(runtime.repository, id) |
| 65 | 65 |
} |
| 66 | 66 |
|
| 67 |
-func (runtime *Runtime) Create(image string, config *Config) (*Container, error) {
|
|
| 67 |
+func (runtime *Runtime) Create(config *Config) (*Container, error) {
|
|
| 68 | 68 |
// Lookup image |
| 69 |
- img, err := runtime.repositories.LookupImage(image) |
|
| 69 |
+ img, err := runtime.repositories.LookupImage(config.Image) |
|
| 70 | 70 |
if err != nil {
|
| 71 | 71 |
return nil, err |
| 72 | 72 |
} |
| ... | ... |
@@ -112,8 +112,9 @@ func TestRuntimeCreate(t *testing.T) {
|
| 112 | 112 |
if len(runtime.List()) != 0 {
|
| 113 | 113 |
t.Errorf("Expected 0 containers, %v found", len(runtime.List()))
|
| 114 | 114 |
} |
| 115 |
- container, err := runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 116 |
- Cmd: []string{"ls", "-al"},
|
|
| 115 |
+ container, err := runtime.Create(&Config{
|
|
| 116 |
+ Image: GetTestImage(runtime).Id, |
|
| 117 |
+ Cmd: []string{"ls", "-al"},
|
|
| 117 | 118 |
}, |
| 118 | 119 |
) |
| 119 | 120 |
if err != nil {
|
| ... | ... |
@@ -158,8 +159,9 @@ func TestDestroy(t *testing.T) {
|
| 158 | 158 |
t.Fatal(err) |
| 159 | 159 |
} |
| 160 | 160 |
defer nuke(runtime) |
| 161 |
- container, err := runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 162 |
- Cmd: []string{"ls", "-al"},
|
|
| 161 |
+ container, err := runtime.Create(&Config{
|
|
| 162 |
+ Image: GetTestImage(runtime).Id, |
|
| 163 |
+ Cmd: []string{"ls", "-al"},
|
|
| 163 | 164 |
}, |
| 164 | 165 |
) |
| 165 | 166 |
if err != nil {
|
| ... | ... |
@@ -204,8 +206,9 @@ func TestGet(t *testing.T) {
|
| 204 | 204 |
t.Fatal(err) |
| 205 | 205 |
} |
| 206 | 206 |
defer nuke(runtime) |
| 207 |
- container1, err := runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 208 |
- Cmd: []string{"ls", "-al"},
|
|
| 207 |
+ container1, err := runtime.Create(&Config{
|
|
| 208 |
+ Image: GetTestImage(runtime).Id, |
|
| 209 |
+ Cmd: []string{"ls", "-al"},
|
|
| 209 | 210 |
}, |
| 210 | 211 |
) |
| 211 | 212 |
if err != nil {
|
| ... | ... |
@@ -213,8 +216,9 @@ func TestGet(t *testing.T) {
|
| 213 | 213 |
} |
| 214 | 214 |
defer runtime.Destroy(container1) |
| 215 | 215 |
|
| 216 |
- container2, err := runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 217 |
- Cmd: []string{"ls", "-al"},
|
|
| 216 |
+ container2, err := runtime.Create(&Config{
|
|
| 217 |
+ Image: GetTestImage(runtime).Id, |
|
| 218 |
+ Cmd: []string{"ls", "-al"},
|
|
| 218 | 219 |
}, |
| 219 | 220 |
) |
| 220 | 221 |
if err != nil {
|
| ... | ... |
@@ -222,8 +226,9 @@ func TestGet(t *testing.T) {
|
| 222 | 222 |
} |
| 223 | 223 |
defer runtime.Destroy(container2) |
| 224 | 224 |
|
| 225 |
- container3, err := runtime.Create(GetTestImage(runtime).Id, &Config{
|
|
| 226 |
- Cmd: []string{"ls", "-al"},
|
|
| 225 |
+ container3, err := runtime.Create(&Config{
|
|
| 226 |
+ Image: GetTestImage(runtime).Id, |
|
| 227 |
+ Cmd: []string{"ls", "-al"},
|
|
| 227 | 228 |
}, |
| 228 | 229 |
) |
| 229 | 230 |
if err != nil {
|
| ... | ... |
@@ -264,8 +269,9 @@ func TestRestore(t *testing.T) {
|
| 264 | 264 |
} |
| 265 | 265 |
|
| 266 | 266 |
// Create a container with one instance of docker |
| 267 |
- container1, err := runtime1.Create(GetTestImage(runtime1).Id, &Config{
|
|
| 268 |
- Cmd: []string{"ls", "-al"},
|
|
| 267 |
+ container1, err := runtime1.Create(&Config{
|
|
| 268 |
+ Image: GetTestImage(runtime1).Id, |
|
| 269 |
+ Cmd: []string{"ls", "-al"},
|
|
| 269 | 270 |
}, |
| 270 | 271 |
) |
| 271 | 272 |
if err != nil {
|