Skip to content

Commit

Permalink
Merge pull request #481 from mdelapenya/fix-docs-create-container
Browse files Browse the repository at this point in the history
docs: fix format for create-container feature
  • Loading branch information
mdelapenya authored Jul 6, 2022
2 parents 2feda90 + 81567e6 commit 3c8722d
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions docs/features/creating_container.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,56 +91,65 @@ the function will create a new generic container. If `Reuse` is true and `Name`

The following test creates an NGINX container, adds a file into it and then reuses the container again for checking the file:
```go
package main

import (
"context"
"fmt"
"log"

"github.com/testcontainers/testcontainers-go"
)

const (
reusableContainerName = "my_test_reusable_container"
reusableContainerName = "my_test_reusable_container"
)

ctx := context.Background()

n1, err := GenericContainer(ctx, GenericContainerRequest{
ContainerRequest: ContainerRequest{
Image: "nginx:1.17.6",
ExposedPorts: []string{"80/tcp"},
WaitingFor: wait.ForListeningPort("80/tcp"),
Name: reusableContainerName,
},
Started: true,
ContainerRequest: ContainerRequest{
Image: "nginx:1.17.6",
ExposedPorts: []string{"80/tcp"},
WaitingFor: wait.ForListeningPort("80/tcp"),
Name: reusableContainerName,
},
Started: true,
})
if err != nil {
log.Fatal(err)
log.Fatal(err)
}
defer n1.Terminate(ctx)

copiedFileName := "hello_copy.sh"
err = n1.CopyFileToContainer(ctx, "./testresources/hello.sh", "/"+copiedFileName, 700)

if err != nil {
log.Fatal(err)
log.Fatal(err)
}

n2, err := GenericContainer(ctx, GenericContainerRequest{
ContainerRequest: ContainerRequest{
Image: "nginx:1.17.6",
ExposedPorts: []string{"80/tcp"},
WaitingFor: wait.ForListeningPort("80/tcp"),
Name: reusableContainerName,
ContainerRequest: ContainerRequest{
Image: "nginx:1.17.6",
ExposedPorts: []string{"80/tcp"},
WaitingFor: wait.ForListeningPort("80/tcp"),
Name: reusableContainerName,
},
Started: true,
Started: true,
Reuse: true,
})
if err != nil {
log.Fatal(err)
log.Fatal(err)
}

c, _, err := n2.Exec(ctx, []string{"bash", copiedFileName})
if err != nil {
log.Fatal(err)
log.Fatal(err)
}
fmt.Println(c)
````
```

# Parallel running
## Parallel running

`testcontainers.ParallelContainers` - defines the containers that should be run in parallel mode.

Expand Down Expand Up @@ -201,4 +210,4 @@ func main() {
defer c.Terminate(ctx)
}
}
```
```

0 comments on commit 3c8722d

Please sign in to comment.