Last active
April 8, 2024 20:40
-
-
Save ph4un00b/bb5d5ebd6156e209a4784053c122ed92 to your computer and use it in GitHub Desktop.
terminal hacks docker / unix / windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|============================= PODMAN / DOCKER =======================| | |
@see https://unix.stackexchange.com/questions/198590/what-is-a-bind-mount | |
* ls ~ .docker/ | |
* cat $env:USERPROFILE/.docker/config.json | |
* docker search nvidia | |
* docker *image* build -t IMAGE_NAME . *--no-cache* | |
* docker container run --rm -d [-p 8080:8080 ⭕ --publish mode=ingress,published=8080,target=8080] example/hello-node:latest ✨ in the background | |
* ✅ docker ps | |
* docker container ls | |
* docker container ls --format "table {{.ID}}\t{{.Image}}\t{{.Status}}" ✨go tmpl | |
* docker container ls --quiet ✨only container ids | |
* docker container stop 267c90d5fd07 | |
* docker container run --rm -d -p 4567:8080 -e WHO="Sean and Karl" example/hello-node:latest | |
* docker context list | |
* docker image inspect example/hello-node:latest | |
* docker build --build-arg email=jamon@jamon.com -t example/hello-node:latest . | |
* docker container export 9c775ea709c2 -o web-app.tar ✨ examinar archivos | |
* tar -tvf web-app.tar | |
* docker container run --rm -it --privileged --pid=host debian nsenter -t 1 -m -u -n -i sh ✨debug shelless | |
* docker image inspect spkane/scratch-helloworld:latest ✨ look for "GraphDriver" | |
* docker container create --name awesome ubuntu:latest sleep 120 | |
* docker container start awesome | |
* docker container stop awesome | |
* docker container create --name with-labels -l deployer=your-mom -l tester=me ubuntu:latest sleep 1000 ✨ labels | |
* docker container ls -a -f label=deployer=your-mom | |
* ✅ docker ps --all --filter label=deployer=your-mom | |
* docker container inspect with-labels | |
# 👀 configurations | |
* docker container run -it --rm ubuntu:latest /bin/bash ✨create then start | |
* docker container run -it --rm --hostname jamon ubuntu:latest /bin/bash ✨ with hostname | |
* docker container run -it --rm --dns=8.8.8.8 --dns=8.8.4.4 --dns-search=example1.com ubuntu:latest /bin/bash | |
* docker container run -it --rm --mac-address="a2:11:aa:22:bb:33" ubuntu:latest /bin/bash | |
# 👀 volumes: Neither the host mount point nor the mount point in the container needs to preexist for this command to work properly. | |
* docker container run -it --rm --mount type=bind,source=/e/projects/helloworld,target=/data ubuntu:latest /bin/bash ✨ read/write by default | |
* mount | grep /data 🐋💦 ...(rw,noatime,dirsync,aname=drvfs;... | |
*✅ docker container run -it --rm --read-only=true -v /e/projects/helloworld:/data ubuntu:latest /bin/bash | |
* docker container run -it --rm -v /e/projects/helloworld:/data:ro ubuntu:latest /bin/bash ✨ readonly | |
* mount | grep /data 🐋💦 ...(ro,noatime,dirsync,aname=drvfs... | |
* docker container run -ti --rm --read-only=true --mount type=tmpfs,destination=/tmp,tmpfs-size=256M ubuntu:latest /bin/bash | |
* df -h /tmp | |
@see https://docs.docker.com/engine/install/linux-postinstall/#your-kernel-does-not-support-cgroup-swap-limit-capabilities | |
--- CPUS | |
* docker container run --rm -ti spkane/train-os stress -v --cpu 2 --io 1 --vm 2 --vm-bytes 128M --timeout 120s | |
* docker run -it --rm --pid=host alpine sh -c 'apk update && apk add htop && htop && exit' | |
* docker run -it --rm --cpu-shares 512 --pid=host alpine sh -c 'apk update && apk add htop && htop && exit' ✨ look for --cpu-period and --cpu-quota | |
* docker container run -ti --rm --cpu-shares 512 --cpuset-cpus=0 spkane/train-os stress -v --cpu 2 --io 1 --vm 2 --vm-bytes 128M --timeout 120s ✨pinned to the first of two CPUs | |
* docker container run --rm -ti --cpus=".25" spkane/train-os stress -v --cpu 2 --io 1 --vm 2 --vm-bytes 128M --timeout 60s ✨ cpu-quota | |
* docker container update --cpus="1.5" 0a33825e4237 asd324 ✨updating two containers | |
--- MEMORY | |
* docker container run -ti --rm --memory 512m --memory-swap=768m spkane/train-os stress -v --cpu 2 --io 1 --vm 2 --vm-bytes 128M --timeout 10s | |
* docker system events | |
* docker container run -it --rm --memory 100m spkane/train-os stress -v --cpu 2 --io 1 --vm 2 --vm-bytes 128M --timeout 10s ✨ out of memo error | |
--- LIMITS | |
* sudo dockerd --default-ulimit nofile=50:150 | |
* docker container run --rm -d --ulimit nofile=150:300 nginx | |
--- CONTAINERS | |
* docker container run -it --restart=on-failure:3 --memory 100m spkane/train-os stress -v --cpu 2 --io 1 --vm 2 --vm-bytes 128M --timeout 10s ✨ 3 retries | |
* docker container kill 234567 * ✨killing❗ | |
* docker container kill --signal=USR1 1232436 ✨signals❗ | |
* docker container pause 12345 ✨in Windows, you must be using Hyper-V or WSL2❗ | |
* docker container unpause 23456 | |
* docker container rm 1234 [--force] | |
--- PRUNING | |
* docker system prune | |
* docker system prune -a ✨with all unused images | |
* docker container rm $(docker container ls -a -q) ✨all containers | |
* docker image rm $(docker images -q) ✨all images | |
* docker container rm $(docker container ls -a -q --filter 'exited!=0') ✨non-zero exit❗ | |
* docker images -q -f "dangling=true" | ForEach-Object { docker rmi $_ } ✨untagged images | |
---- PROXYING COMMANDS | |
* docker container run --rm ubuntu:22.04 /bin/bash -c "/bin/cat /etc/passwd | wc -l" | |
---- VOLUMES | |
* docker volume create my-data | |
* docker container run --rm --mount source=my-data,target=/app ubuntu:latest touch /app/my-persistent-data | |
* docker container run --rm --mount source=my-data,target=/app fedora:latest ls -lFa /app/my-persistent-data | |
* docker volume rm my-data | |
---- LOGING | |
* docker container run --rm -d --name nginx-test --rm nginx:latest | |
* docker container logs nginx-test | |
* docker container logs -f nginx-test ✅ | |
* docker container stop nginx-test | |
---- MONITOR | |
* docker container run --rm -d --name stress docker.io/spkane/train-os:latest stress -v --cpu 2 --io 1 --vm 2 --vm-bytes 128M --timeout 60s | |
* docker container stats stress | |
* docker container stats stress --no-stream # just a shot | |
* docker system events # overall events | |
---- DEBUGGING | |
* docker container run --rm -d --name nginx-debug --rm nginx:latest | |
* docker container top nginx-debug # internal | |
* docker container stop nginx-debug | |
* docker image history nginx:latest # why the size of the final image | |
---- NETWORKING | |
* docker network ls | |
* docker network inspect bridge | |
---- COMPOSE | |
* docker compose top ✅ overview | |
* docker compose exec SERVICE_NAME bash ✅ | |
* docker compose stop ✅ | |
* docker compose start | |
* docker compose pause | |
* docker compose unpause | |
* docker compose -f docker-compose-defaults.yaml up -d | |
* $env:HUBOT_ROCKETCHAT_PASSWORD = "jamon"; docker compose -f docker-compose-defaults.yaml config | grep ROCKETCHAT_PASSWORD | |
@see https://docs.nvidia.com/deeplearning/frameworks/user-guide/index.html | |
- scoop info podman | |
- podman machine init | |
- podman machine start | |
- podman pull | |
- podman system connection list | |
- podman pull ghcr.io/rwxrob/ws-skilstak | |
- podman images | |
- podman run -it --hostname skilstak --name boost -v shared://shared ghcr.io/rwxrob/ws-skilstak | |
- podman ps -a | |
- podman rm boost # ❗ | |
|============================= NVIDIA =======================| | |
@see https://en.wikipedia.org/wiki/List_of_Nvidia_graphics_processing_units | |
@see https://www.microway.com/hpc-tech-tips/nvidia-smi_control-your-gpus/ | |
- dmesg -w # log | |
- nvcc --version # cuda toolkit | |
- nvidia-smi -L # current gpu | |
- nvidia-smi -q # details | |
- nvidia-smi --query-gpu=index,name,uuid,serial --format=csv # query | |
- nvidia-smi dmon # device monitoring | |
- nvidia-smi pmon # process monitoring | |
- nvidia-smi -q -d CLOCK # current GPU clock speed, default clock speed, and maximum possible clock speed | |
- nvidia-smi -q -d PERFORMANCE | |
// =================== power shelle: list items by size in MB | |
Get-ChildItem | Sort-Object Length -Descending | Select-Object Name, @{Name="Size (MB)";Expression={"{0:N2}" -f ($_.Length / 1MB)}} | |
// ======== first 5: | |
Get-ChildItem | Sort-Object Length -Descending | Select-Object -First 5 Name, @{Name="Size (MB)";Expression={"{0:N2}" -f ($_.Length / 1MB)}} | |
//==================================== powershelle torrents | |
function ppt { | |
# $prettyJson = (Invoke-WebRequest -Uri 'http://127.0.0.1:3030/' -Method Get).Content | ConvertFrom-Json | ConvertTo-Json -Depth 10; Write-Output $prettyJson | |
(Invoke-WebRequest -Uri 'http://127.0.0.1:3030/' -Method Get).Content | ConvertFrom-Json | ConvertTo-Json -Depth 10; Write-Output $prettyJson | |
} | |
// ============================================ | |
/* FISH ADD PATH */ | |
For fish 3.2.0 or upper, released in March 2021, the easiest way to add rust to path permanently is like that: | |
fish_add_path $HOME/.cargo/bin | |
IN | |
vim ~/.config/fish/config.fish | |
==================================== | |
On reducing overflow stuff. (mshstk) | |
@link https://developers.redhat.com/articles/2022/06/02/use-compiler-flags-stack-protection-gcc-and-clang#stack_canary | |
===================== | |
fnm env --use-on-cd | Out-String | Invoke-Expression | |
Set-Item -Path Env:DENO_DEPLOY_TOKEN -Value "217441242rhrh193hf-38f38h3fh8" | |
Set-Item -Path Env:PNPM_HOME -Value "A:\PNPM_HOME" | |
$env:Path += ";A:\PNPM_HOME;C:\Users\fau\.deno\bin" | |
set-alias -name pn -value pnpm | |
function p { set-location z:\projects } | |
function branches { git branch -r --sort=-committerdate --format="%(HEAD)%(color:yellow)%(refname:short)|%(color:bold green)%(committerdate:relative)|%(color:blue)%(subject)|%(color:magenta)%(authorname)%(color:reset)" --color=always } | |
function pdev { pnpm run dev } | |
function gss { git status --untracked-files=all } | |
function ppt { | |
# $prettyJson = (Invoke-WebRequest -Uri 'http://127.0.0.1:3030/' -Method Get).Content | ConvertFrom-Json | ConvertTo-Json -Depth 10; Write-Output $prettyJson | |
(Invoke-WebRequest -Uri 'http://127.0.0.1:3030/' -Method Get).Content | ConvertFrom-Json | ConvertTo-Json -Depth 10; Write-Output $prettyJson | |
} | |
============= | |
>> Get-ChildItem -Path Env:\ | |
>> create window alias | |
In a Powershell window with admin rights, execute: | |
`$ notepad $profile.AllUsersAllHosts` | |
In the profile.ps1 file that opens, put: | |
`$ set-alias -name pn -value pnpm` | |
Save the file and close the window. You may need to close any open Powershell window in order for the alias to take effect. | |
========== emscripten====== | |
.emscripten file | |
LLVM_ROOT='E:/scoop_apps/apps/emscripten/current/upstream/bin' | |
NODE_JS='E:/scoop_apps/apps/nodejs/current/node.exe' | |
BINARYEN_ROOT='E:/scoop_apps/apps/binaryen/current/bin' | |
>>> then | |
cmake .. -DCMAKE_TOOLCHAIN_FILE="E:\scoop_apps\apps\emscripten\current\upstream\emscripten\cmake\Modules\Platform\Emscripten.cmake" | |
========================== | |
// search | |
// (--ignore-case) | |
make -help | grep -i the | |
// only "the" (--word-regexp) | |
make -help | grep -i -w the | |
// [list of characters], regex | |
make -help | grep -i [1-5] | |
// --after-context=NUM print NUM lines of trailing context | |
make -help | grep -i -A 3 the | |
// or before lines | |
make -help | grep -i -B 3 the | |
// or before and after | |
make -help | grep -i -C 3 the | |
// filename (--with-filename) | |
make -help | grep -i -H 3 the | |
// filename (--line-number) | |
make -help | grep -i -n 3 the | |
// occurence | |
make -help | grep -i -c 3 the | |
ps -ef | grep -Hn | |
cat somethe | grep | |
=================================== | |
// ranges | |
touch {1..3}.jamon | |
.../etc/passwd | |
gdm:x:121:129:Gnome Display Manager:/var/lib/gdm3:/bin/false | |
cut -d: -f1 < /etc/passwd | xargs // echo by default | |
// alias, puede ser cualquira | |
cut -d: -f1 < /etc/passwd | xargs -I {} echo "jamon/{}" | |
// or | |
cut -d: -f1 < /etc/passwd | xargs -I XXX echo "jamon/XXX" | |
// max args | |
cut -d: -f1 < /etc/passwd | xargs --max-args 1 bash -c 'echo $0; sleep 1' | |
// or | |
cut -d: -f1 < /etc/passwd | xargs -n 1 bash -c 'echo $0; sleep 1' | |
// processes at time | |
cut -d: -f1 < /etc/passwd | xargs -n 1 --max-procs 3 bash -c 'echo $0; sleep 1' | |
//or | |
cut -d: -f1 < /etc/passwd | xargs -n 1 -P 3 bash -c 'echo $0; sleep 1' | |
// executing, es mas rapido que -exec en find | |
find . -type f -name "*.sh" | xargs | |
============================ | |
$ commitizen init cz-conventional-changelog --save-dev --save-exact | |
## or | |
$ npx sui-mono commit | |
============================== | |
$ sudo apt update | |
$ sudo apt upgrade | |
$ sudo apt install build-essential | |
$ sudo apt install git | |
$ git config --global core.autocrlf false | |
$ git config --global core.editor "vim" | |
#### node 14 | |
$ curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - | |
$ sudo apt-get install -y nodejs | |
$ sudo apt install libgtk-3-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 | |
###################################### .bashrc ################################################## | |
######################## set DISPLAY variable to the IP automatically assigned to WSL2 | |
# export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0 | |
# | |
# sudo /etc/init.d/dbus start &> /dev/null | |
# | |
########################################################################################### | |
$ sudo visudo -f /etc/sudoers.d/dbus | |
<your_username> ALL = (root) NOPASSWD: /etc/init.d/dbus | |
~/.ssh/ | |
sudo chmod 644 id_rsa.pub | |
sudo chmod 600 id_rsa | |
sudo chmod 644 known_hosts | |
# change out to set the folder permissions | |
../ | |
sudo chmod 700 .ssh/ | |
# authenticate with GitHub | |
$ ssh -T git@github.com | |
$ sudo chown -R <user>:<group> .ssh go sdk | |
$ sudo apt install libgtk-3-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 -y | |
# If you’re using Playwright there’s a few additional dependencies tha need installing for WebKit | |
$ sudo apt install libgstreamer-plugins-bad1.0-0 libenchant1c2a gstreamer1.0-libav -y | |
================================================================================================ | |
# difftastic | |
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh | |
$ source $HOME/.cargo/env | |
$ cargo install difftastic | |
$ git config --global diff.external difft | |
$ git config --global alias.ff 'diff' | |
$ git config --global alias.lp 'log -p --ext-diff' | |
================================================= | |
# move WSL file system | |
> wsl --shutdown | |
> wsl --list --verbose | |
> mkdir z:\backuplinux | |
> wsl --export Ubuntu z:\backuplinux\ubuntu.tar | |
> wsl --unregister Ubuntu | |
> mkdir z:\wsl | |
# [import] https://docs.microsoft.com/en-us/windows/wsl/use-custom-distro | |
> wsl --import Ubuntu z:\wsl\ z:\backuplinux\ubuntu.tar | |
> wsl -l -v | |
# boot | |
> wsl -d Ubuntu | |
# set user | |
> ubuntu.exe config --default-user yourloginname | |
================================================================================== | |
# or maybe use nc on windows? | |
# netsh (windows AS ADMIN SHELL) | |
- WSL_HOST | |
> wsl --list -v | |
- IP_FROM_WSL | |
> wsl -d WSL_HOST -e sh -c "ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | cut -d/ -f1" | |
OR | |
> wsl -d Ubuntu -e sh -c "hostname --all-ip-addresses" | |
- proxy | |
> netsh interface portproxy add v4tov4 listenport="3000" connectaddress="IP_FROM_WSL" connectport="3000" | |
OR | |
> netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport="3000" connectaddress=$($(wsl hostname -I).Trim()) connectport="3000" | |
- show currently configured proxys | |
> netsh interface portproxy show v4tov4 | |
- reset proxys | |
> netsh interface portproxy reset | |
- better ipconfig: | |
> netsh interface ipv4 show config | |
> netsh interface ipv4 show address | |
- protocal analysis | |
> netsh interface ipv4 show global | |
- toggling: | |
> netsh interface set interface name="vEthernet (WSL)" admin=disabled | |
# double quotes required just in case of spaces | |
> netsh int set int name="vEthernet (WSL)" admin=enabled | |
- netstat: | |
> netsh interface ipv4 show tcpconnections | |
> netsh interface ipv4 show udpconnections | |
- set ip: | |
> netsh interface ipv4 set address name=NETWORK_NAME static IP_ADD MASK GATEWAY store=persistent | |
- set DNS: | |
> netsh interface ipv4 set dnsservers name=NETWORK_NAME source=static "8.8.8.8" primary | |
# docker - remove images | |
docker rmi $(docker images -a -q) | |
- get back to dhcp: | |
> netsh interface ipv4 set address name=NETWORK source=dhcp | |
# and | |
> netsh interface ipv4 set dnsservers name=NETWORK source=dhcp | |
# POWERSHELL - which | |
Get-Command node | Format-Table Path, Name > jamon.txt | |
# POWERSHELL - env vars: | |
- dir env: | |
# POWERSHELL - set session env var: | |
- $env:PUPPETEER_PRODUCT = 'chrome' | |
# look at PATH in a readable way | |
echo $env:Path.Split(';') | |
# affects new processes for everybody permanently, | |
[EnvironmentVariableTarget]::Machine | |
# affects new processes for the current user permanently | |
[EnvironmentVariableTarget]::User | |
# affects the current process environment only | |
[EnvironmentVariableTarget]::Process | |
# set MYUSER path to main PATH | |
# create a new session afterwards | |
[Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", "User") + ";C:\Users\MYUSER\.deno\bin", "User") | |
|============================= GIT =======================| | |
PS C:\U> git config --global user.email "1057021+ph4un00b@users.noreply.github.com" | |
PS C:\U> git config --global user.name "js" | |
e = !git config --global -e | |
c = !git config --list --show-scope | |
o = !git config --list --show-origin | |
# scope config by folder❗ | |
[includeIf "gitdir:~/acme/"] | |
path = ~/.config/git/config-acme | |
# ssh config | |
[core] | |
sshCommand = ssh -i ~/.ssh/acme_id_rsa | |
# Migrate from legacy configurations | |
* ~/.gitconfig to ~/.config/git/config | |
* git config --global core.excludesFile | |
* @see https://git-scm.com/docs/git-config#Documentation/git-config.txt-coreexcludesFile | |
* mv ~/.gitignore_global ~/.config/git/ignore | |
* git config --global --unset core.excludesFile | |
* git config --global core.attributesFile | |
* mv ~/.gitattributes ~/.config/git/attributes | |
* git config --global --unset core.attributesFile | |
– git config --system core.autocrlf false # per-system solution | |
– git config --global core.autocrlf false # per-user solution | |
– git config --local core.autocrlf false # per-project solution | |
# on windows do not let git transform files on save | |
- git config --global core.autocrlf false | |
- git config core.autocrlf # get value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment