【问题标题】:Modify a line before starting the container启动容器前修改一行
【发布时间】:2020-04-18 23:44:41
【问题描述】:

我使用以下命令构建了一个 docker 镜像

docker build -t shantanuo/mydash .

dockerfile 是:

FROM continuumio/miniconda3
EXPOSE 8050
RUN cd /tmp/
RUN apt-get update
RUN apt-get install --yes git zip vim
RUN git clone https://github.com/kanishkan91/SuperTrendfor50Stocks.git
RUN pip install -r SuperTrendfor50Stocks/requirements.txt
WORKDIR SuperTrendfor50Stocks/

我可以启动容器,修改应用程序文件,然后启动应用程序。

第 1 步:

docker run -p 8050:8050 -it shantanuo/mydash bash

第 2 步:

vi application.py

修改最后一行

application.run_server(debug=True)

application.run(host='0.0.0.0')

第 3 步:

python application.py

我可以避免这 3 个步骤并将所有内容合并到我的 dockerfile 中吗?

【问题讨论】:

    标签: awk sed dockerfile


    【解决方案1】:

    我不认为这是更改代码行然后手动运行应用程序的好方法,为什么代码不是自通用的,并根据 ENV 相应地修改应用程序的行为。

    你可以试试

    # set default value accordingly
    app.run(host=os.getenv('HOST', "127.0.0.1") , debug=os.getenv('DEBUG', False))
    

    现在您可以根据 ENV 更改该行为。

    web:
      build: ./web
      environment:
        - HOST=0.0.0.0
        - DEBUG=True
    

    docker run -p 8050:8050 -e HOST="0.0.0.0" e DEBUG=True -it shantanuo/mydash
    

    你还需要在Dockerfile中设置CMD

    CMD python app.py
    

    【讨论】:

      猜你喜欢
      • 2010-11-30
      • 2020-05-23
      • 2016-08-23
      • 2021-12-29
      • 1970-01-01
      • 1970-01-01
      • 2016-09-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多