docker-compose for Detached mode

Solution 1:

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.

Solution 2:

As said by Anand Suthar, you have to use tty: true and stdin_open: true. Here is a minimal example:

version: "3"
services:
  alpine1:
    image: alpine
    tty: true
    stdin_open: true

Start with:

docker-compose up -d

Attach to a container with:

docker attach 268bcfb650fb

and detach with ^P^Q.

Solution 3:

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