Skip to content

Commit

Permalink
doc: tips for auto-removing old containers (#237)
Browse files Browse the repository at this point in the history
Closes #234
  • Loading branch information
nanmu42 committed Nov 17, 2020
1 parent 2444b91 commit 35a8e8a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Expand Up @@ -120,6 +120,26 @@ Sometimes container clean up fails. Check out
resource.Expire(60) // Tell docker to hard kill the container in 60 seconds
```

To let stopped containers removed from file system automatically, use `pool.RunWithOptions()` instead of `pool.Run()` with `config.AutoRemove` set to true, e.g.:

```go
postgres, err := pool.RunWithOptions(&dockertest.RunOptions{
Repository: "postgres",
Tag: "11",
Env: []string{
"POSTGRES_USER=test",
"POSTGRES_PASSWORD=test",
"listen_addresses = '*'",
},
}, func(config *docker.HostConfig) {
// set AutoRemove to true so that stopped container goes away by itself
config.AutoRemove = true
config.RestartPolicy = docker.RestartPolicy{
Name: "no",
}
})
```

## Running dockertest in Gitlab CI

### How to run dockertest on shared gitlab runners?
Expand Down

0 comments on commit 35a8e8a

Please sign in to comment.