2

I was trying to setup Rails console in my dockerized container. The entire application has multiple components and I have set up the orchestration using docker-compose. Here is the relevant service from my docker-compose.yml file.

app:
    image: <image_name>
    # mount the current directory (on the host) to /usr/src/app on the container, any changes in either would be reflected in both the host and the container
    tty: true
    volumes:
    - .:/usr/src/app
    # expose application on localhost:36081
    ports:
    - "36081:36081"
    # application restarts if stops for any reason - required for the container to restart when the application fails to start due to the database containers not being ready
    restart: always
    depends_on:
    - other-db
    # the environment variables are used in docker/config/env_config.rb to connect to different database containers
    container_name: application
    environment:
    - CONSOLE=$CONSOLE

My Dockerfile has the following command ENTRYPOINT /usr/src/app/docker-entrypoint.sh

And in the docker-entrypoint.sh

#!/bin/bash
echo "waiting for all db connections to be healthy... Sleeping..."
sleep 1m
mkdir -p /usr/src/app/tmp/pids/
mkdir -p /usr/src/app/tmp/sockets/
if [ "$CONSOLE" = "Y" ];
then
    echo "Starting Padrino console"
    bundle exec padrino console
fi

When I run

export CONSOLE=Y
docker-compose -f docker-compose.yml up -d && docker attach application

The console starts up and I see >> but I cannot type in it. Where am I going wrong?

Vishakha Lall
  • 1,178
  • 12
  • 33

2 Answers2

2

Try starting your container with -i mode.

-i, --interactive Attach container's STDIN

something like

docker-compose -f docker-compose.yml up -i && docker attach application

you can also mix -d and -i as per need.

Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
  • 1
    Thanks for this, unfortunately `-i` is a Docker option and not available in the list of options for `docker-compose`. I searched for the corresponding option in docker-compose (for interactive) and this is what I found https://stackoverflow.com/a/39150040/8704316. Thanks for the direction :) – Vishakha Lall Jul 22 '20 at 08:38
  • glad to heard that you found corresponding option. – Harsh Manvar Jul 22 '20 at 09:34
1

With help from this post, I figured that I was missing stdin_open: true in the docker-compose.yml. Adding it worked like a breeze.

Vishakha Lall
  • 1,178
  • 12
  • 33