Skip to content

Commit

Permalink
Remove container volumes automatically (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncsibra-lab49 authored Jan 24, 2023
1 parent 9e76db1 commit 4a1b481
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
6 changes: 3 additions & 3 deletions docker/official/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (dockerClient *Client) Run(options *docker.RunOptions) error {

if status.exitCode != options.SuccessStatus {
extra := ""
if err := dockerClient.client.ContainerRemove(context.Background(), response.ID, types.ContainerRemoveOptions{}); err != nil {
if err := dockerClient.RemoveContainer(response.ID); err != nil {
extra = "\nerror removing container: " + err.Error()
}
return fmt.Errorf("container exited with unsuccessful exit code %d%s", status.exitCode, extra)
Expand All @@ -109,7 +109,7 @@ func (dockerClient *Client) Run(options *docker.RunOptions) error {
return fmt.Errorf("error in BeforeRemove function for container: %w", err)
}
}
return dockerClient.client.ContainerRemove(context.Background(), response.ID, types.ContainerRemoveOptions{})
return dockerClient.RemoveContainer(response.ID)
}

type status struct {
Expand Down Expand Up @@ -449,7 +449,7 @@ func (dockerClient *Client) CreateContainer(options *docker.CreateContainerOptio

// RemoveContainer removes a docker container.
func (dockerClient *Client) RemoveContainer(id string) error {
return dockerClient.client.ContainerRemove(context.Background(), id, types.ContainerRemoveOptions{})
return dockerClient.client.ContainerRemove(context.Background(), id, types.ContainerRemoveOptions{RemoveVolumes: true})
}

// CopyFromContainer returns a tar stream for a path within a container (like `docker cp CONTAINER -`).
Expand Down
3 changes: 2 additions & 1 deletion docs/doczrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export default {
'Project Setup',
{ name: 'Commands', menu: [
'Usage',
'Setup',
'Setup',
'Init',
'Release',
'Deploy',
'Destroy',
Expand Down
1 change: 1 addition & 0 deletions docs/src/commands/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ cdflow2 [ GLOBALARGS ] COMMAND [ ARGS ]
## Commands

* [`setup`](setup) - interactive setup for your project.
* [`init`](init) - interactive init for your project.
* [`release`](release) - build and publish a release for a later deploymment.
* [`deploy`](deploy) - apply a release to an environment using Terraform.
* [`destroy`](destroy) - destroy all resources in an environment.
Expand Down
3 changes: 3 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ navigation:
- name: Usage
url: commands/usage
icon: Info
- name: Init Command
url: commands/init
icon: Init
- name: Setup Command
url: commands/setup
icon: Edit
Expand Down
4 changes: 2 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set -e
if [ -z "$PERSIST_REGISTRY" ]; then
if docker inspect "$registry_id" 2>/dev/null >/dev/null; then
docker stop $registry_id >/dev/null
docker rm $registry_id >/dev/null
docker rm -v $registry_id >/dev/null
rm .test-registry-id
registry_id=""
fi
Expand All @@ -30,7 +30,7 @@ fi
if [ "$PERSIST_REGISTRY" == "" ]; then
function finish {
docker stop $registry_id >/dev/null
docker rm $registry_id >/dev/null
docker rm -v $registry_id >/dev/null
rm .test-registry-id
}
trap finish EXIT
Expand Down

0 comments on commit 4a1b481

Please sign in to comment.