Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 545
Justin Borromeo Avatar asked Sep 04 '26 06:09

Justin Borromeo


2 Answers

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.

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
like image 161
Mishi.Srivastava Avatar answered Sep 06 '26 20:09

Mishi.Srivastava


Add these lines in Dockerfile:

RUN echo "LC_ALL=en_US.UTF-8" >> /etc/environment
RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
RUN echo "LANG=en_US.UTF-8" > /etc/locale.conf
RUN locale-gen en_US.UTF-8

Source: https://github.com/tianon/docker-brew-debian/issues/45

like image 40
alaster Avatar answered Sep 06 '26 20:09

alaster