Skip to content

Instantly share code, notes, and snippets.

@ssledz
Last active October 8, 2021 20:56
Show Gist options
  • Save ssledz/3aa78e458ca802c2204fb9d7679d8d31 to your computer and use it in GitHub Desktop.
Save ssledz/3aa78e458ca802c2204fb9d7679d8d31 to your computer and use it in GitHub Desktop.

Remove dangling images

docker image prune

Remove dangling volumes

docker volume prune

Remove unused images until

docker image prune -a --filter "until=2020-01-02T15:04:05" 

Forward ssh agent into a container

docker run -rm -t -i -v $(dirname $SSH_AUTH_SOCK) -e SSH_AUTH_SOCK=$SSH_AUTH_SOCK ubuntu /bin/bash
docker run --volume $SSH_AUTH_SOCK:/ssh-agent --env SSH_AUTH_SOCK=/ssh-agent ubuntu ssh-add -l
docker run -i -t -v $(readlink -f $SSH_AUTH_SOCK):/ssh-agent \
  -e SSH_AUTH_SOCK=/ssh-agent ubuntu /bin/bash

Pass ssh key during building image

# cfg/ssh/config

Host *
     StrictHostKeyChecking no
# Docerfile

USER root
WORKDIR /root
COPY cfg/ssh/config .ssh/
RUN chmod -R 700 .ssh

ARG SSH_KEY="NO Key"

RUN set -xe && \
  echo "$SSH_KEY" > .ssh/id_rsa && \
  chmod -R 700 .ssh && \
  eval $(ssh-agent) && \
  ssh-add && \
  do-something-requiring-ssh-key && \
  rm .ssh/id_rsa
docker build --build-arg SSH_KEY="$(cat ~/.ssh/id_rsa)" -t my-image:latest .

Format ps

 docker ps -a --format "{{.ID}} : {{.Labels}} : {{.Names}}"

How to access docker volume data from host machine ?

docker volume create --driver local -o o=bind -o type=none -o device=$(pwd)/node-ipc node-ipc

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment