使用 docker compose 卷保留 %USERPROFILE% 文件夹

发布于 2025-01-09 06:43:50 字数 976 浏览 1 评论 0原文

我正在搜索如何在卷安装中保留用户配置文件文件夹,

我有文件夹 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽你眉间 2025-01-16 06:43:50

$env:USERPROFILE/ ${env:USERPROFILE} 语法特定于 PowerShell。

文档 来看,docker-compose 使用其自己的语法: $USERPROFILE / ${USERPROFILE}


您报告了一个后续问题,即存储在 中的 Windows 样式路径>$用户资料 (%USERPROFILE%)(例如C:\Users\jdoe\source)不会转换为Unix风格的路径(例如c/Users/jdoe /source

这个答案建议您必须设置环境变量COMPOSE_CONVERT_WINDOWS_PATHS1运行 docker-compose 命令之前。

例如,在 PowerShell 会话中:

$env:COMPOSE_CONVERT_WINDOWS_PATHS=1

考虑将此语句添加到您的 $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 to 1, before running your docker-compose command.

E.g., in a PowerShell session:

$env:COMPOSE_CONVERT_WINDOWS_PATHS=1

Consider adding this statement to your $PROFILE file so that it takes effect in future PowerShell sessions too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文