【问题标题】:Setting up Rails console on Docker container not taking any input在 Docker 容器上设置 Rails 控制台不接受任何输入
【发布时间】:2020-07-22 05:11:18
【问题描述】:

我试图在我的 dockerized 容器中设置 Rails 控制台。整个应用程序有多个组件,我使用docker-compose 设置了编排。这是我的docker-compose.yml 文件中的相关服务。

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

我的Dockerfile 有以下命令ENTRYPOINT /usr/src/app/docker-entrypoint.sh

而在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

当我跑步时

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

控制台启动,我看到&gt;&gt;,但我无法输入。我哪里错了?

【问题讨论】:

    标签: ruby-on-rails docker docker-compose


    【解决方案1】:

    尝试使用-i 模式启动您的容器。

    -i, --interactive 附加容器的标准输入

    类似

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

    您也可以根据需要混合使用-d-i

    【讨论】:

    • 感谢您,不幸的是,-i 是一个 Docker 选项,在 docker-compose 的选项列表中不可用。我在 docker-compose(用于交互)中搜索了相应的选项,这就是我找到的 stackoverflow.com/a/39150040/8704316。感谢您的指导:)
    • 很高兴听到您找到了相应的选项。
    【解决方案2】:

    this 帖子的帮助下,我发现我在docker-compose.yml 中缺少stdin_open: true。添加它就像轻而易举。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-10
      • 1970-01-01
      相关资源
      最近更新 更多