Interactive shell using Docker Compose

drubb picture drubb · Mar 27, 2016 · Viewed 229.4k times · Source

Is there any way to start a interactive shell in a container using Docker Compose only? I've tried something like this, in my docker-compose.yml:

myapp:
  image: alpine:latest
  entrypoint: /bin/sh

When I start this container using docker-compose up it's exited immediately. Are there any flags I can add to the entrypoint command, or as and additional option to myapp, to start as interactive shell?

I know there are native docker command options to achieve this, just curious if it's possible using only Docker Compose, too.

Answer

Leon Carlo Valencia picture Leon Carlo Valencia · Aug 25, 2016

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.