Docker

Clean Up

Remove Unused Images

docker system prune

This removes:

  • all stopped containers
  • all networks not used by at least one container
  • all dangling images
  • all dangling build cache

Remove All Images

docker image rm -f $(docker images -a -q)

or

docker system prune --all

Start docker with SSH

On linux it should be possible to actually use SSH agent forwarding. See: https://gist.github.com/d11wtq/8699521

However, this doesn't work on MacOS. See: https://github.com/docker/for-mac/issues/410 https://github.com/docker/for-mac/issues/483

But, you can of course just share your .ssh folder and start ssh-agent in the container.

Run Docker with .ssh

This uses a bind mount, which shares the files. Should probably use a volume to copy the files.

docker run --rm -it \
       --name sshtest \
       --mount type=bind,source=/Users/chrisc/.ssh,target=/root/.ssh \
       $ImageName \
       /bin/bash

In container, start ssh-agent

eval $(ssh-agent -s)

Add your keys

ssh-add ~/.ssh/id_rsa

Run Simple Images

Images I sometimes run for debugging etc.

Python

Run and mount current dir.

PROJECT_NAME=$(basename $(pwd))

docker run --rm \
       --name $PROJECT_NAME \
       --mount type=bind,source=$(pwd),target=/$PROJECT_NAME \
       python:3.6.5-slim-stretch /bin/bash

Golang

Run golang container for interactive use

docker run -it --rm golang:1.14

Rate Limiting

curl "https://auth.docker.io/token?service=registry.docker.io&scope=repository:ratelimitpreview/test:pull" \
    | jq -r .token
curl --head \
     -H "Authorization: Bearer $TOKEN" \
     https://registry-1.docker.io/v2/ratelimitpreview/test/manifests/latest