本文整理汇总了Golang中github.com/docker/docker/api/client.DockerCli.Err方法的典型用法代码示例。如果您正苦于以下问题:Golang DockerCli.Err方法的具体用法?Golang DockerCli.Err怎么用?Golang DockerCli.Err使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/docker/docker/api/client.DockerCli
的用法示例。
在下文中一共展示了DockerCli.Err方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: inspectAll
func inspectAll(ctx context.Context, dockerCli *client.DockerCli, getSize bool) inspect.GetRefFunc {
client := dockerCli.Client()
return func(ref string) (interface{}, []byte, error) {
c, rawContainer, err := client.ContainerInspectWithRaw(ctx, ref, getSize)
if err == nil || !apiclient.IsErrNotFound(err) {
return c, rawContainer, err
}
// Search for image with that id if a container doesn't exist.
i, rawImage, err := client.ImageInspectWithRaw(ctx, ref)
if err == nil || !apiclient.IsErrNotFound(err) {
return i, rawImage, err
}
// Search for task with that id if an image doesn't exist.
t, rawTask, err := client.TaskInspectWithRaw(ctx, ref)
if err == nil || !(apiclient.IsErrNotFound(err) || isErrorNoSwarmMode(err)) {
if getSize {
fmt.Fprintln(dockerCli.Err(), "WARNING: --size ignored for tasks")
}
return t, rawTask, err
}
return nil, nil, fmt.Errorf("Error: No such container, image or task: %s", ref)
}
}
示例2: ForwardAllSignals
// ForwardAllSignals forwards signals to the container
func ForwardAllSignals(ctx context.Context, cli *client.DockerCli, cid string) chan os.Signal {
sigc := make(chan os.Signal, 128)
signal.CatchAll(sigc)
go func() {
for s := range sigc {
if s == signal.SIGCHLD || s == signal.SIGPIPE {
continue
}
var sig string
for sigStr, sigN := range signal.SignalMap {
if sigN == s {
sig = sigStr
break
}
}
if sig == "" {
fmt.Fprintf(cli.Err(), "Unsupported signal: %v. Discarding.\n", s)
continue
}
if err := cli.Client().ContainerKill(ctx, cid, sig); err != nil {
logrus.Debugf("Error sending signal: %s", err)
}
}
}()
return sigc
}
示例3: runLogs
func runLogs(dockerCli *client.DockerCli, opts *logsOptions) error {
ctx := context.Background()
c, err := dockerCli.Client().ContainerInspect(ctx, opts.container)
if err != nil {
return err
}
if !validDrivers[c.HostConfig.LogConfig.Type] {
return fmt.Errorf("\"logs\" command is supported only for \"json-file\" and \"journald\" logging drivers (got: %s)", c.HostConfig.LogConfig.Type)
}
options := types.ContainerLogsOptions{
ShowStdout: true,
ShowStderr: true,
Since: opts.since,
Timestamps: opts.timestamps,
Follow: opts.follow,
Tail: opts.tail,
Details: opts.details,
}
responseBody, err := dockerCli.Client().ContainerLogs(ctx, opts.container, options)
if err != nil {
return err
}
defer responseBody.Close()
if c.Config.Tty {
_, err = io.Copy(dockerCli.Out(), responseBody)
} else {
_, err = stdcopy.StdCopy(dockerCli.Out(), dockerCli.Err(), responseBody)
}
return err
}
示例4: runConfig
func runConfig(dockerCli *client.DockerCli, opts configOptions) error {
bundle, err := loadBundlefile(dockerCli.Err(), opts.namespace, opts.bundlefile)
if err != nil {
return err
}
return bundlefile.Print(dockerCli.Out(), bundle)
}
示例5: runInspect
func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error {
ctx := context.Background()
client := dockerCli.Client()
var getRefFunc inspect.GetRefFunc
switch opts.inspectType {
case "container":
getRefFunc = func(ref string) (interface{}, []byte, error) {
return client.ContainerInspectWithRaw(ctx, ref, opts.size)
}
case "image":
getRefFunc = func(ref string) (interface{}, []byte, error) {
return client.ImageInspectWithRaw(ctx, ref)
}
case "task":
if opts.size {
fmt.Fprintln(dockerCli.Err(), "WARNING: --size ignored for tasks")
}
getRefFunc = func(ref string) (interface{}, []byte, error) {
return client.TaskInspectWithRaw(ctx, ref)
}
case "":
getRefFunc = inspectAll(ctx, dockerCli, opts.size)
default:
return fmt.Errorf("%q is not a valid value for --type", opts.inspectType)
}
return inspect.Inspect(dockerCli.Out(), opts.ids, opts.format, getRefFunc)
}
示例6: newCreateCommand
func newCreateCommand(dockerCli *client.DockerCli) *cobra.Command {
opts := createOptions{
driverOpts: *opts.NewMapOpts(nil, nil),
}
cmd := &cobra.Command{
Use: "create [OPTIONS] [VOLUME]",
Short: "Create a volume",
Long: createDescription,
Args: cli.RequiresMaxArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 1 {
if opts.name != "" {
fmt.Fprint(dockerCli.Err(), "Conflicting options: either specify --name or provide positional arg, not both\n")
return cli.StatusError{StatusCode: 1}
}
opts.name = args[0]
}
return runCreate(dockerCli, opts)
},
}
flags := cmd.Flags()
flags.StringVarP(&opts.driver, "driver", "d", "local", "Specify volume driver name")
flags.StringVar(&opts.name, "name", "", "Specify volume name")
flags.Lookup("name").Hidden = true
flags.VarP(&opts.driverOpts, "opt", "o", "Set driver specific options")
flags.StringSliceVar(&opts.labels, "label", []string{}, "Set metadata for a volume")
return cmd
}
示例7: runCreate
func runCreate(dockerCli *client.DockerCli, flags *pflag.FlagSet, opts *createOptions, copts *runconfigopts.ContainerOptions) error {
config, hostConfig, networkingConfig, err := runconfigopts.Parse(flags, copts)
if err != nil {
reportError(dockerCli.Err(), "create", err.Error(), true)
return cli.StatusError{StatusCode: 125}
}
response, err := createContainer(context.Background(), dockerCli, config, hostConfig, networkingConfig, hostConfig.ContainerIDFile, opts.name)
if err != nil {
return err
}
fmt.Fprintf(dockerCli.Out(), "%s\n", response.ID)
return nil
}
示例8: runDeploy
func runDeploy(dockerCli *client.DockerCli, opts deployOptions) error {
bundle, err := loadBundlefile(dockerCli.Err(), opts.namespace, opts.bundlefile)
if err != nil {
return err
}
networks := getUniqueNetworkNames(bundle.Services)
ctx := context.Background()
if err := updateNetworks(ctx, dockerCli, networks, opts.namespace); err != nil {
return err
}
return deployServices(ctx, dockerCli, bundle.Services, opts.namespace)
}
示例9: startContainersWithoutAttachments
func startContainersWithoutAttachments(dockerCli *client.DockerCli, ctx context.Context, containers []string) error {
var failedContainers []string
for _, container := range containers {
if err := dockerCli.Client().ContainerStart(ctx, container, types.ContainerStartOptions{}); err != nil {
fmt.Fprintf(dockerCli.Err(), "%s\n", err)
failedContainers = append(failedContainers, container)
} else {
fmt.Fprintf(dockerCli.Out(), "%s\n", container)
}
}
if len(failedContainers) > 0 {
return fmt.Errorf("Error: failed to start containers: %v", strings.Join(failedContainers, ", "))
}
return nil
}
示例10: runRename
func runRename(dockerCli *client.DockerCli, opts *renameOptions) error {
ctx := context.Background()
oldName := strings.TrimSpace(opts.oldName)
newName := strings.TrimSpace(opts.newName)
if oldName == "" || newName == "" {
return fmt.Errorf("Error: Neither old nor new names may be empty")
}
if err := dockerCli.Client().ContainerRename(ctx, oldName, newName); err != nil {
fmt.Fprintf(dockerCli.Err(), "%s\n", err)
return fmt.Errorf("Error: failed to rename container named %s", oldName)
}
return nil
}
示例11: NewVolumeCommand
// NewVolumeCommand returns a cobra command for `volume` subcommands
func NewVolumeCommand(dockerCli *client.DockerCli) *cobra.Command {
cmd := &cobra.Command{
Use: "volume",
Short: "Manage Docker volumes",
Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString())
},
}
cmd.AddCommand(
newCreateCommand(dockerCli),
newInspectCommand(dockerCli),
newListCommand(dockerCli),
newRemoveCommand(dockerCli),
)
return cmd
}
示例12: NewStackCommand
// NewStackCommand returns a cobra command for `stack` subcommands
func NewStackCommand(dockerCli *client.DockerCli) *cobra.Command {
cmd := &cobra.Command{
Use: "stack",
Short: "Manage Docker stacks",
Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString())
},
}
cmd.AddCommand(
newConfigCommand(dockerCli),
newDeployCommand(dockerCli),
newRemoveCommand(dockerCli),
newTasksCommand(dockerCli),
)
return cmd
}
示例13: runLogout
func runLogout(dockerCli *client.DockerCli, serverAddress string) error {
ctx := context.Background()
var isDefaultRegistry bool
if serverAddress == "" {
serverAddress = dockerCli.ElectAuthServer(ctx)
isDefaultRegistry = true
}
var (
loggedIn bool
regsToLogout []string
hostnameAddress = serverAddress
regsToTry = []string{serverAddress}
)
if !isDefaultRegistry {
hostnameAddress = registry.ConvertToHostname(serverAddress)
// the tries below are kept for backward compatibily where a user could have
// saved the registry in one of the following format.
regsToTry = append(regsToTry, hostnameAddress, "http://"+hostnameAddress, "https://"+hostnameAddress)
}
// check if we're logged in based on the records in the config file
// which means it couldn't have user/pass cause they may be in the creds store
for _, s := range regsToTry {
if _, ok := dockerCli.ConfigFile().AuthConfigs[s]; ok {
loggedIn = true
regsToLogout = append(regsToLogout, s)
}
}
if !loggedIn {
fmt.Fprintf(dockerCli.Out(), "Not logged in to %s\n", hostnameAddress)
return nil
}
fmt.Fprintf(dockerCli.Out(), "Removing login credentials for %s\n", hostnameAddress)
for _, r := range regsToLogout {
if err := client.EraseCredentials(dockerCli.ConfigFile(), r); err != nil {
fmt.Fprintf(dockerCli.Err(), "WARNING: could not erase credentials: %v\n", err)
}
}
return nil
}
示例14: NewSwarmCommand
// NewSwarmCommand returns a cobra command for `swarm` subcommands
func NewSwarmCommand(dockerCli *client.DockerCli) *cobra.Command {
cmd := &cobra.Command{
Use: "swarm",
Short: "Manage docker swarm",
Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString())
},
}
cmd.AddCommand(
newInitCommand(dockerCli),
newJoinCommand(dockerCli),
newUpdateCommand(dockerCli),
newLeaveCommand(dockerCli),
newInspectCommand(dockerCli),
)
return cmd
}
示例15: runRemove
func runRemove(dockerCli *client.DockerCli, opts *removeOptions) error {
client := dockerCli.Client()
ctx := context.Background()
status := 0
for _, name := range opts.volumes {
if err := client.VolumeRemove(ctx, name, opts.force); err != nil {
fmt.Fprintf(dockerCli.Err(), "%s\n", err)
status = 1
continue
}
fmt.Fprintf(dockerCli.Out(), "%s\n", name)
}
if status != 0 {
return cli.StatusError{StatusCode: status}
}
return nil
}