Example #1
0
// Pause container
func (container Container) pause() {
	if container.running() {
		if container.paused() {
			print.Noticef("Container %s is already paused.\n", container.Name())
		} else {
			fmt.Printf("Pausing container %s ... ", container.Name())
			args := []string{"pause", container.Name()}
			executeCommand("docker", args)
		}
	} else {
		print.Noticef("Container %s is not running.\n", container.Name())
	}
}
Example #2
0
// Push container
func (container Container) push() {
	if len(container.Image()) > 0 {
		fmt.Printf("Pushing image %s ... ", container.Image())
		args := []string{"push", container.Image()}
		executeCommand("docker", args)
	} else {
		print.Noticef("Skipping %s as it does not have an image name.\n", container.Name())
	}
}
Example #3
0
// Create container
func (c *container) Create() {
	if c.Exists() {
		print.Noticef("Container %s does already exist. Use --recreate to recreate.\n", c.Name())
	} else {
		fmt.Printf("Creating container %s ... ", c.Name())
		args := append([]string{"create"}, c.createArgs()...)
		executeCommand("docker", args)
	}
}
Example #4
0
// Run container, or start it if already existing
func (c *container) Run() {
	if c.Exists() {
		print.Noticef("Container %s does already exist. Use --recreate to recreate.\n", c.Name())
		if !c.Running() {
			c.Start()
		}
	} else {
		fmt.Printf("Running container %s ... ", c.Name())
		args := []string{"run"}
		// Detach
		if c.RunParams.Detach {
			args = append(args, "--detach")
		}
		args = append(args, c.createArgs()...)
		executeCommand("docker", args)
	}
}
Example #5
0
// Run container
func (container Container) run() {
	if container.exists() {
		print.Noticef("Container %s does already exist. Use --recreate to recreate.\n", container.Name())
		if !container.running() {
			container.start()
		}
	} else {
		fmt.Printf("Running container %s ... ", container.Name())
		// Assemble command arguments
		args := []string{"run"}
		// Cidfile
		if len(container.Run.Cidfile()) > 0 {
			args = append(args, "--cidfile", container.Run.Cidfile())
		}
		// CPU shares
		if container.Run.CpuShares > 0 {
			args = append(args, "--cpu-shares", strconv.Itoa(container.Run.CpuShares))
		}
		// Detach
		if container.Run.Detach {
			args = append(args, "--detach")
		}
		// Dns
		for _, dns := range container.Run.Dns() {
			args = append(args, "--dns", dns)
		}
		// Entrypoint
		if len(container.Run.Entrypoint()) > 0 {
			args = append(args, "--entrypoint", container.Run.Entrypoint())
		}
		// Env
		for _, env := range container.Run.Env() {
			args = append(args, "--env", env)
		}
		// Env file
		if len(container.Run.EnvFile()) > 0 {
			args = append(args, "--env-file", container.Run.EnvFile())
		}
		// Expose
		for _, expose := range container.Run.Expose() {
			args = append(args, "--expose", expose)
		}
		// Host
		if len(container.Run.Hostname()) > 0 {
			args = append(args, "--hostname", container.Run.Hostname())
		}
		// Interactive
		if container.Run.Interactive {
			args = append(args, "--interactive")
		}
		// Link
		for _, link := range container.Run.Link() {
			args = append(args, "--link", link)
		}
		// LxcConf
		for _, lxcConf := range container.Run.LxcConf() {
			args = append(args, "--lxc-conf", lxcConf)
		}
		// Memory
		if len(container.Run.Memory()) > 0 {
			args = append(args, "--memory", container.Run.Memory())
		}
		// Net
		if container.Run.Net() != "bridge" {
			args = append(args, "--net", container.Run.Net())
		}
		// Privileged
		if container.Run.Privileged {
			args = append(args, "--privileged")
		}
		// Publish
		for _, port := range container.Run.Publish() {
			args = append(args, "--publish", port)
		}
		// PublishAll
		if container.Run.PublishAll {
			args = append(args, "--publish-all")
		}
		// Rm
		if container.Run.Rm {
			args = append(args, "--rm")
		}
		// Tty
		if container.Run.Tty {
			args = append(args, "--tty")
		}
		// User
		if len(container.Run.User()) > 0 {
			args = append(args, "--user", container.Run.User())
		}
		// Volumes
		for _, volume := range container.Run.Volume() {
			args = append(args, "--volume", volume)
		}
		// VolumesFrom
		for _, volumeFrom := range container.Run.VolumesFrom() {
			args = append(args, "--volumes-from", volumeFrom)
		}
		// Workdir
		if len(container.Run.Workdir()) > 0 {
			args = append(args, "--workdir", container.Run.Workdir())
		}
		// Name
		args = append(args, "--name", container.Name())
		// Image
		args = append(args, container.Image())
		// Command
		args = append(args, container.Run.Cmd()...)
		// Execute command
		executeCommand("docker", args)
	}
}