如何在正在运行的docker-compose容器中输入redis-server shell

我想看看是否正在运行redis-server容器状态.所以我想在redis shell中执行信息,看看redis slave是否与远程redis master同步.

我的docker-compose文件列出了redis,如下所示:

  placements-store:
    image: redis:3.0
    command: redis-server ${REDIS_OPTIONS}
    ports:
      - "6379:6379"

运行docker-compose ps我可以看到容器启动并运行:

app_placements-store_1   docker-entrypoint.sh redis ...   Up      0.0.0.0:6379->6379/tcp 

我试图执行:

docker-compose run --rm redis-cli

得到了:

ERROR: No such service: redis-cli

我认为这是可以理解的,因为没有redis-cli容器.我正在尝试标记正在运行的redis-server而不知道如何做到这一点.

UPDATE

我可以通过执行以下命令查看日志:

docker-compose logs -f --tail 500 placements-store

我确实得到了一些类似下面的信息,但我正在寻找更多可以从外部更容易控制的信息和内容:

placements-store_1  | 1:S 06 Feb 19:16:35.427 * Connecting to MASTER mo-api.mydomain.com:6379
placements-store_1  | 1:S 06 Feb 19:16:35.589 * MASTER <-> SLAVE sync started
placements-store_1  | 1:S 06 Feb 19:16:35.889 * Non blocking connect for SYNC fired the event.
placements-store_1  | 1:S 06 Feb 19:16:36.189 * Master replied to PING, replication can continue...
placements-store_1  | 1:S 06 Feb 19:16:36.790 * Partial resynchronization not possible (no cached master)
placements-store_1  | 1:S 06 Feb 19:16:37.091 * Full resync from master: 5ada1d8c65fd49d67d931bea66530a169ce83a40:29442
placements-store_1  | 1:S 06 Feb 19:16:37.145 * MASTER <-> SLAVE sync: receiving 60 bytes from master
placements-store_1  | 1:S 06 Feb 19:16:37.145 * MASTER <-> SLAVE sync: Flushing old data
placements-store_1  | 1:S 06 Feb 19:16:37.145 * MASTER <-> SLAVE sync: Loading DB in memory
placements-store_1  | 1:S 06 Feb 19:16:37.145 * MASTER <-> SLAVE sync: Finished with success 
最佳答案
您需要使用docker exec登录容器(如另一个答案所述 – 不确定该命令是否100%正确,因为它可能只运行redis-cli然后退出).

我会运行以下命令:

docker exec -it app_placements-store_1 sh

这将使您登录到容器.然后,您可以从命令提示符运行redis-cli.

转载注明原文:如何在正在运行的docker-compose容器中输入redis-server shell - 代码日志