Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker #214

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

/build/
/repo/

APP_PATH
22 changes: 22 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM ubuntu:latest
MAINTAINER Sciroccogti(Based on https://github.com/zq1997/deepin-wine)

ADD container /root/

ENV DEBIAN_FRONTEND=noninteractive
RUN apt update
RUN apt install wget locales ttf-wqy-zenhei sudo tzdata -y
RUN wget -O- https://deepin-wine.i-m.dev/setup.sh | sh
ENV LC_CTYPE=zh_CN.UTF-8 \
XMODIFIERS="@im=fcitx"
RUN \
locale-gen en_US.UTF-8 zh_CN.UTF-8 \
zh_CN.GBK && \
update-locale LANG=zh_CN.UTF-8

RUN apt install com.qq.im.deepin -y
RUN apt clean && apt autoclean

WORKDIR /root

CMD ["/bin/bash"]
85 changes: 85 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# docker

仿照 [docker-wine-linux](https://github.com/RokasUrbelis/docker-wine-linux) 进行的容器化,以期摆脱系统版本要求

目前在 Ubuntu 21.04 + X11 的测试情况:
|体验|应用|包名|情况|
|---|:--:|:---:|---|
|🟨|QQ|com.qq.im.deepin|可以运行,但初次启动没有鼠标,随后有概率在使用时闪退|
|🟥|TIM|com.qq.office.deepin|TIM 内部报错|
|🟥|微信|com.qq.weixin.deepin|微信内部报错|
|🟥|QQ 音乐|com.qq.music.deepin|可以运行,但会触发自动更新,随后闪退|
|🟨|印象笔记|com.evernote.deepin|可以运行,启动界面部分字体缺失,基本不影响使用|
|🟩|阿里旺旺|com.taobao.wangwang.deepin|可以运行,但初次启动闪退,第二次运行闪退,随后正常|

## 1 安装 Docker

[官方教程](https://docs.docker.com/engine/install/ubuntu/)

使用 [官方便捷脚本](https://docs.docker.com/engine/install/ubuntu/#install-using-the-convenience-script) 安装:
```bash
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
```

参考 [Post-installation steps for Linux](https://docs.docker.com/engine/install/linux-postinstall/) 设置用户组:
```bash
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
```

验证安装:
```bash
docker run hello-world
```

## 2 编译镜像

```bash
git clone https://github.com/zq1997/deepin-wine
cd deepin-wine/docker
./run.sh
```

需要注意的是,第一次运行 `run.sh` 并成功编译后,会自动注释掉编译镜像部分的命令。

## 3 启动程序

以启动 QQ 为例:
```bash
# <ID> 为你的容器编号,可以通过 docker ps -a 查看
source ./start.sh -i <ID> com.qq.im.deepin
```

## 4 安装程序

目前默认仅安装了 QQ,其它程序可以手动安装。

以安装 印象笔记 为例:
```bash
# 进入容器
docker exec -it <ID> bash
# 安装印象笔记
apt install com.evernote.deepin
```

## 5 清理和卸载

使用 `clear.sh` 进行清理,会删除 `APP_PATH` 和容器

使用 `uninstall.sh` 移除容器和镜像

## 6 其它问题

### 宿主机重启后如何使用

只需重启容器即可
```bash
docker start <ID>
```

但可能会出现启动程序后没有反应的情况,这是因为重启容器失去了访问 X11 服务的权限。解决方法:
```bash
xhost + # 允许任何用户访问 X11 服务
```
27 changes: 27 additions & 0 deletions docker/clear.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
# Empty the docker container.
# We recommend to clean it at least once a month, this tool can be combined with
# crontab, which means you don't need to do it manually.
# This script also will empty APP_PATH subfile, you can backup it before cleaning if you want.
function CLEAR_CONTAINER() {
for i in $(awk '/deepin-wine/{print $1}' < <(docker ps -a)); do
docker stop $i && docker rm $i
done

}
while true; do
read -p 'Are you sure clear the docker container for deepin-wine?[Y/N]'
case ${REPLY} in
'Y' | 'y')
sudo rm -rf APP_PATH/*
CLEAR_CONTAINER && echo 'clear done' && exit 0
;;
'N' | 'n')
echo 'Abort.'
exit 0
;;
*)
echo -e 'Sorry,input error,please input again\n' && continue
;;
esac
done
Empty file added docker/container/.gitkeep
Empty file.
33 changes: 33 additions & 0 deletions docker/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
xhost + &>/dev/null
set -e
## build docker image
if docker build -t deepin-wine ./; then
sed -i '5,10s/^/#&/g' $0
else
printf "build docker image error,exit process\n"
exit 127
fi
## create docker container
function CREATE() {
mkdir -p $(pwd)/APP_PATH
if docker run -d -ti -v $(pwd)/APP_PATH:/root -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY -e GDK_SCALE -e GDK_DPI_SCALE \
--name deepin-wine-$RANDOM deepin-wine /bin/bash | awk '{print substr($0,1,3)}' | tee docker.id &>/dev/null; then
dockerid=$(cat docker.id)
return 0
else
printf "create container error,exit process\n"
return 127
fi
}
CREATE
code=$?
if [ "$code" == "0" ]; then
awk 'BEGIN{printf "Your container id is ";system("cat docker.id && echo");system("echo -n [\033[32m\033[5m+\033[0m]");\
printf "Run [source start.sh -i '" $dockerid "'";printf "com.qq.im.deepin] to run QQ or another APP\n"}'
echo
echo "Exec 'bash start.sh --help' for more information."
shred -f -u -v -z docker.id >/dev/null 2>&1
else
exit 127
fi
43 changes: 43 additions & 0 deletions docker/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
function RUN_APP() {
docker exec -ti $1 /usr/bin/nohup /bin/bash /opt/apps/$2/files/run.sh &>/dev/null &
}
function USAGE() {

echo 'Usage:'
echo ' -i [Docker Container ID or Name] [APP Name]'
echo ' <APP Name> list:'
echo ' com.qq.im.deepin'
echo ' com.evernote.deepin'
echo 'Example: source start.sh -i 0af com.qq.im.deepin'
}
APP_LIST=(
com.qq.im.deepin
com.qq.office.deepin
com.qq.music.deepin
com.qq.weixin.deepin
com.evernote.deepin
com.taobao.wangwang.deepin
)
if [ $# != 3 ]; then
USAGE
else
case ${1} in
-i)
shift ##ID
if { docker ps -a |& grep $1; } &>/dev/null; then
ID=$1
shift ##APP
{ for i in ${APP_LIST[@]}; do echo $i; done |& grep -i "^${1}$"; } 2>/dev/null 1>APP && RUN_APP ${ID} $(cat APP) ||
echo "Sorry,'$1' not in list"
else
echo "ERROR: Docker Container ID \"$1\" doesn't exist."
return 2
fi
;;
*)
USAGE
;;
esac
fi
[ -f APP ] && shred -f -u -z APP >/dev/null 2>&1
29 changes: 29 additions & 0 deletions docker/uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
function UNINSTALL() {
for i in $(awk '/deepin-wine/{print $1}' < <(docker ps -a)); do
docker stop $i && docker rm $i
done
###stop docker container
for i in $(docker images > >(awk '$1~/deepin-wine/{print $3}')); do
docker rmi $i
done
###remove docker image
echo "Unstall done"
}

while :; do
read -p "Are you sure uninstall the project?[Y/N]:"
case ${REPLY} in
'Y' | 'y')
UNINSTALL && exit 0
;;
'N' | 'n')
echo 'Abort.'
exit 0
;;
*)
echo 'Input error,please input again!'
continue
;;
esac
done