1

Something I'm trying to do is create a docker-compose application that has a single service act as a REPL that can interact with the rest of the services. I tried a variety of ways to get only this service attached to stdin and stdout but I haven't found anything elegant that worked. This stackoverflow post's answer said stdin_open: true and tty: true would work and here's what I made with it:

version: '3'
services:

  redis:
    image: redis

  python:
    image: python
    entrypoint: /bin/sh
    stdin_open: true
    tty: true

Running docker-compose up still sends a log of both services and docker-compose up -d detaches both of the services. For this example is there an elegant way to get an interactive shell to the python service while only running docker-compose up ... (i.e. not running docker exec, etc)?

evandp
  • 11
  • 1

1 Answers1

0

You can docker-compose run an alternate command using the image: and other settings in a Docker Compose YAML file. If that service depends_on: other services, it will start them. The one thing to be aware of is that it will not by default publish the declared ports:.

docker-compose run python /bin/sh

(The Docker setup tends to be a little more optimized around long-running network server processes, like the Redis installation here, and less for "commands" that rely on their stdin for input. Consider packaging your application into an image, but generally using host tools for learning a language and day-to-day development. For Python in particular, a virtual environment gives a self-contained playground where you can install packages, as your user account, without interfering with the system Python.)

David Maze
  • 130,717
  • 29
  • 175
  • 215