UTF-8编码在Docker中不起作用 [英] UTF-8 encoding not working in Docker
问题描述
我正在Docker容器(从Docker Compose开始)中运行Java程序,它抛出了一系列由UTF-8字符引起的错误(因为它们无法映射到ASCII字符集)。有没有一种方法可以从docker-compose文件中启用UTF-8编码?
I'm running a Java program from within a Docker container (started with Docker Compose) and it's throwing a bunch of errors caused by UTF-8 characters (as they can't be mapped to the ASCII charset). Is there a way to enable UTF-8 encoding from the docker-compose file?
推荐答案
您可以使用以下命令进行检查:设置Java参数,然后尝试运行Java程序-
You can check by using below command to set java parameters and then try to run your java program -
export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
如果使用上述命令可以工作,请使用 ENV
命令进行设置
If it worked using above command, set it using an ENV
command during docker image build.
此外,如果需要在bash_profile中进行设置,请参考以下Dockerfile部分-
Also if you need to set it in bash_profile, refer below portion of Dockerfile -
RUN echo "JAVA_HOME=/opt/jdk1.8.0_65" >> ~/.bash_profile
这篇关于UTF-8编码在Docker中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!