本文整理匯總了Golang中github.com/docker/docker/engine.Job.Environ方法的典型用法代碼示例。如果您正苦於以下問題:Golang Job.Environ方法的具體用法?Golang Job.Environ怎麽用?Golang Job.Environ使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/docker/docker/engine.Job
的用法示例。
在下文中一共展示了Job.Environ方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ContainerStart
func (daemon *Daemon) ContainerStart(job *engine.Job) engine.Status {
if len(job.Args) < 1 {
return job.Errorf("Usage: %s container_id", job.Name)
}
var (
name = job.Args[0]
container = daemon.Get(name)
)
if container == nil {
return job.Errorf("No such container: %s", name)
}
if container.IsRunning() {
return job.Errorf("Container already started")
}
// If no environment was set, then no hostconfig was passed.
if len(job.Environ()) > 0 {
hostConfig := runconfig.ContainerHostConfigFromJob(job)
if err := daemon.setHostConfig(container, hostConfig); err != nil {
return job.Error(err)
}
}
if err := container.Start(); err != nil {
return job.Errorf("Cannot start container %s: %s", name, err)
}
return engine.StatusOK
}
示例2: ContainerStart
func (daemon *Daemon) ContainerStart(job *engine.Job) engine.Status {
if len(job.Args) < 1 {
return job.Errorf("Usage: %s container_id", job.Name)
}
var (
name = job.Args[0]
container = daemon.Get(name)
)
if container == nil {
return job.Errorf("No such container: %s", name)
}
if container.IsRunning() {
return job.Errorf("Container already started")
}
// If no environment was set, then no hostconfig was passed.
// This is kept for backward compatibility - hostconfig should be passed when
// creating a container, not during start.
if len(job.Environ()) > 0 {
hostConfig := runconfig.ContainerHostConfigFromJob(job)
if err := daemon.setHostConfig(container, hostConfig); err != nil {
return job.Error(err)
}
}
if err := container.Start(); err != nil {
container.LogEvent("die")
return job.Errorf("Cannot start container %s: %s", name, err)
}
return engine.StatusOK
}
示例3: ContainerStart
func (srv *Server) ContainerStart(job *engine.Job) engine.Status {
if len(job.Args) < 1 {
return job.Errorf("Usage: %s container_id", job.Name)
}
var (
name = job.Args[0]
daemon = srv.daemon
container = daemon.Get(name)
)
if container == nil {
return job.Errorf("No such container: %s", name)
}
if container.State.IsRunning() {
return job.Errorf("Container already started")
}
// If no environment was set, then no hostconfig was passed.
if len(job.Environ()) > 0 {
hostConfig := runconfig.ContainerHostConfigFromJob(job)
if err := srv.setHostConfig(container, hostConfig); err != nil {
return job.Error(err)
}
}
if err := container.Start(); err != nil {
return job.Errorf("Cannot start container %s: %s", name, err)
}
srv.LogEvent("start", container.ID, daemon.Repositories().ImageName(container.Image))
return engine.StatusOK
}
示例4: ContainerStart
func (daemon *Daemon) ContainerStart(job *engine.Job) engine.Status {
if len(job.Args) < 1 {
return job.Errorf("Usage: %s container_id", job.Name)
}
var (
name = job.Args[0]
container = daemon.Get(name)
attach = job.GetenvBool("attach")
)
if container == nil {
return job.Errorf("No such container: %s", name)
}
if container.IsRunning() {
return job.Errorf("Container already started")
}
// If no environment was set, then no hostconfig was passed.
// This is kept for backward compatibility - hostconfig should be passed when
// creating a container, not during start.
if len(job.Environ()) > 0 {
hostConfig := runconfig.ContainerHostConfigFromJob(job)
if err := daemon.setHostConfig(container, hostConfig); err != nil {
return job.Error(err)
}
}
if err := container.Start(); err != nil {
container.LogEvent("die")
return job.Errorf("Cannot start container %s: %s", name, err)
}
if container.Config.MonitorDriver != MonitorBuiltin {
if attach {
// attach mode, call monitor server start API by client
loc := fmt.Sprintf("unix://%s/%s.sock", MonitorSockDir, container.ID)
out := &engine.Env{}
out.Set("redirect", loc)
if _, err := out.WriteTo(job.Stdout); err != nil {
return job.Error(err)
}
} else {
// Call monitor server start API
_, err := container.daemon.callMonitorAPI(container, "POST", "start")
if err != nil {
return job.Error(err)
}
}
}
return engine.StatusOK
}