Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

347
Views
Docker Golang API crea un contenedor con archivos de la memoria

Actualmente, para obtener archivos en un contenedor usando la API de golang, primero debo crear el contenedor y luego usar la función CopyToContainer (Ejemplo a continuación).

¿Es posible crear un contenedor y especificar los archivos que debe tener en el momento de la creación, sin tener los archivos primero en el sistema de archivos?

Ejemplo 1)

 func main() { cli, err := client.NewEnvClient() if err != nil { panic(err) } resp, err := cli.ContainerCreate(context.Background(), &container.Config{ Image: "alpine", Cmd: []string{"ls", "/"}, }, nil, nil, "testContainer") if err != nil { panic(err) } fmt.Printf("Created: %v\n", resp.ID) cli.CopyToContainer(context.Background(), resp.ID, "/", getTar(),types.CopyToContainerOptions{}) } func getTar() io.Reader { ... }

EDITAR:
- Espaciado de código.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Encontré esta solución, pero no puedo hacer que el archivo aparezca en el contenedor. ¡Pruébalo y avísame si te funciona!

 var buf bytes.Buffer tw := tar.NewWriter(&buf) err = tw.WriteHeader(&tar.Header{ Name: filename, // filename Mode: 0777, // permissions Size: int64(len(content)), // filesize }) if err != nil { return nil, fmt.Errorf("docker copy: %v", err) } tw.Write([]byte(content)) tw.Close() // use &buf as argument for content in CopyToContainer cli.CopyToContainer(context.Background(), resp.ID, "/", &buf,types.CopyToContainerOptions{})
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!