python - dockerfile 安装 mysql 并在 ubuntu 镜像中运行脚本
问题描述
我们如何创建一个简单的 docker 文件,该文件可以运行 mysql 数据库并执行存在于某些文件夹(
如scripts-folder )中的脚本,
然后运行将在内部使用此 mysql 数据库的 python 应用程序。
目前,我有一个 Dockerfile 来创建 mysql docker 映像并在其上运行脚本,但我不想为数据库工作创建单独的 docker 映像。
# Derived from official mysql image (our base image)
FROM mysql
# Add a database
ENV MYSQL_DATABASE mydatabase
# Add the content of the sql-scripts/ directory to your image
# All scripts in docker-entrypoint-initdb.d/ are automatically
# executed during container startup
COPY ./sql-scripts/ /docker-entrypoint-initdb.d/
但是,我只需要 1 个应该在内部运行 mysql 和 python 应用程序的 ubuntu docker 映像。
解决方案
尝试添加这些行
RUN sudo apt-get update
RUN sudo apt-get install python
COPY <path/to/your/script.py>
CMD [ "python3", "script.py" ]
更多信息:
推荐阅读
- android - android 8:SELinux:无法打开/sepolicy:没有这样的文件或目录
- google-chrome-devtools - 为什么 Puppeteer elementHandler 没有选择器参数?
- node.js - 服务器使用 express js 运行,但无法在浏览器中查看 html 页面。访问 localhost:3000 时只有一个空白屏幕
- java - 在 Windows 中安排 JavaFX 应用程序
- bootstrap-4 - 引导 $().dropdown() 不起作用
- macos - 找不到 stdio.h
- memory-efficient - 创建局部变量而不是调用方法来获取数据
- arrays - 空间复杂度 - 涉及数组的各种案例函数
- c - 在 Arduino 上执行一段时间后的事情
- excel - Excel 导出格式的更改 - 我们如何收到更改通知?