-1

I used docker-compose up -d . but my docker container exits after executing my script. This is my below docker-compose.yml file. I want to run docker container in the background.

    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

===================================

yivi
  • 42,438
  • 18
  • 116
  • 138
Sakthivel G
  • 121
  • 1
  • 8
  • 1
    Possible duplicate of [How to keep Docker container running after starting services?](https://stackoverflow.com/questions/25775266/how-to-keep-docker-container-running-after-starting-services) – David Maze Nov 16 '18 at 12:59

1 Answers1

-1

The problem is that your shell scripts probably fork themselves to create a daemon, whereas in the Docker model, you would actually not want them to daemonize themselves, because the process would exit and thereby stop the container.

Uku Loskit
  • 40,868
  • 9
  • 92
  • 93