Interactive shell using Docker Compose Interactive shell using Docker Compose docker docker

Interactive shell using Docker Compose


You need to include the following lines in your docker-compose.yml:

version: "3"services:  app:    image: app:1.2.3    stdin_open: true # docker run -i    tty: true        # docker run -t

The first corresponds to -i in docker run and the second to -t.


The canonical way to get an interactive shell with docker-compose is to use:

docker-compose run --rm myapp

You can set stdin_open: true, tty: true, however that won't actually give you a proper shell with up, because logs are being streamed from all the containers.

You can also use

docker exec -ti <container name> /bin/bash

to get a shell on a running container.


In the official getting started example (https://docs.docker.com/compose/gettingstarted/) with the following docker-compose.yml:

version: '3'services:  web:    build: .    ports:     - "5000:5000"  redis:    image: "redis:alpine"

After you start this with docker-compose up, you can easily shell into either your redis container or your web container with:

docker-compose exec redis shdocker-compose exec web sh