使用 docker compose 卷保留 %USERPROFILE% 文件夹
我正在搜索如何在卷安装中保留用户配置文件文件夹,
我有文件夹 C:\Users\ABEL\source\repos ,需要为 Windows 容器保留该文件夹。用户名应该来自主机。目前尚不清楚。
下面是我的 docker-compose 文件,卷部分不正确。 任何评论都会有帮助。预先感谢
version: '3.4'
services:
directoryservice:
image: abc-directoryservice:latest
build: .
ports:
- "44309:44309"
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:44309;
- ASPNETCORE_Kestrel__Certificates__Default__Password=welcome123#
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
volumes:
- ./devops/https/abccert.pfx:/https/aspnetapp.pfx:ro
# - "$env:USERPROFILE/source:$env:USERPROFILE/source"
- ${Env:USERPROFILE}\source:${Env:USERPROFILE}\source
我收到以下错误
invalid interpolation format for services.directoryservice.volumes.[]: "${Env:USERPROFILE}\\source:${Env:USERPROFILE}\\source". You may need to escape any $ with another $.
I am searching on how to persist user profile folder in volume mounting
I have folder C:\Users\ABEL\source\repos which needs to be persisted for a windows container. The username should be from the host. It is unknown.
Below is my docker-compose file, The volume section is not correct.
Any comments will be helpful. Thanks in advance
version: '3.4'
services:
directoryservice:
image: abc-directoryservice:latest
build: .
ports:
- "44309:44309"
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:44309;
- ASPNETCORE_Kestrel__Certificates__Default__Password=welcome123#
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
volumes:
- ./devops/https/abccert.pfx:/https/aspnetapp.pfx:ro
# - "$env:USERPROFILE/source:$env:USERPROFILE/source"
- ${Env:USERPROFILE}\source:${Env:USERPROFILE}\source
I get below error
invalid interpolation format for services.directoryservice.volumes.[]: "${Env:USERPROFILE}\\source:${Env:USERPROFILE}\\source". You may need to escape any $ with another $.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$env:USERPROFILE
/${env:USERPROFILE}
语法特定于 PowerShell。从 文档 来看,
docker-compose
使用其自己的语法:$USERPROFILE
/${USERPROFILE}
您报告了一个后续问题,即存储在
中的 Windows 样式路径>$用户资料
(%USERPROFILE%
)(例如C:\Users\jdoe\source
)不会转换为Unix风格的路径(例如c/Users/jdoe /source
)这个答案建议您必须设置环境变量
COMPOSE_CONVERT_WINDOWS_PATHS
到1
,在运行docker-compose
命令之前。例如,在 PowerShell 会话中:
考虑将此语句添加到您的
$PROFILE
文件,以便它在将来的 PowerShell 会话中也生效。The
$env:USERPROFILE
/${env:USERPROFILE}
syntax is specific to PowerShell.Judging by the docs,
docker-compose
uses its own syntax:$USERPROFILE
/${USERPROFILE}
You report a follow-up problem, namely that the Windows-style path stored in
$USERPROFILE
(%USERPROFILE%
) (e.g.C:\Users\jdoe\source
) isn't converted to a Unix-style path (e.g.c/Users/jdoe/source
)This answer suggests that you must set environment variable
COMPOSE_CONVERT_WINDOWS_PATHS
to1
, before running yourdocker-compose
command.E.g., in a PowerShell session:
Consider adding this statement to your
$PROFILE
file so that it takes effect in future PowerShell sessions too.