44 "archive/tar"
55 "bytes"
66 "context"
7+ "errors"
78 "fmt"
89 "io"
910 "net/netip"
@@ -30,7 +31,6 @@ import (
3031 "github.com/moby/moby/api/types/versions"
3132 "github.com/moby/moby/client"
3233 ocispec "github.com/opencontainers/image-spec/specs-go/v1"
33- "github.com/pkg/errors"
3434 "github.com/spf13/cobra"
3535 "github.com/spf13/pflag"
3636)
@@ -80,7 +80,7 @@ func NewCreateCommand(dockerCli command.Cli) *cobra.Command {
8080 flags .StringVar (& options .pull , "pull" , PullImageMissing , `Pull image before creating ("` + PullImageAlways + `", "|` + PullImageMissing + `", "` + PullImageNever + `")` )
8181 flags .BoolVarP (& options .quiet , "quiet" , "q" , false , "Suppress the pull output" )
8282 flags .BoolVarP (& options .useAPISocket , "use-api-socket" , "" , false , "Bind mount Docker API socket and required auth" )
83- flags .SetAnnotation ("use-api-socket" , "experimentalCLI" , nil ) // Marks flag as experimental for now.
83+ _ = flags .SetAnnotation ("use-api-socket" , "experimentalCLI" , nil ) // Mark flag as experimental for now.
8484
8585 // Add an explicit help that doesn't have a `-h` to prevent the conflict
8686 // with hostname
@@ -113,7 +113,7 @@ func runCreate(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet,
113113 }
114114 }
115115 proxyConfig := dockerCli .ConfigFile ().ParseProxyConfig (dockerCli .Client ().DaemonHost (), opts .ConvertKVStringsToMapWithNil (copts .env .GetSlice ()))
116- newEnv := []string {}
116+ newEnv := make ( []string , 0 , len ( proxyConfig ))
117117 for k , v := range proxyConfig {
118118 if v == nil {
119119 newEnv = append (newEnv , k )
@@ -151,7 +151,9 @@ func pullImage(ctx context.Context, dockerCli command.Cli, img string, options *
151151 if err != nil {
152152 return err
153153 }
154- defer responseBody .Close ()
154+ defer func () {
155+ _ = responseBody .Close ()
156+ }()
155157
156158 out := dockerCli .Err ()
157159 if options .quiet {
@@ -170,13 +172,13 @@ func (cid *cidFile) Close() error {
170172 if cid .file == nil {
171173 return nil
172174 }
173- cid .file .Close ()
175+ _ = cid .file .Close ()
174176
175177 if cid .written {
176178 return nil
177179 }
178180 if err := os .Remove (cid .path ); err != nil {
179- return errors . Wrapf ( err , "failed to remove the CID file '%s'" , cid .path )
181+ return fmt . Errorf ( "failed to remove the CID file '%s': %w " , cid .path , err )
180182 }
181183
182184 return nil
@@ -187,7 +189,7 @@ func (cid *cidFile) Write(id string) error {
187189 return nil
188190 }
189191 if _ , err := cid .file .Write ([]byte (id )); err != nil {
190- return errors . Wrap ( err , "failed to write the container ID to the file" )
192+ return fmt . Errorf ( "failed to write the container ID to the file: %w" , err )
191193 }
192194 cid .written = true
193195 return nil
@@ -198,12 +200,12 @@ func newCIDFile(cidPath string) (*cidFile, error) {
198200 return & cidFile {}, nil
199201 }
200202 if _ , err := os .Stat (cidPath ); err == nil {
201- return nil , errors .Errorf ("container ID file found, make sure the other container isn't running or delete %s" , cidPath )
203+ return nil , errors .New ("container ID file found, make sure the other container isn't running or delete " + cidPath )
202204 }
203205
204206 f , err := os .Create (cidPath )
205207 if err != nil {
206- return nil , errors . Wrap ( err , "failed to create the container ID file" )
208+ return nil , fmt . Errorf ( "failed to create the container ID file: %w" , err )
207209 }
208210
209211 return & cidFile {path : cidPath , file : f }, nil
@@ -224,7 +226,9 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
224226 if err != nil {
225227 return "" , err
226228 }
227- defer containerIDFile .Close ()
229+ defer func () {
230+ _ = containerIDFile .Close ()
231+ }()
228232
229233 ref , err := reference .ParseAnyReference (config .Image )
230234 if err != nil {
@@ -318,7 +322,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
318322 if options .platform != "" && versions .GreaterThanOrEqualTo (dockerCli .Client ().ClientVersion (), "1.41" ) {
319323 p , err := platforms .Parse (options .platform )
320324 if err != nil {
321- return "" , errors . Wrap ( invalidParameter (err ), "error parsing specified platform" )
325+ return "" , invalidParameter (fmt . Errorf ( "error parsing specified platform: %w" , err ) )
322326 }
323327 platform = & p
324328 }
@@ -431,7 +435,7 @@ func copyDockerConfigIntoContainer(ctx context.Context, dockerAPI client.APIClie
431435 // We don't need to get super fancy with the tar creation.
432436 var tarBuf bytes.Buffer
433437 tarWriter := tar .NewWriter (& tarBuf )
434- tarWriter .WriteHeader (& tar.Header {
438+ _ = tarWriter .WriteHeader (& tar.Header {
435439 Name : configPath ,
436440 Size : int64 (configBuf .Len ()),
437441 Mode : 0o600 ,
0 commit comments