awk - 启动容器前修改一行
问题描述
我使用以下命令构建了一个 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)
应用程序运行(主机='0.0.0.0')
第 3 步:
python application.py
我可以避免这 3 个步骤并合并我的 dockerfile 中的所有内容吗?
解决方案
我不认为这是更改代码行然后手动运行应用程序的好方法,为什么代码不是自通用的,并根据 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
您还需要CMD
在 Dockerfile中设置
CMD python app.py
推荐阅读
- java - 我应该如何更新 RecyclerView 的数据集并从视图持有者通知适配器?
- python - pymssql | 找不到 pymssql.pyx
- javascript - 如何在 php 循环中单击时折叠/展开表格
- c# - 非托管 EXE 引用时托管 DLL 的 App.Config
- python - 使用python从xml标签中提取数据
- php - 当我在 laravel 中处理 repo 时出错
- java - 泽西岛,如何以 json 格式创建对象列表的发布请求?
- qt - QPushButton 导出到 QML
- macos - Docker 容器 - 如何在运行容器之前检查目标结构?
- codeigniter - 使用 .htaccess 删除 url 中的 index.php 但失败