docker-compose for Detached mode

I have following docker command to run container

docker run -d --name test -v /etc/hadoop/conf:/etc/hadoop/conf -v /usr/lib/python2.7/dist-packages/hdinsight_common:/usr/lib/python2.7/dist-packages/hdinsight_common -v /etc/hive/conf/:/etc/hive/conf/ -v /etc/tez/conf/:/etc/tez/conf/ -v /usr/hdp/2.4.2.0-258/sqoop/lib/:/usr/hdp/2.4.2.0-258/sqoop/lib/ -i -t hdinsight /bin/bash

This was to complicated so I was trying to create docker-compose file like this

  • can't run a pull queue handler inside a custom vm
  • Cannot start simple docker container with “docker start” command from created image
  • How To Create And Start Docker Container node, detached mode using docker-java
  • Jenkins and docker-compose
  • log tag option ignored by docker daemon
  • Vagrant: Sync folder with boot2docker box on Windows
  • version: '2'
    services:
      hdinsight:
        image: hdinsight
        container_name: ABC
        volumes:
         - /etc/hadoop/conf:/etc/hadoop/conf
         - /usr/lib/python2.7/dist-packages/hdinsight_common:/usr/lib/python2.7/dist-packages/hdinsight_common
         - /etc/hive/conf/:/etc/hive/conf/
         - /etc/tez/conf/:/etc/tez/conf/
         - /usr/hdp/2.4.2.0-258/sqoop/lib/:/usr/hdp/2.4.2.0-258/sqoop/lib/
        entrypoint:
         - bash
        labels:
         - "HDInsight client VM"
    

    But I am not sure where to pass -d, -i & -t flages from my original docker run command

    I was running docker-compose like this

    docker-compose -f docker-compose.yml run hdinsight
    

    can anyone point me to right direction here ?

    UPDATE after first answer

    I tried to run docker-compose up -d

    root@abc-docker:~/ubuntu# docker-compose up -d
    Creating ABC
    root@sbd-docker:~/ubuntu# docker ps -a
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
    ffa4c359abf7        hdinsight           "/bin/bash"         5 seconds ago       Exited (0) 5 seconds ago                       ABC
    root@sbd-docker:~/ubuntu#
    

    Dont know why its in Exited status

    Any idea ?

    Thanks

  • Dockerfile with multiple base image
  • How do I run a docker container as a privileged user with user namespaces
  • Are Bluemix service endpoints publicly accessible?
  • Docker container on windows 10 unable to access host folder. It shows empty.
  • How to fit docker in this architecture?
  • How to add Vxlan Tag to isolation different group of Docker Containers
  • 2 Solutions collect form web for “docker-compose for Detached mode”

    You should scour the Compose file docs.

    Most docker run commands have a compose equivalent, and they should all be listed there.

    The background flag -d goes after run or up.

    The tty flag -t and interactive flag -i are not required as docker-compose run does this by default. You can add tty to individual containers in the compose file with -t, but you cannot use interactive mode since you may start multiple containers at once and you can’t interact with them all.

    In regard to your situation the command you’re using should be working. If you add -d after the run command it will run in the background. But I recommend using up instead of run, as it will simply start all containers in the file rather than you having to specify hdinsight.

    Today I am facing the same issue and below is how I manage.

    I add tty: true kay value & stdin_open: true key value in ‘docker-compose.yml’ file as below and I am sure it will run in detach mode and one can also interact with console.

    version: '2'
    services:
    hdinsight:
    image: hdinsight
    container_name: ABC
    volumes:
     - /etc/hadoop/conf:/etc/hadoop/conf
     - /usr/lib/python2.7/dist-packages/hdinsight_common:/usr/lib/python2.7/dist-packages/hdinsight_common
     - /etc/hive/conf/:/etc/hive/conf/
     - /etc/tez/conf/:/etc/tez/conf/
     - /usr/hdp/2.4.2.0-258/sqoop/lib/:/usr/hdp/2.4.2.0-258/sqoop/lib/
    entrypoint:
     - bash
    labels:
     - "HDInsight client VM"
    tty: true
    stdin_open: true
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.