Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker compose detached mode not working

Q. How to run docker-compose in detach mode

I am trying to run docker-compose in detach mode but it will exits after just it's run, but I am able run same image in detach mode using 'docker run' command.

  • Run image using 'docker run' command (works in detach mode)

    docker run -itd ubuntu:16.04
    

    below is output of 'docker ps -a' command

    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
    d84edc987359        ubuntu:16.04        "/bin/bash"         4 seconds ago       Up 3 seconds                                   romantic_albattani
    
  • Run same image using 'docker-compose up -d' command (didn't work in detach mode)

    below is my docker-compose.yml file

    version: '3'
    services:
    ubuntu:
        image: ubuntu:16.04
    

    'docker-compose ps' command output

             Name              Command    State    Ports 
    ----------------------------------------------------
    composetesting_ubuntu_1   /bin/bash   Exit 0 
    

Update: When using tty: true parameter in docker-compose.yml file as below

version: '3'
services:
ubuntu:
    image: ubuntu:16.04
    tty: true

then console will not execute any command, like if I type 'ls -l' command console will not responding.

like image 966
Anand Suthar Avatar asked Feb 06 '23 02:02

Anand Suthar


1 Answers

I just had to add tty: true to my docker-compose.yml

    version: '2'
    services: 
      ubuntu:
        image: ubuntu:16.04
        tty: true 

Docker version 1.12.5, build 7392c3b

docker-compose version 1.7.1, build 0a9ab35

like image 115
fewtile42 Avatar answered Feb 13 '23 04:02

fewtile42