从Docker容器初始化外部数据库

时间:2019-02-26 16:06:19

标签: docker

我的 Dockerfile 如下所示:

FROM gradle:4.10.2-jdk8

ADD myproject-be/ myproject-be/
ADD myproject-be/build.gradle myproject-be/build.gradle
ADD build.gradle .
ADD settings.gradle .
ADD init/ init/

CMD gradle init_dev
ENTRYPOINT gradle bootRun -p myproject/

如您所见,我正在尝试执行以下任务:

task init_dev {
    doLast {
        exec {
            workingDir '.'
            println "influx url: $System.env.INFLUX_HOST:$System.env.INFLUX_PORT"
            commandLine 'influx', '-host', "$System.env.INFLUX_HOST", '-port', "$System.env.INFLUX_PORT", '-import', '-path=init/influxdb-init-dev.iql', '-precision=s'
        }
        exec {
            workingDir '.'
            println "mongo url: $System.env.MONGO_HOST:$System.env.MONGO_PORT"
            commandLine 'bash', 'init/mongodb-init-runner.sh', "$System.env.MONGO_HOST", "$System.env.MONGO_PORT", 'init/mongodb-init-dev'
        }
    }
}

这样,任务基本上会将数据加载到容器外部的MongoDBInfluxDB数据库中。显然,运行容器时出现以下错误:

Task :init_dev FAILED
influx url: localhost:8087
1 actionable task: 1 executed

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':init_dev'.
> A problem occurred starting process 'command 'influx''

这是因为容器尚未安装influx和mongo CLI。如何安装两个CLI?这是正确的做法吗?

0 个答案:

没有答案