UTF-8 encoding not working in Docker


UTF-8 encoding not working in Docker



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?





Seems to me this has nothing to do with docker but all with your Java program.
– Henry
Jul 1 at 6:28





The program works outside of the Docker container...inside, it outputs "unmappable character for encoding ASCII" when trying to read a French character
– Justin Borromeo
Jul 1 at 6:43





@JustinBorromeo This proves that you've written your Java program so that it is sensitive to its environment in a way that you don't want it to be. The solution is not to force requirements on the environment but simply to change the program to eliminate its undesired behavior. Please edit to show your code.
– Tom Blodget
Jul 1 at 16:43






@TomBlodget the program is a JUnit test that validates that the code can convert UTF-8 strings to it's simplified ASCII string. There's no way to avoid dealing with UTF-8.
– Justin Borromeo
Jul 2 at 17:01





The problem is likely when you are using Default rather than UTF-8. There is no such thing as a UTF-8 String or an ASCII String in Java.
– Tom Blodget
Jul 2 at 17:08




1 Answer
1



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



If it worked using above command, set it using an ENV command during docker image build.


ENV



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






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

List of Kim Possible characters

Audio Livestreaming with Python & Flask

NSwag: Generate C# Client from multiple Versions of an API