亲测有效
資源文件綫上下載太慢,則先下載下來,再add進docker里
openoffice下载地址 http://www.openoffice.org/download/index.html
java 自己在oracle官网下载 https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
DockerFile
#基础镜像为centos
FROM centos:7
#java环境
ADD /lib/jdk-8u271-linux-x64.tar.gz /usr/local/
ENV JAVA_HOME /usr/local/jdk1.8.0_271
ENV JRE_HOME /usr/local/jdk1.8.0_271/jre
ENV PATH $JAVA_HOME/bin:$JRE_HOME/bin:$PATH
#引入openoffice
ADD /lib/Apache_OpenOffice_4.1.8_Linux_x86-64_install-rpm_zh-CN.tar.gz /tmp/Apache_OpenOffice_4.1.8_Linux_x86-64_install-rpm_zh-CN
RUN cd /tmp && \
#解压缩 ADD进来后已经解压了,变成了目录。此处不用解压
#tar -xvf Apache_OpenOffice*.tar.gz
#安装JDK(太慢,改从lib库里add进来了)
#yum install -y java-1.8.0-openjdk.x86_64
#安装wget
#yum -y install wget && \
#安装OpenOffice,会安装到/opt/openoffice4/目录下
yum install -y /tmp/Apache_OpenOffice_4.1.8_Linux_x86-64_install-rpm_zh-CN/zh-CN/RPMS/*.rpm && \
yum install -y /tmp/Apache_OpenOffice_4.1.8_Linux_x86-64_install-rpm_zh-CN/zh-CN/RPMS/desktop-integration/openoffice4.1.8-redhat-menus-4.1.8-9803.noarch.rpm
#删除压缩包
#rm -f /tmp/Apache_OpenOffice_4.1.6_Linux_x86-64_install-rpm_zh-CN&& \
#删除解压缩的文件
#rm -Rf zh-CN
#必要的库
RUN yum install -y libXext.x86_64 && \
yum install -y gcc && \
yum install -y gcc-c++ && \
yum install -y freetype-devel && \
yum install -y glib2-devel && \
yum install -y cairo-devel
#启动openoffice4服务报错:no suitable windowing system found, exiting问题
RUN yum groupinstall -y "X Window System"
#安装中文字体,解决中文乱码
ADD /lib/fonts /usr/share/fonts
RUN cd /usr/share/fonts/ && \
chmod -R 755 /usr/share/fonts && \
yum install -y mkfontscale && \
yum install -y fontconfig && \
mkfontscale && \
mkfontdir && \
fc-cache -fv
#清除yum缓存
RUN yum clean all
#暴露接口
EXPOSE 8100
#启动服务,占用8100端口
CMD /opt/openoffice4/program/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard &
VOLUME /tmp
## 上传自己项目jar包运行
ADD /target/oss-server-1.1.jar /tmp/app.jar
ENTRYPOINT [ "java", "-jar", "/tmp/app.jar" ]
验证openoffice是否启动成功
#進入docker容器
docker exec -it 44fc0f0582d9 /bin/bash
#或
docker exec -it 44fc0f0582d9 /bin/sh
#檢查8100端口是否有了
netstat -anp|grep 8100
# 如果netstat提示 -bash: netstat: command not found
yum install net-tools