> For the complete documentation index, see [llms.txt](https://omalab.gitbook.io/engineeringwiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://omalab.gitbook.io/engineeringwiki/setup/docker.md).

# Docker

## Cleaning up

Cleanup the docker virtual disk for images that are partial stages from builds:

```
function dcleanup {
    docker rm -v $(docker ps --filter status=exited -q 2>/dev/null) 2>/dev/null
    docker rmi $(docker images --filter dangling=true -q 2>/dev/null) 2>/dev/null
}
```

## Nuke

To wipe containers and images out and start fresh. This has to happen from time to time, as Docker uses a virtual disk that has a fixed size, usually between 15Gb and 80Gb. This is shown as a function so it can be copied into your .bashrc if you want to do so.

```
function dnuke {
  docker stop $(docker ps -a -q)
  docker rm $(docker ps -a -q)
  docker rmi $(docker images -q)
  docker ps -a | sed '1 d' | awk '{print $1}' | xargs -L1 docker rm
  docker images -a | sed '1 d' | awk '{print $3}' | xargs -L1 docker rmi -f
  docker volume rm $(docker volume ls -qf dangling=true)
  echo "Nuked!"
}
```

## Remove files matching a name.

This will remove anything that text matches a term you enter on the function.

```
function dremovebyname {
    docker ps -a | awk '{ print $1,$2 }' | grep $1 | awk '{print $1 }' | xargs -I {} docker rm -f {}
}
```

## Start/Stop

Stopping docker containers running.

```
# stops all your continers
function dockerstop {
  docker rm $(docker stop $(docker ps -a -q --filter ancestor=$1 --format="{{.ID}}"))
}
```

## Docker compose

To issue commands with docker-compose, you need to be in the root folder of that drive (that contains the docker-compose.yml files). Otherwise, your results MAY vary. You cannot issue docker-compose commands from INSIDE a container.

To stop everything without deleting all the data:

```
docker-compose stop
```

To stop everything AND delete all the data (the database is the thing that matters here).

```
docker-compose down
```

## Inspecting a Stopped Container

Inspecting a stopped container's file system is a thing that needs to be done from time to time. To do this:

```
docker commit CONTAINER_ID NEWIMAGENAME
docker run -ti --entrypoint /bin/bash NEWIMAGENAME
```
