Monday, September 11, 2017
Hi everybody! welcome back to war !!!! so we want to writerun a code that uploads an image to docker...
// start all services required for the build
// that will get linked to the container.
for _, service := range b.Build.Services {
// Parse the name of the Docker image
// And then construct a fully qualified image name
owner, name, tag := parseImageName(service)
cname := fmt.Sprintf("%s/%s:%s", owner, name, tag)
// Get the image info
img, err := b.dockerClient.Images.Inspect(cname)
if err != nil {
// Get the image if it doesn't exist
if err := b.dockerClient.Images.Pull(cname); err != nil {
return fmt.Errorf("Error: Unable to pull image %s", cname)
}
img, err = b.dockerClient.Images.Inspect(cname)
if err != nil {
return fmt.Errorf("Error: Invalid or unknown image %s", cname)
}
}
// debugging
log.Infof("starting service container %s", cname)
// Run the contianer
run, err := b.dockerClient.Containers.RunDaemonPorts(cname, img.Config.ExposedPorts)
if err != nil {
return err
}
// Get the container info
info, err := b.dockerClient.Containers.Inspect(run.ID)
if err != nil {
// on error kill the container since it hasn't yet been
// added to the array and would therefore not get
// removed in the defer statement.
b.dockerClient.Containers.Stop(run.ID, 10)
b.dockerClient.Containers.Remove(run.ID)
return err
}
// Add the running service to the list
b.services = append(b.services, info)
}
https://searchcode.com/codesearch/view/86051745/
Subscribe to:
Posts (Atom)