简体   繁体   English

在Docker容器中为python使用配置文件

[英]Use config file for python in docker container

I have a docker container with a python application in it. 我有一个带有python应用程序的docker容器。 The application needs the path of a config file as an command line argument: 应用程序需要配置文件的路径作为命令行参数:

$ python MyApp.py config.json

My docker file looks like this 我的docker文件看起来像这样

# Use an official Python runtime as a parent image
FROM python:3.6-slim

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
ADD . /app

# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt

# Make port 80 available to the world outside this container
EXPOSE 80

# Run app.py when the container launches
CMD ["python", "app.py"]

How can I pass the command line argument for the config file to the application inside the docker container? 如何将配置文件的命令行参数传递给docker容器内的应用程序? The directory with the config file is inside the container: 带有配置文件的目录位于容器内:

ContainerDir
    -> app.py
    -> Dockerfile
    -> Config/config.json

Thanks! 谢谢!

In the docker run command, anything after the image name will be parsed as [COMMAND] [ARGS...] . docker run命令中,映像名称之后的所有内容都将解析为[COMMAND] [ARGS...]

In your case, you can use the following docker run command to pass extra arguments to your program. 就您而言,您可以使用以下docker run命令将其他参数传递给您的程序。

docker run <image>:<tag> python app.py Config/config.json

PS Docker run reference: https://docs.docker.com/engine/reference/run/ PS Docker运行参考: https : //docs.docker.com/engine/reference/run/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM