Git & Docker Operations
Git
Git-related operations
Switch Branch
# Check branches
git branch
# Switch to main branch
git checkout main# Check branches
git branch
# Switch to main branch
git checkout mainAdd SSH Key to Machine
git config --global user.name 'dooy'
git config --global user.email 'dooy520@qq.com'
ssh-keygen -t rsa -C 'dooy520@qq.com'
cat ~/.ssh/id_rsa.pub # Get public keygit config --global user.name 'dooy'
git config --global user.email 'dooy520@qq.com'
ssh-keygen -t rsa -C 'dooy520@qq.com'
cat ~/.ssh/id_rsa.pub # Get public keyAfter getting the public key, add it to GitHub at https://github.com/settings/keys
# Test after adding
ssh -T git@github.com# Test after adding
ssh -T git@github.comToken Access
https://github.com/settings/tokens?type=beta
Git SSH Acceleration
vim ~/.ssh/config
Host github.com
HostName 154.91.179.100
User git
Port 6088Host github.com
HostName 154.91.179.100
User git
Port 6088Merge Fork
git remote add upstream https://github.com/Test-2022/git-learn.git # original repo URL
git remote -v
# --- do the above only once ---
git fetch upstream
git checkout main
git merge upstream/maingit remote add upstream https://github.com/Test-2022/git-learn.git # original repo URL
git remote -v
# --- do the above only once ---
git fetch upstream
git checkout main
git merge upstream/mainGit Rollback
# View history to find the version you want to roll back to
git log
# Roll back to the target version
git reset --hard <commit-hash>
# Push to remote
git push origin main --force# View history to find the version you want to roll back to
git log
# Roll back to the target version
git reset --hard <commit-hash>
# Push to remote
git push origin main --forceMerge PR
https://zhuanlan.zhihu.com/p/456872464?utm_id=0
Docker
docker commit php php56fpm:me
docker commit --change='ENTRYPOINT cd /nserver && npm run sk.server ' node18 nServer:1docker commit php php56fpm:me
docker commit --change='ENTRYPOINT cd /nserver && npm run sk.server ' node18 nServer:1Install Docker
- China mirror reference: https://blog.csdn.net/m0_56022510/article/details/142707085
#!/bin/bash
# Step 1: Update apt package index
sudo apt-get update
# Step 2: Install required packages
sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
# Step 3: Add Docker's official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# Step 4: Set up Docker stable repository
echo "deb [signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Step 5: Update apt package index
sudo apt-get update
# Step 6: Install Docker
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
# Step 7: Verify Docker installation
docker --version
# Step 8: Add user to docker group (optional)
sudo usermod -aG docker $USER
echo "Please log out and log back in to apply the changes for Docker to run without sudo."#!/bin/bash
# Step 1: Update apt package index
sudo apt-get update
# Step 2: Install required packages
sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
# Step 3: Add Docker's official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# Step 4: Set up Docker stable repository
echo "deb [signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Step 5: Update apt package index
sudo apt-get update
# Step 6: Install Docker
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
# Step 7: Verify Docker installation
docker --version
# Step 8: Add user to docker group (optional)
sudo usermod -aG docker $USER
echo "Please log out and log back in to apply the changes for Docker to run without sudo."Tag a Local Image
# docker tag image1:latest (local image) ydlhero/pigaiphp:tagname (new tag)
docker tag elastic:2.4 ydlhero/elastic:2.4
docker push ydlhero/pigaiphp:5.6
docker tag nserver:1 ydlhero/nserver:1
docker tag engine7095:last ydlhero/engine7095:last
docker commit penly_service penly:service01
docker tag penly:service01 ydlhero/penly:service01
docker push ydlhero/penly:service01 # docker tag image1:latest (local image) ydlhero/pigaiphp:tagname (new tag)
docker tag elastic:2.4 ydlhero/elastic:2.4
docker push ydlhero/pigaiphp:5.6
docker tag nserver:1 ydlhero/nserver:1
docker tag engine7095:last ydlhero/engine7095:last
docker commit penly_service penly:service01
docker tag penly:service01 ydlhero/penly:service01
docker push ydlhero/penly:service01Export / Import Images
docker save ydlhero/pigaiphp:5.6 -o php5.6.docker.tag
docker load -i php5.6.docker.tag
# Start pigai php container
docker run --name php -v /data/app:/data/app -p 9000:9000 -itd ydlhero/pigaiphp:5.6 docker save ydlhero/pigaiphp:5.6 -o php5.6.docker.tag
docker load -i php5.6.docker.tag
# Start pigai php container
docker run --name php -v /data/app:/data/app -p 9000:9000 -itd ydlhero/pigaiphp:5.6Inspect Mount Directories
docker inspect xstroke --format='{{json .Mounts}}'docker inspect xstroke --format='{{json .Mounts}}'Docker Cleanup
docker system prune # Clear cache, will remove containers
docker image prune # Remove unused images only
docker volume prune # Clean up volumesdocker system prune # Clear cache, will remove containers
docker image prune # Remove unused images only
docker volume prune # Clean up volumesDelete Docker Container Logs
echo "" > /var/lib/docker/containers/<container-id>/<container-id>-json.logecho "" > /var/lib/docker/containers/<container-id>/<container-id>-json.log- Note: this breaks
docker log --tail 100 <container-id> - Specify log options at startup instead:
docker run \
--log-driver json-file \
--log-opt max-size=10m \ # max 10MB per log file
--log-opt max-file=3 \ # keep at most 3 old log files
your_imagedocker run \
--log-driver json-file \
--log-opt max-size=10m \ # max 10MB per log file
--log-opt max-file=3 \ # keep at most 3 old log files
your_imageInstall sunoproxy on Port 9999
git clone https://github.com/Dooy/cockroachai.git
cd cockroachai
./docker-install.sh
cd sunoproxy
./deploy.shgit clone https://github.com/Dooy/cockroachai.git
cd cockroachai
./docker-install.sh
cd sunoproxy
./deploy.shInstall Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"MySQL
Clear bin-log
-- Clear all logs before binlog.000010
PURGE BINARY LOGS TO 'binlog.000010';
-- Clear logs by date
PURGE BINARY LOGS BEFORE '2024-09-01 00:00:00';-- Clear all logs before binlog.000010
PURGE BINARY LOGS TO 'binlog.000010';
-- Clear logs by date
PURGE BINARY LOGS BEFORE '2024-09-01 00:00:00';Truncate Table Data
TRUNCATE TABLE logsTRUNCATE TABLE logsVSCode Auto-Format on Save
To configure Prettier to auto-format on save in VSCode:
Install Prettier extension — search "Prettier - Code formatter" in the marketplace.
Enable format on save — open Settings (
Ctrl+,/Cmd+,), searcheditor.formatOnSaveand enable it.Set default formatter — search
default formatter, setEditor: Default Formattertoesbenp.prettier-vscode.Prettier config — create
.prettierrcin your project:json{ "semi": true, "singleQuote": true, "tabWidth": 2, "trailingComma": "es5" }{ "semi": true, "singleQuote": true, "tabWidth": 2, "trailingComma": "es5" }Workspace settings — create
.vscode/settings.json:json{ "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode" }{ "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode" }
Useful Tools
Intercept Network Requests (New Approach)
Inject into a webpage and override XMLHttpRequest.prototype.send and fetch — suitable for browser extensions.
const origFetch = window.fetch;
window.fetch = async (...args) => {
const [resource, config] = args;
let requestUrl;
if (typeof resource === "string") {
requestUrl = resource;
} else if (resource instanceof Request) {
requestUrl = resource.url;
}
if (config.method != "POST" || !requestUrl.includes("/overview/home/asr")) {
return origFetch(...args);
}
if (config && config.body instanceof FormData) {
const entries = {};
for (const [k, v] of config.body.entries()) {
if (v instanceof File) {
entries[k] = { name: v.name, size: v.size, type: v.type };
} else {
entries[k] = v;
}
}
config.body = JSON.stringify(entries);
config.headers["Content-Type"] = "application/json";
}
return origFetch(...args);
};const origFetch = window.fetch;
window.fetch = async (...args) => {
const [resource, config] = args;
let requestUrl;
if (typeof resource === "string") {
requestUrl = resource;
} else if (resource instanceof Request) {
requestUrl = resource.url;
}
if (config.method != "POST" || !requestUrl.includes("/overview/home/asr")) {
return origFetch(...args);
}
if (config && config.body instanceof FormData) {
const entries = {};
for (const [k, v] of config.body.entries()) {
if (v instanceof File) {
entries[k] = { name: v.name, size: v.size, type: v.type };
} else {
entries[k] = v;
}
}
config.body = JSON.stringify(entries);
config.headers["Content-Type"] = "application/json";
}
return origFetch(...args);
};Main Site Recovery Process
Most outages are caused by MQ. Restart sequence:
docker start mq php74 redis
cd /data/app/my-deploy/api
sudo docker-compose down
sudo ./ai.sh
sudo /usr/local/openresty/nginx/sbin/nginxdocker start mq php74 redis
cd /data/app/my-deploy/api
sudo docker-compose down
sudo ./ai.sh
sudo /usr/local/openresty/nginx/sbin/nginx
HIGO