使用 Docker Compose 的交互式 shell [英] Interactive shell using Docker Compose
问题描述
有什么方法可以仅使用 Docker Compose 在容器中启动交互式 shell?我在我的 docker-compose.yml 中尝试过这样的事情:
Is there any way to start an interactive shell in a container using Docker Compose only? I've tried something like this, in my docker-compose.yml:
myapp:
image: alpine:latest
entrypoint: /bin/sh
当我使用 docker-compose up 启动这个容器时,它会立即退出.是否有任何标志可以添加到 entrypoint
命令中,或者作为 myapp
的附加选项来启动交互式 shell?
When I start this container using docker-compose up it's exited immediately. Are there any flags I can add to the entrypoint
command, or as an additional option to myapp
, to start an interactive shell?
我知道有本地 docker 命令选项可以实现这一点,只是好奇是否也可以只使用 Docker Compose.
I know there are native docker command options to achieve this, just curious if it's possible using only Docker Compose, too.
推荐答案
您需要在 docker-compose.yml 中包含以下几行:
You need to include the following lines in your docker-compose.yml:
version: "3"
services:
app:
image: app:1.2.3
stdin_open: true # docker run -i
tty: true # docker run -t
第一个对应docker run
中的-i
,第二个对应-t
.
The first corresponds to -i
in docker run
and the second to -t
.
这篇关于使用 Docker Compose 的交互式 shell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!