Why does a container running a console app simply exits after starting

后端 未结 2 1737
伪装坚强ぢ
伪装坚强ぢ 2021-01-23 15:38

I want to run a simple dotnet core console app in a container interactively. I am not able to do that and the container simply starts and then exits immediately without fully ru

相关标签:
2条回答
  • 2021-01-23 16:11

    I found, Docker compose run is an alternative to up command.

    docker-compose run <service name from docker-compose.yml file> 
    

    Specifically, for my application, the docker compose file looks as follows.

    version: '3.4'
    
    services:
      dokconsoleapp:
        image: ${DOCKER_REGISTRY-}dokconsoleapp
        build:
          context: .
          dockerfile: DokConsoleApp/Dockerfile
    #    stdin_open: true
    #    tty: true
    

    Note the last two lines are commented out.

    Now if I run

    docker-compose run dokconsoleapp
    

    The container runs till the end of the program, interactively waiting for me to type an input after Hello-World!.

    So statements

        stdin_open: true
        tty: true
    

    are not needed when you use run with docker-compose instead of up

    0 讨论(0)
  • 2021-01-23 16:12

    By default, you don't have an interactive TTY when the container is started with docker-compose up.

    You need to add that to your service:

    stdin_open: true
    tty: true
    
    0 讨论(0)
提交回复
热议问题