本文最后更新于 2025-01-07T00:08:44+08:00
常用命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| docker run -itd -p 10022:22 -v ~/data:/root/data --name my_container ubuntu:22.04 bash
docker ps -a
docker exec -it my_container bash
docker start my_container
docker rm -f my_container
docker inspect my_container
docker network ls
docker network inspcet network_name_or_id
docker nerwork rm network_name
|
docker网段与外部冲突
如果 Docker 的默认网段与外部网络网段发生冲突,可以通过以下步骤进行更改:
编辑 Docker 配置文件:通常,Docker 的配置文件位于 /etc/docker/daemon.json
。如果该文件不存在,可以创建它。
配置自定义网段:在 daemon.json
文件中添加或修改以下内容来设置一个新的网段:
1 2 3
| { "bip": "172.30.0.1/16" }
|
这里的 172.30.0.1/16
是一个示例网段,可以根据需要选择一个不冲突的私有网段。
重启 Docker 服务:保存配置文件后,重启 Docker 服务以应用更改:
1
| sudo systemctl restart docker
|
验证更改:重启后,可以运行以下命令来验证 Docker 是否使用了新的网段:
1
| docker network inspect bridge
|
检查输出中的 Subnet
信息是否与配置一致。这样设置后,Docker 将使用你指定的网段,从而避免与外部网络冲突。如果ip r
发现还有对应的路由表,可能需要docker network rm n_name
手动删除无用的网络。
配置常用环境
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| PUB_KEYS=("pub key1" "pub key2") apt update && apt install ca-certificates -y mv /etc/apt/sources.list /etc/apt/sources.list.backup cat > /etc/apt/sources.list <<EOF deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse EOF apt update && apt upgrade -y && apt install nano git wget curl openssh-server zsh -y sed -i "s/#PubkeyAuthentication.*$/PubkeyAuthentication\ yes/g" /etc/ssh/sshd_config sed -i "s/#PasswordAuthentication.*$/PasswordAuthentication\ no/g" /etc/ssh/sshd_config sed -i "s/#AuthorizedKeysFile.*$/AuthorizedKeysFile\ .ssh\/authorized_keys/g" /etc/ssh/sshd_config if [ ! -d ~/.ssh/ ]; then mkdir ~/.ssh fi if [ ! -f ~/.ssh/authorized_keys ]; then touch ~/.ssh/authorized_keys fi chmod 600 ~/.ssh/authorized_keys for pub in "${PUB_KEYS[@]}"; do echo $pub >> ~/.ssh/authorized_keys done echo "service ssh start" >> ~/.bashrc usermod -s `which zsh` root sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting sed -i "s/^plugins=(git.*$/plugins=(git zsh-autosuggestions zsh-syntax-highlighting)/g" ~/.zshrc git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k sed -i "s/^ZSH_THEME=.*$/ZSH_THEME=powerlevel10k\/powerlevel10k/g" ~/.zshrc
|