我有一个spring-boot应用程序与couchbase对话。我将spring应用程序构建为docker镜像。为了让应用程序运行,需要在couchbase设置中满足一些前提条件。当我首先运行我的couchbase映像然后运行我的spring-boot应用程序映像时,一切运行正常。但是,我需要将其自动化并从docker-compose文件运行,这意味着通过单个docker-compose up命令我应该能够首先运行couchbase映像,使用所有预置配置它然后开始运行spring-boot应用程序。我碰到了不少讨论话题,但遗憾的是我无法以某种方式使其工作。我尝试使用cmd和入口点,但没有成功。这是我的docker-compose文件
version: "2"
services:
expensetracker-cb:
image: chakrar27/expensetracker-cb
command: sh test_hello.sh
ports:
- 8080:8080
depends_on:
- mycouchbase
mycouchbase:
image: chakrar27/couchbase_new_10_08_2016
ports:
- 8091:8091
- 8092:8092
- 8093:8093
- 8094:8094
- 11210:11210
实际上它根本没有触发test_hello.sh。这是spring-boot expensetracker应用程序的dockerfile
FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD expensetracker-cb-0.1.0.jar app.jar
RUN sh -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
有人可以帮忙吗?
答案 0 :(得分:1)
好的......我可以通过将脚本包含在应用容器的Dockerfile中来实现它。不是最好的解决方案,因为我觉得等待代码不应该是容器本身的一部分。此外,我需要找到一种方法来等待couchbase集群启动并运行样本桶,并将其包含在脚本或couchbase容器本身中。目前虽然这种解决方法适合我。这是dockerfile内容
FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD expensetracker-cb-0.1.0.jar app.jar
RUN sh -c 'touch /app.jar'
ADD test_hello.sh .
RUN chmod +x test_hello.sh
CMD sh test_hello.sh
答案 1 :(得分:0)
是。
首先在docker-compose.yml中使用entrypoint而不是command。由于你的入口点调用java。
其次在容器中包含您的脚本:
$( "html *" ).hover(function() {
$( this ).css('box-shadow','inset 0 0 3px red');
}, function() {
$( this ).css('box-shadow','none');
}
);
});
示例test_hello.sh
version: "2"
services:
expensetracker-cb:
image: chakrar27/expensetracker-cb
entrypoint: sh /mnt/test_hello.sh
ports:
- 8080:8080
depends_on:
- mycouchbase
volumes:
- ./test_hello.sh:/mnt/test_hello.sh
mycouchbase:
image: chakrar27/couchbase_new_10_08_2016
ports:
- 8091:8091
- 8092:8092
- 8093:8093
- 8094:8094
- 11210:11210
我遇到了与Oracle相同的问题,我的最后一招是尝试执行SQL直到成功。我认为在沙发基地你可以做类似的事情。