Skip to content

Instantly share code, notes, and snippets.

@iegik
Last active October 25, 2021 09:02
Show Gist options
  • Save iegik/d2932ab62ff297f4535bde1f0d1cc94f to your computer and use it in GitHub Desktop.
Save iegik/d2932ab62ff297f4535bde1f0d1cc94f to your computer and use it in GitHub Desktop.
## Node.js
node () { docker run -it -u $(id -u) -v "$PWD":/usr/src/app -w /usr/src/app --rm node:4 node $@; }
npm () { docker run -it -u $(id -u) -v "$PWD":/usr/src/app -v $HOME/.npm:/.npm -w /usr/src/app --rm node:4 npm $@; }

UPDATE: Docker has security issues:

  • Kernel exploits
  • Denial-of-service attacks
  • Container breakouts
  • Poisoned images
  • Compromising secrets

https://www.oreilly.com/content/five-security-concerns-when-using-docker/

  • docker image prune -a - Remove all unused images
  • docker images --format 'table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.CreatedAt}}\t{{.Size}}' - list images with their size

Get containers IP

docker container inspect -f '{{ .NetworkSettings.IPAddress }}' CONTAINER_NAME

Get network info

brew install jq

docker network inspect -f '{{json .Containers}}' bridge | \
    jq '.. | if type=="object" and has("Name") then {(.Name): .IPv4Address} else empty end'

Howto setup windows-based docker machine

Enable Virtualisation with Hyper-V:

Enable-WindowsOptionalFeature -Online -FeatureName $(“Microsoft-Hyper-V”, “Containers”) -All
bcdedit /set hypervisorlaunchtype Auto

Enable Virtualisation with WSL:

Enable-WindowsOptionalFeature -Online -FeatureName $("VirtualMachinePlatform", "Microsoft-Windows-Subsystem-Linux")

Switch to WSLv2:

wsl set-default-verion 2

Disable Docker with WSL:

wsl --unregister docker-desktop-data

Disable Firewall:

Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False

Enable Virtualisation for Docker Desktop VM:

Set-VMProcessor DockerDesktopVM -ExposeVirtualizationExtensions $true
Invoke-WebRequest https://raw.githubusercontent.com/Microsoft/Virtualization-Documentation/master/hyperv-tools/Nested/Enable-NestedVm.ps1 -OutFile ~/Enable-NestedVm.ps1
~/Enable-NestedVm.ps1 -VmName "DockerDesktopVM"

Enable Hyper-V

bcdedit /set hypervisorlaunchtype Auto

Restart Hyper-V

net stop vmms
net start vmms

Update context

docker context update 10-box --docker "host=tcp://192.168.5.38:2376,ca=$HOME/.docker/machine/machines/10-box/ca.pem,cert=$HOME/.docker/machine/machines/10-box/cert.pem,key=$HOME/.docker/machine/machines/10-box/key.pem"

https://github.com/StefanScherer/windows-docker-machine

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