docker-compose up is starting the container and immediately stopping them

前端 未结 2 798
长发绾君心
长发绾君心 2021-02-20 08:27

I am trying to build services using docker-compose but containers started using docker-compose is stopping immediately as compose script is over. But when i am creating containe

相关标签:
2条回答
  • 2021-02-20 08:41

    If you use bash as the command, but without a terminal, it will exit immediately. This is because when bash starts up, if there is no terminal attached, and it has no script or other command to execute, it has nothing to do, so it exits (by design).

    You can either use a different command, or attach a terminal with tty: true as part of the definition of this service.

    services:
      composetestdb:
        tty: true
        ...
    
    0 讨论(0)
  • 2021-02-20 08:45

    I have the same problem, but tty : true doesn't resolve the problem for me.

    This is my docker-compose file :

    ---
    version: "3"
    services :
      data:
        container_name: data
        environment:
          - MYSQL_ROOT_PASSWORD=0283
        image: mysql:5.7
        restart: always
        volumes:
          - "./database:/var/lib/mysql"
        ports:
          - "3306:3306"
      mail:
        container_name: mail
        image: djfarrelly/maildev
        ports:
          - "1080:80"
          - "1025:25"
      web:
        container_name: web
        image: "web:php7.1a"
        links:
          - mail
          - data
        ports:
          - "80:80"
        volumes:
          - "./www:/var/www/html"
        working_dir : /var/www/html
        tty: true
        command:
          echo "test"
          #bash -c "php composer.phar self-update"
    

    After command, Docker return me : "the container is exited (0)" If I comment these lines, the container starts fine.

    Windows 10 Pro
    Docker version 18.09.2, build 6247962
    Docker-compose version 1.23.2, build 1110ad01
    

    Thanks,

    0 讨论(0)
提交回复
热议问题