极空间Docker运行Ubuntu/Debian并添加自定义启动脚本
1、添加外部文件夹并装载到 /sh 路径
2、打开容器命令选项卡,Console 连接模式选择 Interacticve &TTV(-i-t )模式
3、其他默认,应用,首次运行系统
4、通过运行的容器的ssh连接至控制终端,命令选择:/bin/sh
5、创建st.sh文件
touch /sh/st.sh
5、设置脚本文件权限
chmod 777 /sh/st.sh
7、写入基本命令
echo "
#!/bin/sh
# vim:sw=4:ts=4:et
exec "$@"
" >> /sh/st.sh
或分别执行
echo " service ssh restart " >> /sh/st.sh
echo "# vim:sw=4:ts=4:et" >> /sh/st.sh
echo "exec "$@"" >> /sh/st.sh
检查写入文件内容,确认无误后继续下一步
8、停止容器,打开容器命令选项卡,编辑EntryPoint选项,选择自定义并输入内容 /sh/st.sh (执行脚本路径)
9、应用修改,容器重新启动
10、通过运行的容器的ssh连接至控制终端
11、执行初始化,替换国内源:
Ubuntu
sudo sed -i "s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
sudo sed -i "s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
Debian
sed -i "s@http://ftp.debian.org@https://repo.huaweicloud.com@g" /etc/apt/sources.list
sed -i "s@http://security.debian.org@https://repo.huaweicloud.com@g" /etc/apt/sources.list
如果遇到无法拉取 HTTPS 源的情况,请先使用 HTTP 源并安装:
sudo apt install apt-transport-https ca-certificates
Debian 12 (bookworm) 源:
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb http://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
# deb http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
# # deb-src http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
12、更新系统并安装基本软件
apt-get update &&
apt install -y sudo &&
sudo apt-get -y update && sudo apt-get -y upgrade && sudo apt-get -y dist-upgrade &&
sudo apt install -y openssh-server &&
sudo apt install -y vim
13、允许root用户远程登陆,修改/etc/ssh/sshd_config文件:
sudo vim /etc/ssh/sshd_config
修改相关内容,
Port 22
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes
14、刷新状态:
sudo service ssh restart
15、设定root用户密码
输入 sudo passwd 命令,输入一般用户密码并设定root用户密码
16、自动安装标准软件包(适用于最小安装)
unminimize
17、通过运行的容器的ssh连接至控制终端,命令选择:/bin/sh ,增加 ssh 的自动启动
echo " service ssh restart " >> /sh/st.sh
18、完成基本设定
1、添加外部文件夹并装载到 /sh 路径
2、打开容器命令选项卡,Console 连接模式选择 Interacticve &TTV(-i-t )模式
3、其他默认,应用,首次运行系统
4、通过运行的容器的ssh连接至控制终端,命令选择:/bin/sh
5、创建st.sh文件
touch /sh/st.sh
5、设置脚本文件权限
chmod 777 /sh/st.sh
7、写入基本命令
echo "
#!/bin/sh
# vim:sw=4:ts=4:et
exec "$@"
" >> /sh/st.sh
或分别执行
echo " service ssh restart " >> /sh/st.sh
echo "# vim:sw=4:ts=4:et" >> /sh/st.sh
echo "exec "$@"" >> /sh/st.sh
检查写入文件内容,确认无误后继续下一步
8、停止容器,打开容器命令选项卡,编辑EntryPoint选项,选择自定义并输入内容 /sh/st.sh (执行脚本路径)
9、应用修改,容器重新启动
10、通过运行的容器的ssh连接至控制终端
11、执行初始化,替换国内源:
Ubuntu
sudo sed -i "s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
sudo sed -i "s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
Debian
sed -i "s@http://ftp.debian.org@https://repo.huaweicloud.com@g" /etc/apt/sources.list
sed -i "s@http://security.debian.org@https://repo.huaweicloud.com@g" /etc/apt/sources.list
如果遇到无法拉取 HTTPS 源的情况,请先使用 HTTP 源并安装:
sudo apt install apt-transport-https ca-certificates
Debian 12 (bookworm) 源:
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb http://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
# deb-src http://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
# deb http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
# # deb-src http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
12、更新系统并安装基本软件
apt-get update &&
apt install -y sudo &&
sudo apt-get -y update && sudo apt-get -y upgrade && sudo apt-get -y dist-upgrade &&
sudo apt install -y openssh-server &&
sudo apt install -y vim
13、允许root用户远程登陆,修改/etc/ssh/sshd_config文件:
sudo vim /etc/ssh/sshd_config
修改相关内容,
Port 22
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes
14、刷新状态:
sudo service ssh restart
15、设定root用户密码
输入 sudo passwd 命令,输入一般用户密码并设定root用户密码
16、自动安装标准软件包(适用于最小安装)
unminimize
17、通过运行的容器的ssh连接至控制终端,命令选择:/bin/sh ,增加 ssh 的自动启动
echo " service ssh restart " >> /sh/st.sh
18、完成基本设定