使用docker容器时找不到文件

问题描述 投票:-1回答:1

我有一个读取配置文件的应用程序:

config.read('/data123/config/conf.ini')

conf.ini中存在文件/data123/config/

当我从命令行运行应用程序时,应用程序可以成功找到conf.ini

我为我的应用程序创建了一个泊坞窗,当我运行泊坞窗时,该应用程序找不到该文件。

我的dockerfile:

FROM ubuntu:latest
RUN apt update -y
RUN apt install -y python3-pip
COPY . /app
WORKDIR /app
RUN pip3 install -r requirements.txt
ENTRYPOINT ["python3"]
CMD ["main.py"]
  • 这是为什么?

  • 使用容器时如何从应用程序读取配置文件?

    • 我不想每次配置文件更改时都创建新的docker和
    • 我不想使用环境变量,因为我在配置文件中有很多值。
python docker
1个回答
1
投票

使用此命令运行Docker:

sudo docker run -it -v path_to_file_you_want_to_work_with:/app/data123/config/ your_docker_name

并且容器将运行并在运行时加载您提供的配置文件

© www.soinside.com 2019 - 2024. All rights reserved.