3

Taking a course that deals with these; the actual specifics is not pertinent to the course, but I generally have interest in trying to understand things regardless.

I have a docker-compose.yml file which I 'call on', or 'spin up'. The file contains the following information:

services:
  redis:
    image: redis:latest
    expose:
      - "6379"

  sample0395:
    image: sample0395/base:latest
    stdin_open: true
    tty: true
    expose:
      - "8888"
    ports:
      - "8888:8888"

From what I understand, and just based on the hierarchy as shown:

  • redis and sample0395 are 'services'
  • redis:latest and sample0395/base:latest are the image_name:tag combinations
  • expose and ports: list the ports (not sure what the difference is or what the significance is of the difference between these two)
  • I have no idea what stdin_open or tty do, and cannot seem to get an understanding through google.
jmtb28
  • 138
  • 3
  • 11

1 Answers1

9

tty and stdin_open are analogous to the -t and -i arguments for the docker run command, respectively.

You use stdin_open when you need to work on a project outside the Docker container.

You use tty when you need to work on a project inside the Docker container.

To test this out, try running docker-compose up with either tty or stdin_open but not both and you'll find that with stdin_open you don't log in to the container's terminal while the opposite happens with tty.

As for your question regarding the difference between expose and ports, answers are found here.

jmtb28
  • 138
  • 3
  • 11
  • 3
    This helps. Could you please share examples of working on a project from outside the container vs inside the container? – ypahalajani Sep 05 '21 at 03:15