1.拉取ubuntu镜像
docker pull ubuntu
2.进入ubuntu容器
docker run -it --name your_ubuntu_name imageID
//例:dockr run -it --name ubuntu01 6a47e077731f
3.ubuntu容器配置
首先执行非最小化,使用下面这条命令,遇y/N一直y
unminimize
3.1 查看ubuntu版本
# uname -a
#Linux 0d5b64b0eb08 5.10.104-linuxkit #1 SMP PREEMPT Thu Mar 17 17:05:54 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux
可以看到当前ubuntu是aarch64架构的,换源时选择arm64的版本,使用echo写到/etc/apt/sources.list就可以,echo "xxxx" > /etc/apt/sources.list
3.2 换源
-
清华大学源
mirrors.tuna.tsinghua.edu.cn/help/ubuntu…
-
阿里巴巴
developer.aliyun.com/mirror/
....
可以自由选择,这里选择清华大学arm64源,注意是否使用HTTPS选择否
root@0d5b64b0eb08:/var/lib/apt/lists# echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
# deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
# deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse
# # deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse"> /etc/apt/sources.list
3.3 安装一些常用工具
安装一些自己需要的就可以,遇到y/N,就Y,这里可能出现一些错误,可以继续往下看
# apt-get update
# apt-get upgrade
# apt install vim
# apt install net-tools
# apt install inetutils-ping
3.4 重新打包一下镜像
以后出可以直接使用此版本的ubuntu
docker commit container-id image-name:tag
//例:docker commit -a huoxun 0d5b64b0eb08 ubuntu:useful
//-a 作者
4. 常见问题
4.1 E: Failed to fetch mirrors.aliyun.com/ubuntu/dist… 404 Not Found [IP: 119.167.137.102 80]
1.可能是换源时版本不对,选成其他架构了,选择对应版本的就可以
2.如果不是,可以配置dns
echo "nameserver 114.114.114.114" > /etc/resolv.conf
4.2 E: Some index files failed to download. They have been ignored, or old ones used instead.
清空/var/lib/apt/lists/
路径下文件夹