Search code examples
unicodedocker-composecharacter-encodingenv-file

Encoding of .env-files used by docker-compose


I have a docker-compose file which references an .env file like this:

version: '2.4'

services:
    MyService:
    #...more in here
        env_file:
             - staging.env

Now in my staging.env I have occurrences of German umlauts. So I saved that file as UTF-8 without BOM. I want to make sure that docker-compose will always pick up the correct encoding, for example if the staging environment uses (say) a different Windows version than my dev machine.

Will docker-compose always pick up utf-8 by default? Then this is fine as a solution for me. Otherwise, how can I specify explicitly in the docker-compose file that the encoding of the env file is UTF-8?


Solution

  • I'm working on a fairly similar setup, which also references *.env files containing certain special characters from it's docker-compose file.

    From some fiddling around with different encodings (and having had encoding issues with compose and environment files popping up on several occasions) I've found that Docker, if with anything, will work with UTF-8.

    Furthermore, Docker will output a stacktrace with an error message if, e.g. ANSI in my case, is chosen as encoding: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfc in position 1914: invalid start byte [10196] Failed to execute script docker-compose

    So, I strongly recommend defaulting to UTF-8 as your standard encoding in anything Docker-related.

    Also, you'd might want to look into docker-compose's option --ansi never (formerly -no-ansi) to even prohibit printing ANSI characters to console for integration with other systems.

    TL;DR: Yes, Docker seems to default to UTF-8.