Docker:稼働しているDockerコンテナに接続する方法

スポンサーリンク

稼働しているDockerコンテナに接続する方法

稼働しているDockerコンテナに接続する方法docker container attachコマンド実行します。

 

コマンドの説明

$ docker container attach --help

Usage:  docker container attach [OPTIONS] CONTAINER

Attach local standard input, output, and error streams to a running container

Options:
      --detach-keys string   Override the key sequence for detaching a container
      --no-stdin             Do not attach STDIN
      --sig-proxy            Proxy all received signals to the process (default true)

 

実行例

$ docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              1d622ef86b13        3 days ago          73.9MB
centos              latest              470671670cac        3 months ago        237MB
centos              7.7.1908            08d05d1d5859        5 months ago        204MB

$ docker container run -itd --name test01 centos:7.7.1908 /bin/bash  # バックグラウンドで起動する
b2988cb0855818831503ba4ea0dba739e62851ee4bb9e6d8a8933ba21462c6bc

$ docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
b2988cb08558        centos:7.7.1908     "/bin/bash"         5 seconds ago       Up 4 seconds                            test01

$ docker container attach test01  # コンテナに接続する
[root@b2988cb08558 /]#