Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Psuedo-tty allocation in docker-compose

In docker, I can simply use the -t switch to have docker run allocate a pseudo-tty (in these examples I'm using nohup to detach from my real tty):

$ nohup docker run    debian tty   # Produces "not a tty"
$ nohub docker run -t debian tty   # Produces "/dev/pts/0"

I'm trying to achieve the same result with docker-compose. I have the following docker-compose.yml:

version: "3"
services:
  myservice:
    image: debian
    tty: true

The I run it with and without nohup:

$       docker-compose run myservice tty   # Produces "/dev/pts/0"
$ nohup docker-compose run myservice tty   # Produces "not a tty"

The documentation of docker-compose run says that I can use -T to disable the allocation of a pseudo-tty, but there does not seem to be a way to explicitely enable it (which should not be necessary as by default a tty should be allocated).

-T Disable pseudo-tty allocation. By default docker-compose run allocates a TTY.

Am I doing something wrong?

like image 697
Spiros Avatar asked Mar 23 '26 05:03

Spiros


1 Answers

Include the following in your docker-compose.yml for your service:

services:
  myservice:
    ...
    stdin_open: true # docker run -i
    tty: true        # docker run -t
like image 168
zr0gravity7 Avatar answered Mar 25 '26 19:03

zr0gravity7



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!