docker export,import后无法运行,如java命令找不到,运行后容器内编码有问题

为什么用docker export呢,~由于客户环境太恶心了,测试一次更是麻烦,所以什么都得在本地调试完成,争取每次测试+上线一次通过才行,说多了都是泪。

由于踩坑几次了,每次都忘记,且每次网上找半天也难以发现问题,今日决定记录一笔。

在进行docker export导出镜像,然后import后运行,发现要么提示无执行命令,要么找不到执行程序,这都是因为在export后都失效了,所以我们需要在当前Dockerfile里重新声明一下,然后我这还发现容器内中文乱码,所以编码也需设置一下,具体配置如下:
Dockerfile

FROM libreoffice_jre:v3
MAINTAINER baikunlong "[email protected]"

WORKDIR /opt/kkFileView-4.4.0-SNAPSHOT

# 开始重新设置下相关环境变量
ENV LC_ALL zh_CN.utf8
ENV JAVA_HOME /usr/local/jdk1.8.0_251
ENV JRE_HOME ${JAVA_HOME}/jre
ENV CLASSPATH .:${JAVA_HOME}/lib:${JRE_HOME}/lib
ENV PATH ${JAVA_HOME}/bin:$PATH
# 结束重新设置下相关环境变量

ENV KKFILEVIEW_BIN_FOLDER /opt/kkFileView-4.4.0-SNAPSHOT/bin

ADD kkFileView-4.4.0-SNAPSHOT.tar.gz /opt/
ENTRYPOINT ["java","-Dfile.encoding=UTF-8","-Dspring.config.location=/opt/kkFileView-4.4.0-SNAPSHOT/config/application.properties","-jar","/opt/kkFileView-4.4.0-SNAPSHOT/bin/kkFileView-4.4.0-SNAPSHOT.jar",">","/opt/kkFileView-4.4.0-SNAPSHOT/log/kkFileView.log","2>&1"]

想了想,其实用docker save也行,把本地测试环境改成和生产环境都一样就可以了,但是都折腾这么久了,要继续~

顺手记录
build.sh

docker build -t bkl/kkfileview:4.4.0 .

run.sh

docker rm -f kkfileview18012

#docker run -d --name kkfileview18012 -p 18012:18012 --restart=always --privileged=true -v /docker_data/kkfileview18012/log:/opt/kkFileView-4.4.0-SNAPSHOT/log -v /docker_data/kkfileview18012/config:/opt/kkFileView-4.4.0-SNAPSHOT/config -v /etc/localtime:/etc/localtime:ro -e TZ=Asia/Shanghai bkl/kkfileview:4.4.0

docker run -d --name kkfileview18012 -p 18012:18012 --restart=always --privileged=true -v /docker_data/kkfileview18012/file:/opt/kkFileView-4.4.0-SNAPSHOT/file -v /docker_data/kkfileview18012/log:/opt/kkFileView-4.4.0-SNAPSHOT/log -v /docker_data/kkfileview18012/config:/opt/kkFileView-4.4.0-SNAPSHOT/config -v /etc/localtime:/etc/localtime:ro -e TZ=Asia/Shanghai bkl/kkfileview:4.4.0

docker logs -f kkfileview18012

你可能感兴趣的:(docker,java,docker,java)