Skip to content

Instantly share code, notes, and snippets.

@jonashackt
Last active July 13, 2021 15:12
Show Gist options
  • Save jonashackt/17e0876e41ec32518e926845d4b743a8 to your computer and use it in GitHub Desktop.
Save jonashackt/17e0876e41ec32518e926845d4b743a8 to your computer and use it in GitHub Desktop.
Docker cheatsheet

Docker container, images, networks management is easy with the prune command which is available for all types of Docker artifacts (see https://stackoverflow.com/a/32723127/4964553 & https://docs.docker.com/config/pruning/#prune-images & https://docs.docker.com/engine/reference/commandline/system_prune/#filtering).

remove all local Docker containers, that are older than

docker container prune --filter "until=48h"

remove all local Docker images, that are older than

docker image prune -a --filter "until=2020-10-25"

run multiple commands with only one single docker run

docker run --rm -v "$PWD":/usr/src/app -w /usr/src/app ruby:2.5 bash -c "bundle install; bundle exec jekyll build -d public; ls -l"

su or sudo not working inside container, since you're another user then root

errors like

$ su root
su: must be suid to work properly

simply use --user root while doing docker exec -it: docker exec -it --user containerId bash

Install ssh and scp to Alpine Docker Container

# optinally add proxy
export HTTP_PROXY=http://proxy.your.lan:8080
export HTTPS_PROXY=http://proxy.your.lan:8080
apk update
apk add openssh

local root erlangen per Docker

docker run -it --rm
--volume $(pwd):/build
--workdir /build
use_some_image bash

Docker Hub Badge

[![Dockerhub badge](http://dockeri.co/image/aveltens/docker-testinfra)](https://hub.docker.com/r/aveltens/docker-testinfra)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment