Snippets

Custom format for docker ps
Docker tipps and tricks
git credentials from environment variables
Incremental deployments using rancher-compose
Pull images on all Rancher hosts
Ubuntu Packages for troubleshooting

Custom format for docker ps

#Docker

docker ps --format "table {{.Names}}\\t{{.Image}}\\t{{.Status}}"
cat ~/.docker/config.json
#...
"psFormat":"table {{.ID}}\\t{{.Names}}\\t{{.Image}}\\t{{.Status}}"
#...

Docker tipps and tricks

#Docker
  • Only use library images from Docker Hub
  • Build everything else yourself
  • Don’t derive from latest, use versioned tags
  • Test your images before promoting them to production
  • Use SHELL [“bash”, “-e”, “-x”, “-c”]
  • Readability over layer consolidation
  • Use a single ADD statement to integrate a directory tree
  • Build pipelines over multi-stage builds
  • Use microlabeling
  • Check downloads against checksum or signature
  • Separate deployment information from build (e.g. credentials, proxy)
  • When using the build cache, also use explicit pull
  • Create sane environment (clean up before your build)
  • Clean up after your build
  • Always do test deployments
  • Monitor your environments
  • Dependencies before code
  • Don’t run as root
  • Gosu instead of sudo
  • Use variables in docker-compose.yml

git credentials from environment variables

#SSH #git

For HTTP(S) URLs use a custom credential helper (source):

git config --global credential.helper '!f() { sleep 1; echo "username=${GIT_USER}\npassword=${GIT_PASS}"; }; f'
GIT_USER=user GIT_PASS=pass git clone https://git-rd.haufe.io/...

For SSH based repos use a custom SSH command:

GIT_SSH_COMMAND='echo "${SSH_KEY}" | ssh-add -t 20 -; ssh' git clone git@github.com:nicholasdille/test-ssh.git

Incremental deployments using rancher-compose

#Rancher #Docker

Rancher deploys incrementally when docker-compose.yml is missing an existing service

Pull images on all Rancher hosts

#Rancher #Docker

Using rancher-compose pull on a docker-compose.yml forces all hosts to pull the specified images reducing deployment times

Ubuntu Packages for troubleshooting

#Docker #Ubuntu

Base packages

  • ca-certificates
  • apt-transport-https
  • curl
  • wget
  • software-properties-common for add-apt-repository
  • net-tools for netstat
  • dnsutils for nslookup, dig
  • vim.tiny followed by

      update-alternatives --install "/usr/bin/vim" "vim" "/usr/bin/vim.tiny" 1
      update-alternatives --set "vim" "/usr/bin/vim.tiny"
    
  • iproute2