[Share Experiences] distrobox+docker+ubuntu:20.04 配置宝塔面板
Tofloor
poster avatar
酷谷的谷子
deepin
2023-06-14 22:18
Author

基于 Red Hat 系的系统的镜像系统使用的应用 移植到基于 Debian Ubuntu 镜像

参考https://bbs.deepin.org/zh/post/256081


参考帖子: https://bbs.deepin.org/zh/post/256901


1.安装distrobox sudo apt install distrobox

如果源里面没有下载这个附件 进行手动安装distrobox-1.4.2.1.zip 在解压的文件夹里 右键打开终端

./install
echo 'export distrobox=$HOME/.local'    | sudo tee -a /etc/profile
echo 'export PATH=$distrobox/bin:$PATH' | sudo tee -a /etc/profile
source /etc/profile

2.安装 docker

sudo apt install docker.io
sudo usermod -aG docker $USER
sudo systemctl daemon-reload
sudo systemctl restart docker

3.配置国内 docker 镜像源

修改/etc/docker/daemon.json,增加或者修改以下配置:
sudo su
vim /etc/docker/daemon.json

{
  "registry-mirrors": [
    "https://dockerproxy.com",
    "https://hub-mirror.c.163.com",
    "https://mirror.baidubce.com",
    "https://ccr.ccs.tencentyun.com"
  ]
}

配置好以后重启docker

systemctl daemon-reload
systemctl restart docker

#------------

配置好的镜像 以及Dockerfile https://cloud.189.cn/t/y6zQ7vyieQzq (访问码:6vtb)

导入镜像 docker load -i new-ubuntu2004.tar

直接 跳到第 6 步

#------------

有道云笔记 https://note.youdao.com/s/SbCaFu4a

4.写一个 基于乌班图 ubuntu:20.04 的 Dockerfile 编译一个镜像,ubuntu:20.04的镜像对宝塔的兼容更好

把下面内存保存到 Dockerfile 文本文件里

FROM ubuntu:20.04
MAINTAINER i8520
#定义环境变量
ENV PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
RUN export PATH=$PATH
#更新镜像 安装常用网络工具 SSH等
RUN apt update  -y && apt upgrade -y
RUN apt install -y init openssh-server vim libc-ares2 sudo p7zip-full curl zip unzip wget
RUN apt install -y iproute2 net-tools iputils-ping libsasl2-dev
RUN apt install -y libxml2-dev openssl* libcurl4-openssl-dev pkg-config
RUN apt install -y autoconf g++ make openssl libssl-dev libcurl4-openssl-dev
#安装 支持中文显示 安装 simsun.ttc 字体
RUN apt install -y fontconfig xfonts-utils language-pack-zh-hans
RUN apt install -y fonts-wqy-microhei fonts-wqy-zenhei fonts-arphic-ukai fonts-arphic-uming
#支持 AppImage 应用
RUN apt install -y psmisc fuse libdatrie1 libnss3 libatk1.0-0 libatk-bridge2.0-0 libgdk-pixbuf2.0-0 libgtk-3-0
COPY MYStart /bin
RUN chmod -R 755 /bin/MYStart
RUN mkdir -p /usr/share/fonts/my_fonts
COPY simsun.ttc /usr/share/fonts/my_fonts
RUN cd /usr/share/fonts/my_fonts
RUN mkfontscale
RUN mkfontdir
RUN fc-cache -fv
RUN echo 'export LANG=zh_CN.UTF-8' >> $HOME/.bashrc
RUN echo 'export LANG=en_US.UTF-8' >> $HOME/.bashrc
RUN echo 'source /etc/profile' >> $HOME/.bashrc
RUN localedef -i en_US -f UTF-8 en_US.UTF-8
RUN /bin/bash -c "source $HOME/.bashrc"
CMD ["/bin/bash"]

5.利用 Dockerfile 制作一个新 镜像 ,cd 到保存Dockerfile文件的目录。或者在有Dockerfile的目录右键在终端打开

# --no-cache 表示不缓存
# -t ubuntubt:1.0 表示镜像名字ubuntubt版本1.0
docker build --no-cache -t ubuntubt:1.0 .

6.使用 distrobox 创建容器 使用刚才编译好的镜像 ubuntubt:1.0

MYubuntuBT 就是创建的容器名称 容器名称最好是大小写字母组合不要和应用程序名一样

distrobox create --image ubuntubt:1.0 MYubuntuBT

进入容器 这一步根据个人网络需要时间等待,会安装一些环境,也会在开始菜单生成一个打开容器的快捷方式

distrobox enter MYubuntuBT

进入容器后 ,安装宝塔面板 https://bt.cn/new/download.html

wget -O install.sh https://download.bt.cn/install/install-ubuntu_6.0.sh && sudo bash install.sh ed8484bec

安装好以后 ssh配置看这里 https://note.youdao.com/s/Xx4GHUdf

#设置容器root密码 这样就可以通过SSH连接到容器 IP 就是宿主机 IP 账号root密码就是你设置的
sudo passwd root
#启动宝塔
sudo bt 1
#修改宝塔帐号密码
sudo bt 5
sudo bt 6
#修改宝塔端口
sudo bt 8
#查看宝塔面板地址
sudo bt 14

6.通过宝塔面板把这个脚本上转到容器内的 / 根目录 MYStart.zip 这个脚本的作用是启动服务

su
cd / && unzip MYStart.zip
chmod -R 755 /MYStart
mv  /MYStart /bin
exit

7.这一步是在宿主机操作的,直接启动容器内的宝塔和相关服务。

echo 'export LANG=zh_CN.UTF-8' >> $HOME/.bashrc
echo 'export LANG=en_US.UTF-8' >> $HOME/.bashrc
echo 'source /etc/profile' >> $HOME/.bashrc
source $HOME/.bashrc
#重启电脑(宿主机)/虚拟机
reboot

这依赖于 MYStart 脚本,只需要在电脑(宿主机)开机的时候运行一次

# MYStart启动服务类的脚本,
# MYubuntuBT 就是创建的容器名称
distrobox-enter -n MYubuntuBT -- "sudo /bin/MYStart"

非服务类程序

有些程序在 MYubuntuBT 容器里 distrobox-export --app AppName

不会在宿主机创建快捷方式,或者创建了也启动不了,手动创建一个启动器文件就可以

把下面代码保存到 xxx.desktop 文件里

[Desktop Entry]
Name=名字
Name[zh_CN]=名字
Comment=说明
Terminal=false
Type=Application
Categories=Graphics;
StartupNotify=true
Actions=Configure;Capture;
Exec=bash -c "distrobox-enter -n MYubuntuBT -- /程序路径/程序名字"
Icon=图标路径

distrobox-enter -n MYubuntuBT -- "/程序路径/程序名字"

8.注意事项

如果宿主机开启的防火墙需要在防火墙放行相应的端口,有可能在容器内也需要

还有就是,在distrobox创建容的时候,【容器名字】不能和【容器内安装的程序名字一样】,不然很麻烦

Reply Favorite View the author
All Replies
阿尼樱奈奈
Moderator
2023-06-14 22:20
#1

like

Reply View the author
青稚
Moderator
2023-06-14 22:21
#2

赞了。

Reply View the author
ThinkYoung
deepin
2023-06-14 22:42
#3

like帅!

Reply View the author
晚秋(lateautumn)
Moderator
2023-06-14 22:58
#4

kissing_heart

Reply View the author
无心
deepin
2023-06-15 03:23
#5

楼主提供的的国内docker镜像源好牛,速度真快,我用的阿里的镜像加速服务半天拉不下来镜像

Reply View the author
Ruyisi
deepin
2023-06-20 06:53
#6

感谢大佬

Reply View the author