Keep Encoding from Docker-Container

156 views Asked by At

I use MariaDB on Docker for Windows with the Powershell. When I want to create a mysqldump with docker exec and redirect the file from container to hostsystem, the encoding changes from UTF8 to UTF16.

This is my command to create mysqldump:

docker exec -i containername mysqldump -uusername -ppassword database > .\sql-filename.sql

And cause of this ">" the file will be encoded in UTF16.

1

There are 1 answers

0
mk-94 On BEST ANSWER

The problem is the usage of Powershell 5.1. With the installation of Windows Terminal and Powershell (7+) via the Microsoft Store it is possible to change the encoding. Important is to use the pwsh.exe and not powershell.exe. After installation the following settings must be done. So the link of Pino is great.

#if you want to revert the default-encoding you should save the actual settings
$defaultEncoding = [Console]::OutputEncoding
# Set the encoding to UTF8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
# docker exec command, also | Set-Content sql-file.sql is possible
docker exec -i containername mysqldump -uusername -ppassword database > .\sql-filename.sql
# revert default encoding
[Console]::OutputEncoding = $defaultEncoding