Welcome to the Linux Foundation Forum!

When running a docker container, what's the point of -idt option ?

Options
Mhd Tahawi
Mhd Tahawi Posts: 2
edited March 4 in LFS261 Class Forum

For example, in Lab2 of DebOps and SRE fundametals course:
docker container run -idt --name redis redis:alpine

What's the point of i (interactive) and t (attach a pseudo TTY) if we are also running in d (detached mode) ?

Best Answer

Answers

  • luisviveropena
    luisviveropena Posts: 1,158
    Options

    Moved to the correct forum.

  • luisviveropena
    luisviveropena Posts: 1,158
    edited March 4
    Options

    Hi @Mhd Tahawi ,

    The idea of this is to have the container running in background mode. The default action is to run it on foreground. So whenever you want, you can close the terminal, or perform any other stuff in the terminal, and when you need you can connect to the container -running a binary as sh:

    For example:

    docker exec -it 6782576441fe sh

    And you will get into the container, by running a sh shell.

    You can have more information in the official documentation:

    https://docs.docker.com/engine/reference/run/

    ==>Foreground and background

    Regards,
    Luis.

  • Mhd Tahawi
    Mhd Tahawi Posts: 2
    Options

    Hello @luisviveropena

    Thanks for answering (and for moving the question to the right forum).

    I do understand foreground and background, detached mode and accessing the container in interactive mode.

    Let me phrase my question differently:
    What difference in behavior would I get if I use:
    docker container run -idt --name redis redis:alpine // interactive tty and detached
    over
    docker container run -d --name redis redis:alpine // just detached

    In both cases, I will end up running in detached mode, and in both cases, I will need to run
    docker exec -it <containerName/Id>
    for an interactive shell. So what extra functionality do I get from adding "-it" with "-d" ?

    I can think of one use case for "-i", running a container in detached mode while handling input from stdin, something like:
    echo "some input" | docker run -id myFancyImage

    but for "t" option, I don't see any point, and it feels redundant.

    Thanks for your help,
    Mohamad

Categories

Upcoming Training