提问人:mk-94 提问时间:10/13/2023 最后编辑:danblackmk-94 更新时间:10/16/2023 访问量:78
从 Docker-Container 保留编码
Keep Encoding from Docker-Container
问:
我在 Docker for Windows 上使用 MariaDB 和 Powershell。 当我想使用 docker exec 创建 mysqldump 并将文件从容器重定向到 hostsystem 时,编码从 UTF8 更改为 UTF16。
这是我创建mysqldump的命令:
docker exec -i containername mysqldump -uusername -ppassword database > .\sql-filename.sql
由于这个“>”,文件将以 UTF16 编码。
答:
0赞
mk-94
10/16/2023
#1
问题在于 Powershell 5.1 的使用。 通过 Microsoft Store 安装 Windows 终端和 Powershell (7+),可以更改编码。 重要的是使用 pwsh.exe 而不是 powershell.exe。 安装后,必须完成以下设置。所以皮诺的链接很棒。
#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
下一个:UTF-8 贯穿始终
评论