2016-12-02 83 views
1

我做了一个小的Python脚本来创建一个数据库和内部RethinkDB执行给定的码头工人,撰写容器

但现在我想启动我rethink容器内推出这个python脚本的一些表内的Python脚本与docker-compose

这是我的搬运工,compose.yml反思容器配置

# Rethink DB 
rethink: 
    image: rethinkdb:latest 
    container_name: rethink 
    ports: 
    - 58080:8080 
    - 58015:28015 
    - 59015:29015 

我试图与执行脚本发动我的容器

docker exec -it rethink python src/app/db-install.py 

之后,但我得到这个错误

rpc error: code = 2 desc = oci runtime error: exec failed: exec: "python": executable file not found in $PATH

在我的容器中找不到Python。是否有可能在docker-composedocker exec的指定容器内执行python脚本?

+0

让你的python脚本连接到你的数据库不是更有意义吗? – polku

回答

0

的rethinkdb图像基于Debian:杰西图像:

https://github.com/rethinkdb/rethinkdb-dockerfiles/blob/da98484fc73485fe7780546903d01dcbcd931673/jessie/2.3.5/Dockerfile

Debian的:杰西图像没有安装python。

所以,你需要创建自己的Dockerfile,是这样的:

FROM rethinkdb:latest 
RUN apt-get update && apt-get install -y python 

然后改变你的搬运工,撰写:

# Rethink DB 
rethink: 
    build : . 
    container_name: rethink 
    ports: 
    - 58080:8080 
    - 58015:28015 
    - 59015:29015 

build : .是路径到您的Dockerfile。

3

先找出如果你有在containerpython可执行文件:

docker exec -it rethink which python 

如果它存在,使用在上一步中which命令提供absolute path

docker exec -it rethink /absolute/path/to/python src/app/db-install.py 

如果没有,你可以将你的python script转换为bash script,这样你就可以在没有额外的executableslibraries的情况下运行它。

或者您可以创建dockerfile,使用base image,并安装python

dockerfile:

FROM rethinkdb:latest 
RUN apt-get update && apt-get install -y python 

多克尔撰写的文件:

rethink: 
    build : . 
    container_name: rethink 
    ports: 
    - 58080:8080 
    - 58015:28015 
    - 59015:29015 
相关问题