我使用docker-compose up -d。 但是我的Docker容器在执行脚本后退出。这是我下面的docker-compose.yml文件。我想在后台运行docker容器。
version: "3"
services:
master:
build: .
command: sh /opt/spark/sbin/start-master.sh
ports:
- 8080:8080
- 8081:8081
- 7077:7077
- 4040:4040
worker:
depends_on:
- master
deploy:
- replicas: 2
- endpoint_mode: dnsrr
build: .
command: sh /opt/spark/sbin/start-slave.sh spark://172.17.0.2:7077
ports:
- 9080:8080
- 9081:8081
- 9077:7077
- 9040:4040
================
$ docker container ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
975a3af7dc27 mysparkdocker_master "sh /opt/spark/sbin/…" 41 minutes ago Exited (0) 18 seconds ago mysparkdocker_master_1
e52cf60c820c mysparkdocker_worker "sh /opt/spark/sbin/…" 41 minutes ago Exited (0) 17 seconds ago mysparkdocker_worker_1
==================================
答案 0 :(得分:0)
问题是您的shell脚本可能会自行创建一个守护程序,而在Docker模型中,您实际上不希望它们自己守护进程,因为进程将退出并因此停止容器。