Containers
Parse build arguments from a file
docker build -t foo \ $(while IFS= read -r line; do args+="--build-arg ${line} "; \above done < <(cat .arg); \echo "$args"; unset args) .
From here
Remove all ‘exited’ containers
docker rm $(docker ps --all -q -f status=exited)
Build and run container
docker build -t foo . && docker run --rm -it foo
Prune everything that shouldn’t exist
docker system prune -a -f
Remove all images except ‘latest’
docker images | grep -v "latest" | tail -n +2 | awk '{ print $3 }' | xargs --no-run-if-empty docker rmi
Improve ‘RUN’ execution in a Dockerfile
Benefit is that when a specific line fails, then the error message is much more concise as opposed to the standard method of using ampersands.
RUN set -eu; \ python3 -m venv venv; \ venv/bin/pip install -r requirements.txt; \ venv/bin/pip install -r requirements-dev.txt; \ echo 'Venv creation + requirements installation: OK';
Remove dangling images
docker rmi $(docker images -f "dangling=true" -q)