Python 使用docker容器时找不到文件
我有一个读取配置文件的应用程序:Python 使用docker容器时找不到文件,python,docker,Python,Docker,我有一个读取配置文件的应用程序: config.read('/data123/config/conf.ini') 文件conf.ini存在于/data123/config/ 当我从命令行运行应用程序时,应用程序可以成功地找到conf.ini 我为我的应用程序制作了一个docker,当我运行docker时,应用程序找不到文件 我的dockerfile: FROM ubuntu:latest RUN apt update -y RUN apt install -y python3-pip COPY
config.read('/data123/config/conf.ini')
文件conf.ini
存在于/data123/config/
当我从命令行运行应用程序时,应用程序可以成功地找到conf.ini
我为我的应用程序制作了一个docker,当我运行docker时,应用程序找不到文件
我的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 及
- 我不想使用环境变量,因为配置文件中有很多值
sudo docker run -it -v path_to_file_you_want_to_work_with:/app/data123/config/ your_docker_name
容器将运行并加载您在运行时提供的配置文件您是否已将“conf.ini”文件复制到docker容器?如果在/data123/config/中搜索该文件,为什么需要复制它?当我需要替换一些配置时,我想更改conf.ini文件…@Boom,你能分享你的Dockerfile吗?您必须将所有项目文件和配置放入容器中,以便在其运行时访问。您可以在Dockerfile中使用
ADD
或COPY
命令将所需文件放置在图像中,例如ADD//
除非创建了/data123/config/
文件夹,否则容器中不会有该文件夹。您可以将配置放在项目根文件夹的data123/config
中,COPY/app
将data123
文件夹复制到容器中。然后可以像config.read('/app/data123/config/conf.ini')一样读取它