OnlyOffice驗(yàn)證(三)OnlyOffice編譯結(jié)果自制Docker鏡像
??之前驗(yàn)證了OnlyOffice驗(yàn)證(二)在Centos7上部署OnlyOffice編譯結(jié)果,由于現(xiàn)在普遍都是容器化部署,所以還是驗(yàn)證下Docker鏡像打包是否可行,因?yàn)樽罱K部署還是會(huì)上到K8S,所以這步必須要驗(yàn)證一下。
資源準(zhǔn)備
??提前安裝好docker
和docker-compose
,安裝docker-compose
是為了簡(jiǎn)化容器啟動(dòng)方式。菜鳥教程傳送門
??首先準(zhǔn)備好,要打包鏡像的資源。
[root@test documentserver]# pwd
/opt/documentserver
[root@test documentserver]# ll
總用量 822720
-rwxr-xr-x. 1 root root 1220 3月 2 14:10 docker-entrypoint.sh
-rw-r--r--. 1 root root 1366 3月 2 13:34 Dockerfile
drwxr-xr-x. 2 root root 37 3月 1 21:53 DocService
-rw-r--r--. 1 root root 764 3月 1 21:10 documentServer.conf
-rw-r--r--. 1 root root 842447109 2月 24 10:40 documentserver.tar.gz
drwxr-xr-x. 2 root root 37 3月 1 21:53 FileConverter
-rw-r--r--. 1 root root 167 3月 2 13:38 run.sh
??此處說明一下相關(guān)文件的功能。
-
docker-entrypoint.sh
容器啟動(dòng)的時(shí)候會(huì)調(diào)用該腳本(基礎(chǔ)鏡像ubuntu/nginx:1.18-20.04_beta) -
Dockerfile
用于構(gòu)建鏡像的配置文件 -
DocService
文檔服務(wù)文件夾,里面放的后臺(tái)啟動(dòng)腳本 -
documentServer.conf
Nginx代理配置文件 -
documentserver.tar.gz
編譯結(jié)果壓縮包,相當(dāng)于安裝程序 -
FileConverter
轉(zhuǎn)換服務(wù)文件夾,里面放的后臺(tái)啟動(dòng)腳本 -
run.sh
主啟動(dòng)腳本,文檔服務(wù)和轉(zhuǎn)換服務(wù)最終會(huì)由該腳本負(fù)責(zé)執(zhí)行啟動(dòng)
1、run.sh 啟動(dòng)文件
#!/bin/sh
# 啟動(dòng)轉(zhuǎn)換服務(wù)
cd /opt/documentserver/server/FileConverter
sh ./start.sh
# 啟動(dòng)文檔服務(wù)
cd /opt/documentserver/server/DocService
sh ./start.sh
2、轉(zhuǎn)換服務(wù)相關(guān)腳本FileConverter
[root@test documentserver]# cd FileConverter/
[root@test FileConverter]# pwd
/opt/documentserver/FileConverter
[root@test FileConverter]# ll
總用量 8
-rw-r--r--. 1 root root 233 2月 28 21:31 start.sh
-rw-r--r--. 1 root root 215 3月 1 21:53 stop.sh
啟動(dòng)腳本 start.sh
#!/bin/sh
server_path=$(dirname $(pwd))
LD_LIBRARY_PATH=$PWD/bin
export PATH=$PATH:$LD_LIBRARY_PATH
export NODE_ENV=development-linux
export NODE_CONFIG_DIR="$server_path/Common/config"
nohup ./converter > $PWD/out.log 2>&1 &
關(guān)閉腳本 stop.sh
#!/bin/sh
pid_file=pids
ps -ef | grep converter | grep -v grep | awk '{print $2}' > $PWD/pids
pid_arg=$(awk '{print $1}' $pid_file)
for pid in ${pid_arg}
do
echo "to kill pid = $pid"
kill -9 $pid
done
3、文檔服務(wù)相關(guān)腳本DocService
[root@test documentserver]# cd DocService/
[root@test DocService]# pwd
/opt/documentserver/DocService
[root@test DocService]# ll
總用量 8
-rw-r--r--. 1 root root 172 2月 28 21:32 start.sh
-rw-r--r--. 1 root root 216 3月 1 21:53 stop.sh
啟動(dòng)腳本 start.sh
#!/bin/sh
server_path=$(dirname $(pwd))
export NODE_ENV=development-linux
export NODE_CONFIG_DIR="$server_path/Common/config"
nohup ./docservice > $PWD/out.log 2>&1 &
關(guān)閉腳本 stop.sh
#!/bin/sh
pid_file=pids
ps -ef | grep docservice | grep -v grep | awk '{print $2}' > $PWD/pids
pid_arg=$(awk '{print $1}' $pid_file)
for pid in ${pid_arg}
do
echo "to kill pid = $pid"
kill -9 $pid
done
4、docker-entrypoint.sh 容器內(nèi)啟動(dòng)腳本
??此處具體得看用的什么基礎(chǔ)鏡像(此次驗(yàn)證用的是ubuntu/nginx:1.18-20.04_beta)。主要是將run.sh
執(zhí)行添加到這個(gè)腳本中,如下所示./opt/run.sh
是唯一添加的內(nèi)容,其余的都是原本的內(nèi)容。這樣轉(zhuǎn)換服務(wù)和文檔服務(wù)就都可以跟隨容器一起啟動(dòng)了。
#!/bin/sh
# vim:sw=4:ts=4:et
./opt/run.sh
set -e
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
exec 3>&1
else
exec 3>/dev/null
fi
if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
echo >&3 "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
echo >&3 "$0: Looking for shell scripts in /docker-entrypoint.d/"
find "/docker-entrypoint.d/" -follow -type f -print | sort -n | while read -r f; do
case "$f" in
*.sh)
if [ -x "$f" ]; then
echo >&3 "$0: Launching $f";
"$f"
else
# warn on shell scripts without exec bit
echo >&3 "$0: Ignoring $f, not executable";
fi
;;
*) echo >&3 "$0: Ignoring $f";;
esac
done
echo >&3 "$0: Configuration complete; ready for start up"
else
echo >&3 "$0: No files found in /docker-entrypoint.d/, skipping configuration"
fi
fi
exec "$@"
5、documentServer.conf 代理配置
??此處就是官方提供的默認(rèn)配置,只不過是把80端口改成了81。
map $http_host $this_host {
"" $host;
default $http_host;
}
map $http_x_forwarded_proto $the_scheme {
default $http_x_forwarded_proto;
"" $scheme;
}
map $http_x_forwarded_host $the_host {
default $http_x_forwarded_host;
"" $this_host;
}
map $http_upgrade $proxy_connection {
default upgrade;
"" close;
}
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
proxy_set_header X-Forwarded-Host $the_host;
proxy_set_header X-Forwarded-Proto $the_scheme;
server {
listen 0.0.0.0:81;
listen [::]:81 default_server;
server_tokens off;
rewrite ^\/OfficeWeb(\/apps\/.*)$ /web-apps$1 redirect;
location / {
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
}
}
6、Dockerfile 鏡像配置文件
??由于基礎(chǔ)鏡像的原因,該配置文件并不需要配置ENTRYPOINT
和CMD
:
FROM ubuntu/nginx:1.18-20.04_beta
MAINTAINER lyan
COPY ./documentserver.tar.gz /opt
COPY ./FileConverter /opt/FileConverter/
COPY ./DocService /opt/DocService/
COPY ./documentServer.conf /opt
COPY ./run.sh /opt
COPY ./docker-entrypoint.sh /opt
RUN cd /opt && \
chmod +x docker-entrypoint.sh && \
mv docker-entrypoint.sh / && \
chmod +x run.sh && \
mv documentServer.conf /etc/nginx/conf.d/ && \
tar -zxvf documentserver.tar.gz && \
rm documentserver.tar.gz && \
cd documentserver && \
LD_LIBRARY_PATH=${PWD}/server/FileConverter/bin server/tools/allfontsgen \
--input="${PWD}/core-fonts" \
--allfonts-web="${PWD}/sdkjs/common/AllFonts.js" \
--allfonts="${PWD}/server/FileConverter/bin/AllFonts.js" \
--images="${PWD}/sdkjs/common/Images" \
--selection="${PWD}/server/FileConverter/bin/font_selection.bin" \
--output-web='fonts' \
--use-system="true" && \
LD_LIBRARY_PATH=${PWD}/server/FileConverter/bin server/tools/allthemesgen \
--converter-dir="${PWD}/server/FileConverter/bin" \
--src="${PWD}/sdkjs/slide/themes" \
--output="${PWD}/sdkjs/common/Images" && \
cd /opt/documentserver/server/FileConverter && \
mv /opt/FileConverter/* ./ && \
chmod +x ./start.sh && \
cd /opt/documentserver/server/DocService && \
mv /opt/DocService/* ./ && \
chmod +x ./start.sh
7、documentserver.tar.gz 自行編輯結(jié)果
??可以參考OnlyOffice驗(yàn)證(一)DocumentServer編譯驗(yàn)證,自行編譯,隨后將編譯結(jié)果打成壓縮包就可以了。
構(gòu)建鏡像并運(yùn)行
??在Dockerfile
同級(jí)目錄下執(zhí)行docker build -t ds:v1 .
命令,構(gòu)建名為ds
版本為v1
的鏡像
[root@test documentserver]# ll
總用量 822720
-rwxr-xr-x. 1 root root 1220 3月 2 14:10 docker-entrypoint.sh
-rw-r--r--. 1 root root 1366 3月 2 13:34 Dockerfile
drwxr-xr-x. 2 root root 37 3月 1 21:53 DocService
-rw-r--r--. 1 root root 764 3月 1 21:10 documentServer.conf
-rw-r--r--. 1 root root 842447109 2月 24 10:40 documentserver.tar.gz
drwxr-xr-x. 2 root root 37 3月 1 21:53 FileConverter
-rw-r--r--. 1 root root 167 3月 2 13:38 run.sh
[root@test documentserver]# docker build -t ds:v1 .
??構(gòu)建成功后執(zhí)行docker images
命令后,會(huì)在結(jié)果里看到下圖框住鏡像信息:
??接下來用這個(gè)鏡像啟動(dòng)一個(gè)容器。因?yàn)槲业呐渲貌]有去覆蓋Nginx默認(rèn)的80端口,而是另起一個(gè)配置監(jiān)聽81端口,所以此處會(huì)映射兩個(gè)端口:
[root@test documentserver]# docker run --name ds -p 9001:80 -p 9002:81 -d ds:v1
??啟動(dòng)容器后可通過執(zhí)行docker ps -all
查看該容器是否在正常運(yùn)行
訪問容器Nginx驗(yàn)證是否正常啟動(dòng)
??此處宿主機(jī)的IP為192.168.95.131
,映射端口為9001
。此處訪問Nginx歡迎頁http://192.168.95.131:9001/
驗(yàn)證一下:
訪問容器DocumentServer驗(yàn)證是否正常啟動(dòng)
??此處宿主機(jī)的IP為192.168.95.131
,映射端口為9002
。此處訪問歡迎頁http://192.168.95.131:9002/welcome/
驗(yàn)證一下:
使用Docker-compose啟動(dòng)鏡像
??有kubesphere的可以忽略此處,鏡像推到私有鏡像倉庫隨便拉著玩就成了。這里先把之前啟動(dòng)的容器刪了。
[root@test documentserver]# docker ps -all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1d80dd2ea6bf ds:v1 "/docker-entrypoint.…" 17 minutes ago Up 17 minutes 0.0.0.0:9001->80/tcp, 0.0.0.0:9002->81/tcp ds
[root@test documentserver]# docker stop 1d80dd2ea6bf
1d80dd2ea6bf
[root@test documentserver]# docker rm 1d80dd2ea6bf
1d80dd2ea6bf
??直接在資源準(zhǔn)備的文件里創(chuàng)建一個(gè)名為docker-compose.yaml
的配置文件,內(nèi)容配置如下:
version: "2"
services:
ds:
image: ds:v1
container_name: ds
ports:
- "9001:80"
- "9002:81"
volumes:
- "/opt/documentserver/data/:/opt/documentserver/server/App_Data/"
restart: always
??主要就是映射端口,容器共享宿主機(jī)的目錄,服務(wù)隨docker
服務(wù)一起啟動(dòng)。
[root@test documentserver]# pwd
/opt/documentserver
[root@test documentserver]# vim docker-compose.yaml
[root@test documentserver]# ll
總用量 822724
-rw-r--r--. 1 root root 311 3月 2 22:08 docker-compose.yaml
-rwxr-xr-x. 1 root root 1220 3月 2 14:10 docker-entrypoint.sh
-rw-r--r--. 1 root root 1366 3月 2 13:34 Dockerfile
drwxr-xr-x. 2 root root 37 3月 1 21:53 DocService
-rw-r--r--. 1 root root 764 3月 1 21:10 documentServer.conf
-rw-r--r--. 1 root root 842447109 2月 24 10:40 documentserver.tar.gz
drwxr-xr-x. 2 root root 37 3月 1 21:53 FileConverter
-rw-r--r--. 1 root root 167 3月 2 13:38 run.sh
??在docker-compose.yaml
同級(jí)目錄下執(zhí)行docker-compose up -d
命令,后臺(tái)啟動(dòng)容器
[root@test documentserver]# pwd
/opt/documentserver
[root@test documentserver]# docker-compose up -d
Creating network "documentserver_default" with the default driver
Creating ds ... done
[root@test documentserver]# docker ps -all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1b79ca4c4233 ds:v1 "/docker-entrypoint.…" 12 seconds ago Up 11 seconds 0.0.0.0:9001->80/tcp, 0.0.0.0:9002->81/tcp ds
??接下來直接調(diào)用文檔轉(zhuǎn)換接口測(cè)試下文檔轉(zhuǎn)換是否可用,此處是將word文檔轉(zhuǎn)換成一個(gè)圖片:文章來源:http://www.zghlxwxcb.cn/news/detail-418993.html
{
"async": false,
"filetype": "docx",
"key": "000001",
"outputtype": "png",
"title": "demo.docx",
"url": "https://d2nlctn12v279m.cloudfront.net/assets/docs/samples/demo.docx"
}
文章來源地址http://www.zghlxwxcb.cn/news/detail-418993.html
相關(guān)總結(jié)
- 《OnlyOffice驗(yàn)證(一)DocumentServer編譯驗(yàn)證》
- 《OnlyOffice驗(yàn)證(二)在Centos7上部署OnlyOffice編譯結(jié)果》
- 《OnlyOffice驗(yàn)證(三)OnlyOffice編譯結(jié)果自制Docker鏡像》
- 《OnlyOffice驗(yàn)證(四)MoblieWeb編譯》
到了這里,關(guān)于OnlyOffice驗(yàn)證(三)OnlyOffice編譯結(jié)果自制Docker鏡像的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!