【问题标题】:How to pass a config file into docker for windows如何将配置文件传递到 docker for windows
【发布时间】:2021-12-22 14:15:34
【问题描述】:

我正在尝试运行位于此处的官方最新 redis docker 映像:

https://hub.docker.com/_/redis

我想在自定义配置文件中传递它。

为了测试,我从这里下载了示例配置文件:

https://redis.io/topics/config

我将文件存储在:

C:/Users//redis/config/redis.config

我将目录更改为 redis/config 文件夹(在 powershell 中)并执行命令:

docker run -it --rm --name redis --net redis -v ${pwd}:/config redis redis-server redis.conf

我收到以下错误:

Fatal error, can't open config file '/data/redis.conf': No such file or directory

我也试过命令:

docker run -it --rm --name redis --net redis -v ${PWD}/config:/etc/redis/ redis redis-server C:\Users\<username>\redis\config\redis.conf

这给了我类似的错误:

Fatal error, can't open config file '/data/C:\Users\<username>\redis\config\redis.conf': No such file or directory

在我看来,它正在容器\data 目录中寻找本地配置文件...

我不应该从本地机器文件结构中传递它吗?

如何从 windows 执行此命令,以便容器化机器加载本地 conf。

【问题讨论】:

    标签: windows docker redis configuration


    【解决方案1】:

    您可能希望将单个文件挂载为卷:

    我假设您的config 文件实际上是:C:/Users/redis/config/redis.config

    > cd C:/Users/redis
    > docker run -it --rm --name redis --net redis -v config/redis.config:/etc/redis/redis.conf redis redis-server /etc/redis/redis.conf
    

    您的文件C:/Users/redis/config/redis.config 被引用为config/redis.conf 的相对路径,因为当前工作目录是C:\Users\redisredis 映像是按照 redis-server 在路径上的约定构建的,并使用 .conf 文件的参数运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-16
      • 2021-06-03
      • 1970-01-01
      • 2013-07-11
      • 2017-03-22
      • 2021-08-03
      • 2017-12-25
      • 1970-01-01
      相关资源
      最近更新 更多