首页 > 解决方案 > 难以附加状态容器?

问题描述

我创建了一个在后台启动并运行的 docker 容器。我尝试使用容器 ID 将容器附加到终端中。它进入容器,但我无法在其中做任何事情。所以,我每次使用 ctrl+c 都必须退出。

在此处输入图像描述

标签: dockerdockerfilecontainersdocker-container

解决方案


If the comment by Lawrence Cherone did not help you consider the following options:

  1. If you want to invoke a command in a already running container, use docker exec. You can exec into you container by it's name or id. This means you can run a command in a running container. See docs.docker.com: docker exec.

    Example:
    The docker exec command runs the command bash in a running container.

    docker exec -it <container-id> bash
    

    Note: This will really invoke a new command and do not attach to the currelty running command.

  2. If you just want to get the putput of a container, you can use docker logs. Again you use your container name or id. See docs.docker.com: docker logs

    Example:

    docker logs <container-id>
    

推荐阅读