'docker attach' 无法联系到 Bash Shell
Unable to reach Bash Shell on 'docker attach'
在远程服务器上,docker 是 运行 基于 nginx
和 Dockerfile
的图像
FROM nginx
COPY ./ /usr/share/nginx/html
EXPOSE 80
CMD /usr/sbin/nginx -g "daemon off;"
docker ps
显示:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a71e45d5cd40 myUsername/myNginxWebsite:latest "\"/bin/sh -c '/usr/ 23 hours ago Up 23 hours 80/tcp, 443/tcp sharp_fermi
通过 SSH 连接到远程服务器后,运行 docker attach <container_id>
显示 nginx
的输出并按 ctrl
+q
,ctrl
+c
, ctrl
+p
不让我回到 bash shell.
可以到达shell吗?我想做一些类似 git pull
.
的事情
docker exec -it <container-id-or-name> /bin/bash
根据https://docs.docker.com/reference/commandline/cli/#exec -
Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Run a command in a running container
-d, --detach=false Detached mode: run command in the
background -i, --interactive=false Keep STDIN open even if not
attached -t, --tty=false Allocate a pseudo-TTY
在远程服务器上,docker 是 运行 基于 nginx
和 Dockerfile
FROM nginx
COPY ./ /usr/share/nginx/html
EXPOSE 80
CMD /usr/sbin/nginx -g "daemon off;"
docker ps
显示:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a71e45d5cd40 myUsername/myNginxWebsite:latest "\"/bin/sh -c '/usr/ 23 hours ago Up 23 hours 80/tcp, 443/tcp sharp_fermi
通过 SSH 连接到远程服务器后,运行 docker attach <container_id>
显示 nginx
的输出并按 ctrl
+q
,ctrl
+c
, ctrl
+p
不让我回到 bash shell.
可以到达shell吗?我想做一些类似 git pull
.
docker exec -it <container-id-or-name> /bin/bash
根据https://docs.docker.com/reference/commandline/cli/#exec -
Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Run a command in a running container
-d, --detach=false Detached mode: run command in the background -i, --interactive=false Keep STDIN open even if not attached -t, --tty=false Allocate a pseudo-TTY