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

Tom*_*Tom 4 redis docker-compose

我想查看是否正在运行的Redis服务器容器状态。所以我想info在redis shell中执行,看看redis slave是否与远程redis master同步。

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

  placements-store:
    image: redis:3.0
    command: redis-server ${REDIS_OPTIONS}
    ports:
      - "6379:6379"
Run Code Online (Sandbox Code Playgroud)

运行中,docker-compose ps我可以看到容器已启动并正在运行:

app_placements-store_1   docker-entrypoint.sh redis ...   Up      0.0.0.0:6379->6379/tcp 
Run Code Online (Sandbox Code Playgroud)

我试图执行:

docker-compose run --rm redis-cli
Run Code Online (Sandbox Code Playgroud)

并得到:

ERROR: No such service: redis-cli
Run Code Online (Sandbox Code Playgroud)

我认为这是可以理解的,因为没有redis-cli容器。我正在尝试标记正在运行的redis服务器,但不知道如何执行此操作。

更新

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

docker-compose logs -f --tail 500 placements-store
Run Code Online (Sandbox Code Playgroud)

我确实获得了一些类似以下的信息,但我正在寻找更多信息,并且可以从外部更轻松地进行控制:

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 
Run Code Online (Sandbox Code Playgroud)

ajt*_*rds 7

您需要使用登录到容器docker exec(如另一个答案中所述-不确定命令是否100%正确,因为它可能刚刚运行redis-cli然后退出)。

我将运行以下命令:

docker exec -it app_placements-store_1 sh

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


Mar*_*tin 6

使用docker exec到正在运行的容器内执行命令:

docker exec -it app_placements-store_1 redis-cli